SyntaxTreeNode.equal verbessert
This commit is contained in:
parent
94aae83ca8
commit
dbda805fa5
@ -1539,5 +1539,6 @@ public class SourceFile
|
|||||||
//this.filename = filename;
|
//this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -47,7 +47,8 @@ public abstract class SyntaxTreeNode {
|
|||||||
if(!(object instanceof SyntaxTreeNode))return false;
|
if(!(object instanceof SyntaxTreeNode))return false;
|
||||||
SyntaxTreeNode equal = (SyntaxTreeNode)object;
|
SyntaxTreeNode equal = (SyntaxTreeNode)object;
|
||||||
if(!equal.getDescription().equals(this.getDescription()))return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@ public class FieldDeclaration extends Field{
|
|||||||
@Override
|
@Override
|
||||||
public String toString()
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription(){
|
||||||
|
return "Block";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -5,6 +5,7 @@ package mycompiler.mystatement;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import mycompiler.SyntaxTreeNode;
|
||||||
import mycompiler.mybytecode.ClassFile;
|
import mycompiler.mybytecode.ClassFile;
|
||||||
import mycompiler.mybytecode.CodeAttribute;
|
import mycompiler.mybytecode.CodeAttribute;
|
||||||
import mycompiler.myclass.Class;
|
import mycompiler.myclass.Class;
|
||||||
@ -23,6 +24,7 @@ import org.apache.log4j.Logger;
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
import typinferenz.ConstraintsSet;
|
import typinferenz.ConstraintsSet;
|
||||||
import typinferenz.JavaCodeResult;
|
import typinferenz.JavaCodeResult;
|
||||||
@ -111,5 +113,6 @@ public class EmptyStmt extends Statement
|
|||||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||||
return new JavaCodeResult("");
|
return new JavaCodeResult("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -5,6 +5,7 @@ package mycompiler.mystatement;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import mycompiler.SyntaxTreeNode;
|
||||||
import mycompiler.mybytecode.ClassFile;
|
import mycompiler.mybytecode.ClassFile;
|
||||||
import mycompiler.mybytecode.CodeAttribute;
|
import mycompiler.mybytecode.CodeAttribute;
|
||||||
import mycompiler.mybytecode.JVMCode;
|
import mycompiler.mybytecode.JVMCode;
|
||||||
@ -25,6 +26,7 @@ import org.apache.log4j.Logger;
|
|||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import typinferenz.ConstraintsSet;
|
import typinferenz.ConstraintsSet;
|
||||||
import typinferenz.JavaCodeResult;
|
import typinferenz.JavaCodeResult;
|
||||||
import typinferenz.ResultSet;
|
import typinferenz.ResultSet;
|
||||||
@ -120,5 +122,10 @@ public class Null extends Literal
|
|||||||
return new JavaCodeResult("null");
|
return new JavaCodeResult("null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector<SyntaxTreeNode> getChildren() {
|
||||||
|
return new Vector<SyntaxTreeNode>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -145,5 +145,10 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
|||||||
|
|
||||||
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
|
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription(){
|
||||||
|
return this.printJavaCode(new ResultSet(new Vector<Pair>())).toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -152,6 +152,5 @@ public class StringLiteral extends Literal
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -51,4 +51,11 @@ public class TypeInsertPoint {
|
|||||||
String ret = type.printJavaCode(this.resultSet).toString()+" ";
|
String ret = type.printJavaCode(this.resultSet).toString()+" ";
|
||||||
return ret;
|
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 java.util.Vector;
|
||||||
|
|
||||||
|
import mycompiler.SyntaxTreeNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bündelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder gehören.
|
* Bündelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder gehören.
|
||||||
* Diese müssen gemeinsam eingesetzt werden.
|
* Diese müssen gemeinsam eingesetzt werden.
|
||||||
@ -38,4 +40,16 @@ public class TypeInsertSet {
|
|||||||
return ret;
|
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;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class NodeEqualTest extends TestCase{
|
public class NodeEqualTest extends TestCase{
|
||||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/";
|
private static final String rootDirectory = System.getProperty("user.dir")+"/test/syntaxTree/";
|
||||||
private static final String testFile = "";
|
private static final String testFile = "NodeEqualTest.jav";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test(){
|
public void test(){
|
||||||
String inferedSource = "";
|
|
||||||
MyCompilerAPI compiler = MyCompiler.getAPI();
|
MyCompilerAPI compiler = MyCompiler.getAPI();
|
||||||
|
MyCompilerAPI compiler2 = MyCompiler.getAPI();
|
||||||
SourceFile tree = null;
|
SourceFile tree = null;
|
||||||
|
SourceFile tree2 = null;
|
||||||
try {
|
try {
|
||||||
tree = compiler.parse(new File(rootDirectory + testFile));
|
tree = compiler.parse(new File(rootDirectory + testFile));
|
||||||
|
tree2 = compiler2.parse(new File(rootDirectory + testFile));
|
||||||
} catch (IOException | yyException e) {
|
} catch (IOException | yyException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
recursivlyCheckEqual(tree, tree2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){
|
private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){
|
||||||
@ -36,11 +39,15 @@ public class NodeEqualTest extends TestCase{
|
|||||||
int matches = 0;
|
int matches = 0;
|
||||||
for(SyntaxTreeNode n2 : node2.getChildren()){
|
for(SyntaxTreeNode n2 : node2.getChildren()){
|
||||||
if(n2.equals(n1)){
|
if(n2.equals(n1)){
|
||||||
|
System.out.println(n2 + " == "+n1);
|
||||||
matches++;
|
matches++;
|
||||||
this.recursivlyCheckEqual(n1, n2);
|
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