SyntaxTreeNode.equal verbessert
This commit is contained in:
parent
94aae83ca8
commit
dbda805fa5
@ -1539,5 +1539,6 @@ public class SourceFile
|
||||
//this.filename = filename;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -47,7 +47,8 @@ public abstract class SyntaxTreeNode {
|
||||
if(!(object instanceof SyntaxTreeNode))return false;
|
||||
SyntaxTreeNode equal = (SyntaxTreeNode)object;
|
||||
if(!equal.getDescription().equals(this.getDescription()))return false;
|
||||
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen.
|
||||
if(this.getParent()!=null)
|
||||
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,8 @@ public class FieldDeclaration extends Field{
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString() + "=" + getWert().toString();
|
||||
if(getWert()!=null)return super.toString() + "=" + getWert().toString();
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -308,5 +308,10 @@ public class Block extends Statement
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(){
|
||||
return "Block";
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,6 +5,7 @@ package mycompiler.mystatement;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.myclass.Class;
|
||||
@ -23,6 +24,7 @@ import org.apache.log4j.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
@ -111,5 +113,6 @@ public class EmptyStmt extends Statement
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
return new JavaCodeResult("");
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,6 +5,7 @@ package mycompiler.mystatement;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.mybytecode.JVMCode;
|
||||
@ -25,6 +26,7 @@ import org.apache.log4j.Logger;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
@ -120,5 +122,10 @@ public class Null extends Literal
|
||||
return new JavaCodeResult("null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
return new Vector<SyntaxTreeNode>();
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -145,5 +145,10 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
||||
|
||||
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
|
||||
|
||||
@Override
|
||||
public String getDescription(){
|
||||
return this.printJavaCode(new ResultSet(new Vector<Pair>())).toString();
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -152,6 +152,5 @@ public class StringLiteral extends Literal
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -192,6 +192,6 @@ public class This extends Expr
|
||||
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -51,4 +51,11 @@ public class TypeInsertPoint {
|
||||
String ret = type.printJavaCode(this.resultSet).toString()+" ";
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return - Der Punkt (Knoten) im Syntaxbaum, für den dieser TypeInsertPoint gilt.
|
||||
*/
|
||||
public TypeInsertable getInsertNode(){
|
||||
return this.point;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package typinferenz;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
|
||||
/**
|
||||
* Bündelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder gehören.
|
||||
* Diese müssen gemeinsam eingesetzt werden.
|
||||
@ -38,4 +40,16 @@ public class TypeInsertSet {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param node
|
||||
* @return - null, falls kein InsertPoint für node vorhanden.
|
||||
*/
|
||||
public TypeInsertPoint getInsertPointFor(TypeInsertable node){
|
||||
for(TypeInsertPoint point : points){
|
||||
if(point.getInsertNode().equals(node))return point;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
9
test/syntaxTree/NodeEqualTest.jav
Normal file
9
test/syntaxTree/NodeEqualTest.jav
Normal file
@ -0,0 +1,9 @@
|
||||
class NodeEqualTest {
|
||||
String var1;
|
||||
void methode1(){
|
||||
var1 = "String";
|
||||
}
|
||||
String methode2(String test){
|
||||
return test;
|
||||
}
|
||||
}
|
@ -15,20 +15,23 @@ import org.junit.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NodeEqualTest extends TestCase{
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/";
|
||||
private static final String testFile = "";
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/syntaxTree/";
|
||||
private static final String testFile = "NodeEqualTest.jav";
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
String inferedSource = "";
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI();
|
||||
MyCompilerAPI compiler2 = MyCompiler.getAPI();
|
||||
SourceFile tree = null;
|
||||
SourceFile tree2 = null;
|
||||
try {
|
||||
tree = compiler.parse(new File(rootDirectory + testFile));
|
||||
tree2 = compiler2.parse(new File(rootDirectory + testFile));
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
recursivlyCheckEqual(tree, tree2);
|
||||
}
|
||||
|
||||
private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){
|
||||
@ -36,11 +39,15 @@ public class NodeEqualTest extends TestCase{
|
||||
int matches = 0;
|
||||
for(SyntaxTreeNode n2 : node2.getChildren()){
|
||||
if(n2.equals(n1)){
|
||||
System.out.println(n2 + " == "+n1);
|
||||
matches++;
|
||||
this.recursivlyCheckEqual(n1, n2);
|
||||
}else{
|
||||
System.out.println(n2 + " != "+ n1);
|
||||
}
|
||||
}
|
||||
assertTrue("Nur eines der Children darf gleich sein", matches == 1);
|
||||
System.out.println("");
|
||||
assertTrue("Nur eines der Children darf gleich sein, nicht "+matches, matches == 1 && node2.getChildren().size()>0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user