diff --git a/src/mycompiler/MyCompiler.java b/src/mycompiler/MyCompiler.java index a40d05547..7d511bb4e 100755 --- a/src/mycompiler/MyCompiler.java +++ b/src/mycompiler/MyCompiler.java @@ -483,14 +483,16 @@ public class MyCompiler implements MyCompilerAPI */ // ino.end // ino.method.parse.21298.definition - public void parse(File file) + public SourceFile parse(File file) throws FileNotFoundException, IOException, JavaParser.yyException // ino.end // ino.method.parse.21298.body { FileReader fr = new FileReader(file); - this.m_AbstractSyntaxTree.add(this.parse2SyntaxTree(fr)); + SourceFile ret = this.parse2SyntaxTree(fr); + this.m_AbstractSyntaxTree.add(ret); fr.close(); + return ret; } // ino.end diff --git a/src/mycompiler/MyCompilerAPI.java b/src/mycompiler/MyCompilerAPI.java index 9120cb74a..e71ba8e8a 100755 --- a/src/mycompiler/MyCompilerAPI.java +++ b/src/mycompiler/MyCompilerAPI.java @@ -50,7 +50,7 @@ public interface MyCompilerAPI */ // ino.end // ino.method.parse.21334.declaration - public void parse(File file) + public SourceFile parse(File file) throws FileNotFoundException, IOException, JavaParser.yyException; // ino.end diff --git a/src/mycompiler/SyntaxTreeNode.java b/src/mycompiler/SyntaxTreeNode.java index cc8f4d6de..f085ce075 100644 --- a/src/mycompiler/SyntaxTreeNode.java +++ b/src/mycompiler/SyntaxTreeNode.java @@ -41,4 +41,13 @@ public abstract class SyntaxTreeNode { public String getDescription(){ return this.toString(); } + + @Override + public boolean equals(Object object){ + 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. + return true; + } } diff --git a/test/syntaxTree/NodeEqualTest.java b/test/syntaxTree/NodeEqualTest.java new file mode 100644 index 000000000..e79a4234d --- /dev/null +++ b/test/syntaxTree/NodeEqualTest.java @@ -0,0 +1,49 @@ +package syntaxTree; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import mycompiler.MyCompiler; +import mycompiler.MyCompilerAPI; +import mycompiler.SourceFile; +import mycompiler.SyntaxTreeNode; +import mycompiler.myparser.JavaParser.yyException; + +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 = ""; + @Test + public void test(){ + String inferedSource = ""; + MyCompilerAPI compiler = MyCompiler.getAPI(); + SourceFile tree = null; + try { + tree = compiler.parse(new File(rootDirectory + testFile)); + } catch (IOException | yyException e) { + e.printStackTrace(); + fail(); + } + + } + + private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){ + for(SyntaxTreeNode n1 : node1.getChildren()){ + int matches = 0; + for(SyntaxTreeNode n2 : node2.getChildren()){ + if(n2.equals(n1)){ + matches++; + this.recursivlyCheckEqual(n1, n2); + } + } + assertTrue("Nur eines der Children darf gleich sein", matches == 1); + } + } + + + +}