Merge remote-tracking branch 'origin/NewParser' into NewParser
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
# Conflicts: # src/test/java/parser/AstBuilderTest.java
This commit is contained in:
commit
3e1456351c
@ -18,27 +18,22 @@ import ast.statementexpressions.AssignNode;
|
|||||||
import ast.statementexpressions.AssignableNode;
|
import ast.statementexpressions.AssignableNode;
|
||||||
import ast.statementexpressions.crementexpressions.CrementType;
|
import ast.statementexpressions.crementexpressions.CrementType;
|
||||||
import ast.statementexpressions.crementexpressions.IncrementNode;
|
import ast.statementexpressions.crementexpressions.IncrementNode;
|
||||||
|
import ast.statementexpressions.NewDeclarationNode;
|
||||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||||
import ast.statements.*;
|
import ast.statements.*;
|
||||||
|
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||||
|
import ast.statements.BlockNode;
|
||||||
|
import ast.statements.LocalVariableDeclarationNode;
|
||||||
|
import ast.statements.ReturnNode;
|
||||||
import ast.type.AccessModifierNode;
|
import ast.type.AccessModifierNode;
|
||||||
import ast.type.EnumValueNode;
|
import ast.type.EnumValueNode;
|
||||||
import ast.type.ValueNode;
|
import ast.type.ValueNode;
|
||||||
import ast.type.type.BaseType;
|
import ast.type.type.BaseType;
|
||||||
import ast.type.type.ITypeNode;
|
import ast.type.type.ReferenceType;
|
||||||
import ast.type.type.TypeEnum;
|
import ast.type.type.TypeEnum;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import org.antlr.v4.runtime.CharStream;
|
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import parser.astBuilder.ASTBuilder;
|
|
||||||
import parser.generated.SimpleJavaLexer;
|
|
||||||
import parser.generated.SimpleJavaParser;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Member;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@ -345,7 +340,38 @@ class AstBuilderTest {
|
|||||||
@DisplayName("Self Reference Test")
|
@DisplayName("Self Reference Test")
|
||||||
public void selfReferneceTest(){
|
public void selfReferneceTest(){
|
||||||
|
|
||||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
ClassNode testClass = Helper.generateEmptyClass("TestClass");
|
||||||
|
|
||||||
|
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("TestClass"),"testClass");
|
||||||
|
|
||||||
|
BlockNode testMethod1Block = new BlockNode();
|
||||||
|
testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(new TargetNode(true), "testMethod2"))));
|
||||||
|
MethodNode testMethod1 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod1", testMethod1Block);
|
||||||
|
|
||||||
|
BlockNode testMethod2Block = new BlockNode();
|
||||||
|
testMethod2Block.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE,"1"))));
|
||||||
|
MethodNode testMethod2 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod2", testMethod2Block);
|
||||||
|
|
||||||
|
BlockNode testMethod3Block = new BlockNode();
|
||||||
|
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("TestClass"),"testClass1", "=", new UnaryNode(new NewDeclarationNode("TestClass")))); // Assing einfach "=" ?
|
||||||
|
MemberAccessNode methodAccess = new MemberAccessNode(false);
|
||||||
|
methodAccess.addIdentifier("testClass1");
|
||||||
|
methodAccess.addIdentifier("testClass");
|
||||||
|
TargetNode methodTarget = new TargetNode(methodAccess);
|
||||||
|
testMethod3Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(methodTarget,"testMethod1"))));
|
||||||
|
MethodNode testMethod3 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod3", testMethod3Block);
|
||||||
|
|
||||||
|
testClass.addMember(testClassObject);
|
||||||
|
testClass.addMember(testMethod1);
|
||||||
|
testClass.addMember(testMethod2);
|
||||||
|
testClass.addMember(testMethod3);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(testClass);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/SelfReference.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -3,14 +3,14 @@ class TestClass{
|
|||||||
TestClass testClass;
|
TestClass testClass;
|
||||||
|
|
||||||
int testMethod1() {
|
int testMethod1() {
|
||||||
return this.testMethod2()
|
return this.testMethod2();
|
||||||
}
|
}
|
||||||
|
|
||||||
int testMethod2() {
|
int testMethod2() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int testMehtod3(){
|
int testMethod3(){
|
||||||
TestClass testClass1 = new TestClass();
|
TestClass testClass1 = new TestClass();
|
||||||
return testClass1.testClass.testMethod1();
|
return testClass1.testClass.testMethod1();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user