Compare commits
6 Commits
3e901ea254
...
e94cd9cc2a
Author | SHA1 | Date | |
---|---|---|---|
e94cd9cc2a | |||
|
dcd20a2394 | ||
2ae0988986 | |||
dfded3e592 | |||
|
dccd34db73 | ||
|
27f50b9c66 |
@ -15,30 +15,20 @@ public class ClassNode implements ASTNode, Visitable {
|
|||||||
public AccessModifierNode accessType;
|
public AccessModifierNode accessType;
|
||||||
public String identifier;
|
public String identifier;
|
||||||
public List<MemberNode> members = new ArrayList<>();
|
public List<MemberNode> members = new ArrayList<>();
|
||||||
public boolean hasConstructor;
|
|
||||||
|
|
||||||
public ClassNode() {}
|
public ClassNode(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public ClassNode(String accessType, String identifier){
|
public ClassNode(String accessType, String identifier){
|
||||||
this.accessType = new AccessModifierNode(accessType);
|
this.accessType = new AccessModifierNode(accessType);
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
hasConstructor = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMember(MemberNode member) {
|
public void addMember(MemberNode member) {
|
||||||
if (member instanceof ConstructorNode) {
|
|
||||||
this.hasConstructor = true;
|
|
||||||
}
|
|
||||||
members.add(member);
|
members.add(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensureConstructor(){
|
|
||||||
if(!hasConstructor) {
|
|
||||||
ConstructorNode constructor = new ConstructorNode(new AccessModifierNode("public"), identifier);
|
|
||||||
members.addFirst(constructor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MethodNode> getMethods(){
|
public List<MethodNode> getMethods(){
|
||||||
List<MethodNode> methods = new ArrayList<>();
|
List<MethodNode> methods = new ArrayList<>();
|
||||||
for (MemberNode member : members) {
|
for (MemberNode member : members) {
|
||||||
|
@ -13,11 +13,6 @@ public class ConstructorNode extends MethodNode {
|
|||||||
public List<ParameterNode> parameters = new ArrayList<>();
|
public List<ParameterNode> parameters = new ArrayList<>();
|
||||||
public BlockNode block;
|
public BlockNode block;
|
||||||
|
|
||||||
public ConstructorNode(AccessModifierNode accessType, String identifier) {
|
|
||||||
this.accessType = accessType;
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
||||||
this.accessType = new AccessModifierNode(accessType);
|
this.accessType = new AccessModifierNode(accessType);
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
@ -44,11 +44,32 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ASTNode visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) {
|
public ASTNode visitClassDeclaration(SimpleJavaParser.ClassDeclarationContext ctx) {
|
||||||
ClassNode classNode = new ClassNode(ctx.AccessModifier().getText(), ctx.Identifier().getText());
|
ClassNode classNode;
|
||||||
for (SimpleJavaParser.MemberDeclarationContext member : ctx.memberDeclaration()) {
|
if(ctx.AccessModifier() != null){
|
||||||
classNode.addMember((MemberNode) visit(member));
|
classNode = new ClassNode(ctx.AccessModifier().getText(), ctx.Identifier().getText());
|
||||||
}
|
}
|
||||||
classNode.ensureConstructor();
|
else{
|
||||||
|
classNode = new ClassNode("public", ctx.Identifier().getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasConstructor = false;
|
||||||
|
|
||||||
|
for (SimpleJavaParser.MemberDeclarationContext member : ctx.memberDeclaration()) {
|
||||||
|
MemberNode memberNode = (MemberNode) visit(member);
|
||||||
|
if(memberNode != null) {
|
||||||
|
if(memberNode instanceof ConstructorNode){
|
||||||
|
hasConstructor = true;
|
||||||
|
}
|
||||||
|
classNode.addMember(memberNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!hasConstructor){
|
||||||
|
BlockNode blockNode = new BlockNode();
|
||||||
|
blockNode.addStatement(new ReturnNode(null));
|
||||||
|
classNode.members.addFirst(new ConstructorNode("public", ctx.Identifier().getText(), blockNode));
|
||||||
|
}
|
||||||
|
|
||||||
return classNode;
|
return classNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,29 +93,54 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|||||||
return mainMethod;
|
return mainMethod;
|
||||||
} else {
|
} else {
|
||||||
if(ctx.type() != null) {
|
if(ctx.type() != null) {
|
||||||
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
if(ctx.AccessModifier() != null) {
|
||||||
if(ctx.parameterList() != null) {
|
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
||||||
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
if(ctx.parameterList() != null) {
|
||||||
methodNode.addParameter((ParameterNode) visit(parameter));
|
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
||||||
|
methodNode.addParameter((ParameterNode) visit(parameter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return methodNode;
|
||||||
|
} else {
|
||||||
|
MethodNode methodNode = new MethodNode("public", createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
||||||
|
if(ctx.parameterList() != null) {
|
||||||
|
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
||||||
|
methodNode.addParameter((ParameterNode) visit(parameter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return methodNode;
|
||||||
}
|
}
|
||||||
return methodNode;
|
|
||||||
} else {
|
} else {
|
||||||
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
if(ctx.AccessModifier() != null) {
|
||||||
if(ctx.parameterList() != null) {
|
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
||||||
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
if(ctx.parameterList() != null) {
|
||||||
methodNode.addParameter((ParameterNode) visit(parameter));
|
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
||||||
|
methodNode.addParameter((ParameterNode) visit(parameter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
methodNode.block.addStatement(new ReturnNode(null));
|
||||||
|
return methodNode;
|
||||||
|
} else {
|
||||||
|
MethodNode methodNode = new MethodNode("public", null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
|
||||||
|
if(ctx.parameterList() != null) {
|
||||||
|
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
|
||||||
|
methodNode.addParameter((ParameterNode) visit(parameter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
methodNode.block.addStatement(new ReturnNode(null));
|
||||||
|
return methodNode;
|
||||||
}
|
}
|
||||||
methodNode.block.addStatement(new ReturnNode(null));
|
|
||||||
return methodNode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ASTNode visitFieldDeclaration(SimpleJavaParser.FieldDeclarationContext ctx) {
|
public ASTNode visitFieldDeclaration(SimpleJavaParser.FieldDeclarationContext ctx) {
|
||||||
return new FieldNode(new AccessModifierNode(ctx.AccessModifier().getText()), createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
|
if(ctx.AccessModifier() != null) {
|
||||||
|
return new FieldNode(new AccessModifierNode(ctx.AccessModifier().getText()), createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
|
||||||
|
} else {
|
||||||
|
return new FieldNode(new AccessModifierNode("public"), createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -184,10 +230,17 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|||||||
crement = (IStatementNode) visit(ctx.statementExpression(i));
|
crement = (IStatementNode) visit(ctx.statementExpression(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockNode forBlock = (BlockNode) visit(ctx.blockStatement());
|
BlockNode forBlock = new BlockNode();
|
||||||
|
|
||||||
|
BlockNode forStatements = (BlockNode) visit(ctx.blockStatement());
|
||||||
|
if(forStatements != null) {
|
||||||
|
forBlock.addStatement((IStatementNode) forStatements);
|
||||||
|
}
|
||||||
|
|
||||||
if(crement != null){
|
if(crement != null){
|
||||||
forBlock.addStatement((crement));
|
BlockNode forCrement = new BlockNode();
|
||||||
|
forCrement.addStatement((crement));
|
||||||
|
forBlock.addStatement(forCrement);
|
||||||
}
|
}
|
||||||
|
|
||||||
WhileNode While = new WhileNode(condition, forBlock);
|
WhileNode While = new WhileNode(condition, forBlock);
|
||||||
@ -259,7 +312,12 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ASTNode visitMethodCall(SimpleJavaParser.MethodCallContext ctx) {
|
public ASTNode visitMethodCall(SimpleJavaParser.MethodCallContext ctx) {
|
||||||
MethodCallNode methodCallStatementExpressionNode = new MethodCallNode((TargetNode) visit(ctx.target()), ctx.Identifier().getText());
|
MethodCallNode methodCallStatementExpressionNode;
|
||||||
|
if(ctx.target() != null) {
|
||||||
|
methodCallStatementExpressionNode = new MethodCallNode((TargetNode) visit(ctx.target()), ctx.Identifier().getText());
|
||||||
|
} else {
|
||||||
|
methodCallStatementExpressionNode = new MethodCallNode(null, ctx.Identifier().getText());
|
||||||
|
}
|
||||||
for(SimpleJavaParser.ChainedMethodContext chainedMethod : ctx.chainedMethod()) {
|
for(SimpleJavaParser.ChainedMethodContext chainedMethod : ctx.chainedMethod()) {
|
||||||
methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod));
|
methodCallStatementExpressionNode.addChainedMethod((ChainedMethodNode) visit(chainedMethod));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
import org.antlr.v4.runtime.Lexer;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.atn.*;
|
||||||
import org.antlr.v4.runtime.dfa.DFA;
|
import org.antlr.v4.runtime.dfa.DFA;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Generated from C:/Users/Maxi/Documents/DHBW/Compilerbau/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
// Generated from C:/Users/janni/Desktop/NichtHaskell2.0/src/main/java/parser/grammar/SimpleJava.g4 by ANTLR 4.13.1
|
||||||
package parser.generated;
|
package parser.generated;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||||
|
|
||||||
|
@ -1,57 +1,405 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
|
|
||||||
|
import ast.ASTNode;
|
||||||
import ast.ClassNode;
|
import ast.ClassNode;
|
||||||
import ast.ProgramNode;
|
import ast.ProgramNode;
|
||||||
|
import ast.expressions.IExpressionNode;
|
||||||
|
import ast.expressions.unaryexpressions.MemberAccessNode;
|
||||||
|
import ast.expressions.unaryexpressions.UnaryNode;
|
||||||
|
import ast.members.ConstructorNode;
|
||||||
|
import ast.members.FieldNode;
|
||||||
|
import ast.members.MemberNode;
|
||||||
|
import ast.members.MethodNode;
|
||||||
|
import ast.parameters.ParameterNode;
|
||||||
|
import ast.statementexpressions.AssignNode;
|
||||||
|
import ast.statementexpressions.AssignableNode;
|
||||||
|
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||||
|
import ast.statements.BlockNode;
|
||||||
|
import ast.statements.IStatementNode;
|
||||||
|
import ast.statements.ReturnNode;
|
||||||
|
import ast.type.AccessModifierNode;
|
||||||
|
import ast.type.EnumValueNode;
|
||||||
|
import ast.type.ValueNode;
|
||||||
|
import ast.type.type.BaseType;
|
||||||
|
import ast.type.type.ITypeNode;
|
||||||
|
import ast.type.type.TypeEnum;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import org.antlr.v4.runtime.CharStream;
|
||||||
import org.antlr.v4.runtime.CharStreams;
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
import org.antlr.v4.runtime.CommonTokenStream;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import parser.astBuilder.ASTBuilder;
|
import parser.astBuilder.ASTBuilder;
|
||||||
import parser.generated.SimpleJavaLexer;
|
import parser.generated.SimpleJavaLexer;
|
||||||
import parser.generated.SimpleJavaParser;
|
import parser.generated.SimpleJavaParser;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Member;
|
||||||
|
|
||||||
public class AstBuilderTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@DisplayName("Untyped Abstract Syntax Tree")
|
||||||
|
class AstBuilderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void astBuilderTest() {
|
@DisplayName("Empty Class Test")
|
||||||
// ---------------- Leere Klasse nachgebaut ----------------
|
public void emptyClassTest(){
|
||||||
|
ClassNode emptyClass = Helper.generateEmptyClass("TestClass");
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(emptyClass);
|
||||||
|
|
||||||
ProgramNode expectedASTEmptyClass = new ProgramNode();
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClass.java");
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
// public class Name {}
|
@Test
|
||||||
ClassNode nameClass = new ClassNode("public", "Name");
|
@DisplayName("Multiple Empty Classes Test")
|
||||||
|
public void multipleEmptyClassesTest() {
|
||||||
|
ClassNode class1 = Helper.generateEmptyClass("TestClass1");
|
||||||
|
ClassNode class2 = Helper.generateEmptyClass("TestClass2");
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
expected.addClass(class2);
|
||||||
|
|
||||||
expectedASTEmptyClass.addClass(nameClass);
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/MultipleClasses.java");
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Empty Class Test with Constructor")
|
||||||
|
public void emptyClassWithConstructorTest() {
|
||||||
|
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
// ---------------- Leere Klasse erzeugt ----------------
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/EmptyClassWithConstructor.java");
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
// init
|
@Test
|
||||||
CharStream inputCharStream = CharStreams.fromString("public class Name {}");
|
@DisplayName("Field Test")
|
||||||
SimpleJavaLexer lexer = new SimpleJavaLexer(inputCharStream);
|
public void fieldTest() {
|
||||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||||
tokenStream.fill();
|
class1.addMember(new FieldNode(null, new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
/* Parser -> Parsetree */
|
ProgramNode expected = new ProgramNode();
|
||||||
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
expected.addClass(class1);
|
||||||
ParseTree parseTreeEmptyClass = parser.program(); // parse the input
|
|
||||||
|
|
||||||
/* AST builder -> AST */
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Field.java");
|
||||||
ASTBuilder astBuilder = new ASTBuilder();
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
ProgramNode actualASTEmptyClass = (ProgramNode) new ASTBuilder().visit(parseTreeEmptyClass);
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Field Test with Accessmodifier")
|
||||||
|
public void fieldTestWithModifier() {
|
||||||
|
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
// ---------------- Vergleichen ----------------
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
String expectedASTasString = expectedASTEmptyClass.toString();
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/FieldWithAccessModifier.java");
|
||||||
String actualASTasString = new ASTBuilder().visit(parseTreeEmptyClass).toString();
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
// Wie vergleiche ich das?
|
@Test
|
||||||
assertEquals(expectedASTasString, actualASTasString);
|
@DisplayName("Commments Ignore Test")
|
||||||
assertEquals(expectedASTEmptyClass, actualASTEmptyClass);
|
public void commmentsIgnoreTest(){
|
||||||
|
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Comments.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Constructor Paramerter Test")
|
||||||
|
public void constructorParameterTest(){
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||||
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "b"));
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorParameter.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("This Dot Test")
|
||||||
|
public void thisDotTest(){
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
ValueNode value = new ValueNode(EnumValueNode.INT_VALUE, "1");
|
||||||
|
IExpressionNode expression = new UnaryNode(value);
|
||||||
|
|
||||||
|
block.addStatement(new AssignNode(assignable, expression));
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ThisDot.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Constructor This Dot Test")
|
||||||
|
public void constructorThisDotTest(){
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
IExpressionNode expression = new UnaryNode("a");
|
||||||
|
|
||||||
|
block.addStatement(new AssignNode(assignable, expression));
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", block);
|
||||||
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("private"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorThisDot.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Void Methoden Test")
|
||||||
|
public void voidMethodenTest(){
|
||||||
|
ClassNode class1 = Helper.generateEmptyClass("TestClass");
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
class1.addMember(new MethodNode("public", null, true, "test", block));
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/VoidMethod.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Constructor Method call Test")
|
||||||
|
public void constructorMethodCallTest(){
|
||||||
|
BlockNode blockCon = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
IExpressionNode expression = new UnaryNode(new MethodCallNode(null, "testMethod"));
|
||||||
|
|
||||||
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||||
|
|
||||||
|
BlockNode blockMethod = new BlockNode();
|
||||||
|
blockMethod.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "1"))));
|
||||||
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
class1.addMember(method);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCall.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Constructor Method call Parameters Test")
|
||||||
|
public void constructorMethodCallParametersTest(){
|
||||||
|
BlockNode blockCon = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
MethodCallNode methodCall = new MethodCallNode(null, "testMethod");
|
||||||
|
methodCall.addExpression(new UnaryNode("a"));
|
||||||
|
IExpressionNode expression = new UnaryNode(methodCall);
|
||||||
|
|
||||||
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||||
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
|
BlockNode blockMethod = new BlockNode();
|
||||||
|
blockMethod.addStatement(new ReturnNode(new UnaryNode("a")));
|
||||||
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod", blockMethod);
|
||||||
|
method.addParameter(new ParameterNode(new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
class1.addMember(method);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/ConstructorMethodCallParameters.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Char Test")
|
||||||
|
public void charTest(){
|
||||||
|
BlockNode blockCon = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
MethodCallNode methodCall = new MethodCallNode(null, "testMethod");
|
||||||
|
methodCall.addExpression(new UnaryNode("a"));
|
||||||
|
IExpressionNode expression = new UnaryNode(methodCall);
|
||||||
|
|
||||||
|
blockCon.addStatement(new AssignNode(assignable, expression));
|
||||||
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||||
|
constructor.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||||
|
|
||||||
|
BlockNode blockMethod = new BlockNode();
|
||||||
|
blockMethod.addStatement(new ReturnNode(new UnaryNode("a")));
|
||||||
|
MethodNode method = new MethodNode("public", new BaseType(TypeEnum.CHAR), false, "testMethod", blockMethod);
|
||||||
|
method.addParameter(new ParameterNode(new BaseType(TypeEnum.CHAR), "a"));
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.CHAR), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
class1.addMember(method);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Char.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Null Test")
|
||||||
|
public void nullTest(){
|
||||||
|
BlockNode blockCon = new BlockNode();
|
||||||
|
MemberAccessNode memberAccess = new MemberAccessNode(true);
|
||||||
|
memberAccess.addIdentifier("a");
|
||||||
|
|
||||||
|
AssignableNode assignable = new AssignableNode(memberAccess);
|
||||||
|
|
||||||
|
blockCon.addStatement(new AssignNode(assignable, new UnaryNode(new ValueNode(EnumValueNode.NULL_VALUE, "null"))));
|
||||||
|
blockCon.addStatement(new ReturnNode(null));
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "TestClass");
|
||||||
|
class1.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Null.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Self Reference Test")
|
||||||
|
public void selfReferneceTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Variable Compare Test")
|
||||||
|
public void variableCompareTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Variable Calculation Test")
|
||||||
|
public void variableCalculationTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Main Method Test")
|
||||||
|
public void mainMethodTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("While Test")
|
||||||
|
public void whileTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Do While Test")
|
||||||
|
public void doWhileTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("For Test")
|
||||||
|
public void forTest(){
|
||||||
|
|
||||||
|
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Noch nicht speziell Increment nur zum Development Testen per Debug
|
||||||
|
@Test
|
||||||
|
@DisplayName("Increment Test")
|
||||||
|
public void incrementTest(){
|
||||||
|
ClassNode classNode = Helper.generateEmptyClass("TestClass");
|
||||||
|
classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"));
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(classNode);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Increment.java");
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -65,39 +413,4 @@ public class AstBuilderTest {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------- Alter CompilerInput nachgebaut ----------------
|
|
||||||
// ProgramNode startNode = new ProgramNode();
|
|
||||||
// public class CompilerInput {}
|
|
||||||
// ClassNode compilerInputClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "CompilerInput");
|
|
||||||
// public int a;
|
|
||||||
// compilerInputClass.addMember(new FieldNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), new BaseTypeNode(EnumTypeNode.INT), "a"));
|
|
||||||
// public static int testMethod(char x) { return 0; }
|
|
||||||
/* compilerInputClass.addMember(
|
|
||||||
new MethodNode(
|
|
||||||
new AccessTypeNode(EnumAccessTypeNode.PUBLIC),
|
|
||||||
new BaseTypeNode(EnumTypeNode.INT),
|
|
||||||
"testMethod",
|
|
||||||
new ParameterListNode(List.of(new ParameterNode(new BaseTypeNode(EnumTypeNode.CHAR), "x"))),
|
|
||||||
List.of(new ReturnStatementNode(new LiteralNode(0)))
|
|
||||||
));
|
|
||||||
|
|
||||||
ClassNode testClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "Test");
|
|
||||||
testClass.addMember(
|
|
||||||
new MethodNode(
|
|
||||||
new AccessTypeNode(EnumAccessTypeNode.PUBLIC),
|
|
||||||
new BaseTypeNode(EnumTypeNode.INT),
|
|
||||||
"testMethod",
|
|
||||||
new ParameterListNode(List.of(new ParameterNode(new BaseTypeNode(EnumTypeNode.CHAR), "x"), new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "a"))),
|
|
||||||
List.of(new ReturnStatementNode(new LiteralNode(0)))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//compilerInputClass.addClass(testClass);
|
|
||||||
|
|
||||||
// startNode.addClass(compilerInputClass);
|
|
||||||
// startNode.addClass(testClass);
|
|
||||||
}
|
|
47
src/test/java/parser/Helper.java
Normal file
47
src/test/java/parser/Helper.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package parser;
|
||||||
|
|
||||||
|
import ast.ASTNode;
|
||||||
|
import ast.ClassNode;
|
||||||
|
import ast.ProgramNode;
|
||||||
|
import ast.members.ConstructorNode;
|
||||||
|
import ast.members.MemberNode;
|
||||||
|
import ast.statements.BlockNode;
|
||||||
|
import ast.statements.ReturnNode;
|
||||||
|
import ast.type.AccessModifierNode;
|
||||||
|
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 parser.astBuilder.ASTBuilder;
|
||||||
|
import parser.generated.SimpleJavaLexer;
|
||||||
|
import parser.generated.SimpleJavaParser;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Helper {
|
||||||
|
public static ASTNode generateAST(String filePath) {
|
||||||
|
CharStream testFile = null;
|
||||||
|
try {
|
||||||
|
testFile = CharStreams.fromFileName(filePath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
SimpleJavaLexer lexer = new SimpleJavaLexer(testFile);
|
||||||
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||||
|
tokenStream.fill();
|
||||||
|
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
||||||
|
ParseTree parseTree = parser.program();
|
||||||
|
ASTBuilder astBuilder = new ASTBuilder();
|
||||||
|
|
||||||
|
return astBuilder.visit(parseTree);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClassNode generateEmptyClass(String className) {
|
||||||
|
BlockNode blockNode = new BlockNode();
|
||||||
|
blockNode.addStatement(new ReturnNode(null));
|
||||||
|
MemberNode constructor = new ConstructorNode("public",className, blockNode);
|
||||||
|
ClassNode classNode = new ClassNode("public", className);
|
||||||
|
classNode.addMember(constructor);
|
||||||
|
return classNode;
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/input/javaCases/Char.java
Normal file
12
src/test/resources/input/javaCases/Char.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
char a;
|
||||||
|
|
||||||
|
public TestClass(char a){
|
||||||
|
this.a = testMethod(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
char testMethod(char a){
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
8
src/test/resources/input/javaCases/Comments.java
Normal file
8
src/test/resources/input/javaCases/Comments.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Mutliple Line Comment. Ignore
|
||||||
|
|
||||||
|
*/
|
||||||
|
class TestClass{
|
||||||
|
private int a; // Ignore
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
class TestClass {
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
public TestClass(){
|
||||||
|
this.a = testMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMethod(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
class TestClass {
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
public TestClass(int a){
|
||||||
|
this.a = testMethod(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMethod(int a){
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
class TestClass {
|
||||||
|
public TestClass(int a, int b){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
private int a;
|
||||||
|
|
||||||
|
public TestClass(int a){
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
}
|
10
src/test/resources/input/javaCases/DoWhile.java
Normal file
10
src/test/resources/input/javaCases/DoWhile.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
public TestClass(){
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
do{
|
||||||
|
i++
|
||||||
|
}while(i < 10);
|
||||||
|
}
|
||||||
|
}
|
1
src/test/resources/input/javaCases/EmptyClass.java
Normal file
1
src/test/resources/input/javaCases/EmptyClass.java
Normal file
@ -0,0 +1 @@
|
|||||||
|
class TestClass {}
|
@ -0,0 +1,5 @@
|
|||||||
|
public class TestClass {
|
||||||
|
public TestClass() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
src/test/resources/input/javaCases/Field.java
Normal file
3
src/test/resources/input/javaCases/Field.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public class TestClass {
|
||||||
|
int a;
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
public class TestClass {
|
||||||
|
public int a;
|
||||||
|
}
|
8
src/test/resources/input/javaCases/For.java
Normal file
8
src/test/resources/input/javaCases/For.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
public TestClass(){
|
||||||
|
for(int i = 0; i < 10; i++){
|
||||||
|
int a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/input/javaCases/Increment.java
Normal file
12
src/test/resources/input/javaCases/Increment.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
public class Increment {
|
||||||
|
|
||||||
|
public int test;
|
||||||
|
|
||||||
|
public void increment(int p) {
|
||||||
|
test = p++;
|
||||||
|
|
||||||
|
for(int i = 1; i<=10, i++) {
|
||||||
|
int a = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
src/test/resources/input/javaCases/MainMehod.java
Normal file
5
src/test/resources/input/javaCases/MainMehod.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
}
|
||||||
|
}
|
3
src/test/resources/input/javaCases/MultipleClasses.java
Normal file
3
src/test/resources/input/javaCases/MultipleClasses.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class TestClass1 {}
|
||||||
|
|
||||||
|
class TestClass2{}
|
8
src/test/resources/input/javaCases/Null.java
Normal file
8
src/test/resources/input/javaCases/Null.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
int a;
|
||||||
|
|
||||||
|
public TestClass(){
|
||||||
|
this.a = null;
|
||||||
|
}
|
||||||
|
}
|
18
src/test/resources/input/javaCases/SelfReference.java
Normal file
18
src/test/resources/input/javaCases/SelfReference.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
TestClass testClass;
|
||||||
|
|
||||||
|
int testMethod1() {
|
||||||
|
return this.testMethod2()
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMethod2() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int testMehtod3(){
|
||||||
|
TestClass testClass1 = new TestClass();
|
||||||
|
return testClass1.testClass.testMethod1();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
src/test/resources/input/javaCases/ThisDot.java
Normal file
8
src/test/resources/input/javaCases/ThisDot.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
public int a;
|
||||||
|
|
||||||
|
public TestClass() {
|
||||||
|
this.a = 1;
|
||||||
|
}
|
||||||
|
}
|
3
src/test/resources/input/javaCases/VoidMethod.java
Normal file
3
src/test/resources/input/javaCases/VoidMethod.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class TestClass{
|
||||||
|
void test(){}
|
||||||
|
}
|
10
src/test/resources/input/javaCases/While.java
Normal file
10
src/test/resources/input/javaCases/While.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
public TestClass(){
|
||||||
|
int i = 10;
|
||||||
|
|
||||||
|
while ( i > 0){
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
int aPlusB(int a, int b){
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int aMinusB(int a, int b){
|
||||||
|
return a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int aTimeB(int a, int b){
|
||||||
|
return a * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int aDivB(int a, int b){
|
||||||
|
return a / b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int colmplexCalc (int a, int b){
|
||||||
|
return a * (b / 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean aSmallerB (int a, int b){
|
||||||
|
return a < b;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean aGreaterB (int a, int b){
|
||||||
|
return a > b;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean aEqualsB (int a, int b){
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
}
|
30
src/test/resources/input/javaCases/variableCompareTest.java
Normal file
30
src/test/resources/input/javaCases/variableCompareTest.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
class TestClass{
|
||||||
|
|
||||||
|
boolean true(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean false(){
|
||||||
|
return false();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueAndTrue(){
|
||||||
|
return true && true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueAndFalse(){
|
||||||
|
return true && true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean falseAndFalse(){
|
||||||
|
return false && false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean trueOrFalse(){
|
||||||
|
return true || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean falseOrFalse(){
|
||||||
|
return false || false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user