Compare commits
10 Commits
ed25868ff7
...
JannikChan
Author | SHA1 | Date | |
---|---|---|---|
91552ad147 | |||
084808c3ab | |||
d19748766f | |||
|
4bdb65a6ce | ||
|
97e0c228d6 | ||
|
d4be77ceb2 | ||
ca539add98 | |||
1bcf396f95 | |||
8ba58d492b | |||
879fa08cdc |
@@ -1,11 +0,0 @@
|
|||||||
package ast.statement;
|
|
||||||
|
|
||||||
import ast.statements.IStatementNode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BlockStatementNode {
|
|
||||||
List<IStatementNode> statements;
|
|
||||||
|
|
||||||
public BlockStatementNode(List<IStatementNode> statements) {this.statements = statements;}
|
|
||||||
}
|
|
@@ -281,8 +281,13 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) {
|
public ASTNode visitIfElseStatement(SimpleJavaParser.IfElseStatementContext ctx) {
|
||||||
IfElseNode ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()),
|
IfElseNode ifElseStatementNode;
|
||||||
(ElseNode) visit(ctx.elseStatement()));
|
if(ctx.elseStatement() != null) {
|
||||||
|
ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()),
|
||||||
|
(ElseNode) visit(ctx.elseStatement()));
|
||||||
|
} else {
|
||||||
|
ifElseStatementNode = new IfElseNode((IfNode) visit(ctx.ifStatement()), null);
|
||||||
|
}
|
||||||
|
|
||||||
for (SimpleJavaParser.ElseIfStatementContext elseIf : ctx.elseIfStatement()){
|
for (SimpleJavaParser.ElseIfStatementContext elseIf : ctx.elseIfStatement()){
|
||||||
ifElseStatementNode.addElseIfStatement(((IfNode) visit(elseIf)));
|
ifElseStatementNode.addElseIfStatement(((IfNode) visit(elseIf)));
|
||||||
|
@@ -325,6 +325,12 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
||||||
|
|
||||||
if (toCheck.target != null) {
|
if (toCheck.target != null) {
|
||||||
|
if(toCheck.target.memberAccess == null){
|
||||||
|
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||||
|
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||||
|
memberAccessNode.identifiers.add(toCheck.target.identifier);
|
||||||
|
toCheck.target.memberAccess = memberAccessNode;
|
||||||
|
}
|
||||||
if (toCheck.target.identifier != null) {
|
if (toCheck.target.identifier != null) {
|
||||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||||
if (targetType == null) {
|
if (targetType == null) {
|
||||||
@@ -612,6 +618,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
|
|
||||||
if (targetNode.memberAccess != null) {
|
if (targetNode.memberAccess != null) {
|
||||||
return targetNode.memberAccess.accept(this);
|
return targetNode.memberAccess.accept(this);
|
||||||
|
} else if(targetNode.identifier != null) {
|
||||||
|
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||||
|
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||||
|
memberAccessNode.identifiers.add(targetNode.identifier);
|
||||||
|
targetNode.memberAccess = memberAccessNode;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -333,6 +333,92 @@ class AstBuilderTest {
|
|||||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("If Test")
|
||||||
|
public void ifTest() {
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
|
||||||
|
|
||||||
|
BlockNode ifBlock = new BlockNode();
|
||||||
|
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
block.addStatement(new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), null));
|
||||||
|
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "If", block);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "If");
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST(directoryPath + "If.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("If Else Test")
|
||||||
|
public void ifElseTest() {
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
|
||||||
|
|
||||||
|
BlockNode ifBlock = new BlockNode();
|
||||||
|
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
BlockNode elseBlock = new BlockNode();
|
||||||
|
elseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
block.addStatement(new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), new ElseNode(elseBlock)));
|
||||||
|
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "IfElse", block);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "IfElse");
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST(directoryPath + "IfElse.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("If Else If ElseTest")
|
||||||
|
public void ifElseIfElseTest() {
|
||||||
|
BlockNode block = new BlockNode();
|
||||||
|
block.addStatement(new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "intValue", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))));
|
||||||
|
|
||||||
|
BlockNode ifBlock = new BlockNode();
|
||||||
|
ifBlock.addStatement(new DecrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
BlockNode elseBlock = new BlockNode();
|
||||||
|
elseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
|
||||||
|
IfElseNode ifElseStatement = new IfElseNode(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "5"))), ifBlock), new ElseNode(elseBlock));
|
||||||
|
|
||||||
|
BlockNode ifElseBlock = new BlockNode();
|
||||||
|
ifElseBlock.addStatement(new IncrementNode(CrementType.SUFFIX, new AssignableNode("intValue")));
|
||||||
|
ifElseStatement.addElseIfStatement(new IfNode(new NonCalculationNode(new UnaryNode("intValue"), "==", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "4"))), ifElseBlock));
|
||||||
|
|
||||||
|
block.addStatement(ifElseStatement);
|
||||||
|
|
||||||
|
block.addStatement(new ReturnNode(null));
|
||||||
|
|
||||||
|
ConstructorNode constructor = new ConstructorNode("public", "IfElseIfElse", block);
|
||||||
|
|
||||||
|
ClassNode class1 = new ClassNode("public", "IfElseIfElse");
|
||||||
|
class1.addMember(constructor);
|
||||||
|
|
||||||
|
ProgramNode expected = new ProgramNode();
|
||||||
|
expected.addClass(class1);
|
||||||
|
|
||||||
|
ASTNode actual = Helper.generateAST(directoryPath + "IfElseIfElse.java");
|
||||||
|
|
||||||
|
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Self Reference Test")
|
@DisplayName("Self Reference Test")
|
||||||
public void selfReferneceTest(){
|
public void selfReferneceTest(){
|
||||||
|
@@ -26,6 +26,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import semantic.exceptions.*;
|
||||||
import semantic.exceptions.NotDeclaredException;
|
import semantic.exceptions.NotDeclaredException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -109,7 +110,6 @@ public class EndToTypedAstTest {
|
|||||||
} else {
|
} else {
|
||||||
System.out.println("The provided path is not a directory.");
|
System.out.println("The provided path is not a directory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -154,6 +154,132 @@ public class EndToTypedAstTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void notDeclared() {
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/NotDeclared.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void typeMismatchTest() {
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchIntBool.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parameterAlreadyDecleared() {
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ParameterAlreadyDecleared.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof AlreadyDeclaredException));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fieldAlreadyDecleared(){
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldAlreadyDecleared.java");
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof AlreadyDeclaredException));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void typeMismatchRefType(){
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/TypeMismatchRefType.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void correctRetType(){
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/CorrectRetType.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retTypeMismatch(){
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/RetTypeMismatch.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void multipleRetType(){
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/MultipleRetTypes.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof MultipleReturnTypes));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void BothTypesMustBeSameGreaterSmallerEqual(){
|
||||||
|
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/BothTypesMustBeSame.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void NoSuchType(){
|
||||||
|
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ClassNotDeclared.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotDeclaredException));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void FieldIsNotVisible(){
|
||||||
|
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/FieldIsNotVisible.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof NotVisibleException));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ChainedMethods(){
|
||||||
|
|
||||||
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/ChainedMethods.java");
|
||||||
|
|
||||||
|
SemanticAnalyzer.generateTast(tast);
|
||||||
|
|
||||||
|
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ Helpers ------------------
|
// ------------------ Helpers ------------------
|
||||||
|
|
||||||
|
32
src/test/java/semantic/SemanticHelper.java
Normal file
32
src/test/java/semantic/SemanticHelper.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package semantic;
|
||||||
|
|
||||||
|
import ast.ASTNode;
|
||||||
|
import ast.ProgramNode;
|
||||||
|
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 SemanticHelper {
|
||||||
|
public static ASTNode generateTypedASTFrom(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 (ProgramNode) astBuilder.visit(parseTree);
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25
src/test/resources/input/endabgabeTests/Car.java
Normal file
25
src/test/resources/input/endabgabeTests/Car.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Car myCar = new Car(2020);
|
||||||
|
int tires = 0;
|
||||||
|
int year = myCar.getYear();
|
||||||
|
|
||||||
|
if (year == 2020) {
|
||||||
|
tires = 4;
|
||||||
|
} else {
|
||||||
|
tires = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Car {
|
||||||
|
private int year;
|
||||||
|
|
||||||
|
public Car(int year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return this.year;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
public class ControlStructures {
|
||||||
|
|
||||||
|
public int sum(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public cahr checkNumber(int num) {
|
||||||
|
if (num > 0) {
|
||||||
|
return "p";
|
||||||
|
} else if (num < 0) {
|
||||||
|
return "n";
|
||||||
|
} else {
|
||||||
|
return "z";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printNumbersUpTo(int limit) {
|
||||||
|
int even = 0;
|
||||||
|
int uneven = 0;
|
||||||
|
int i = 0;
|
||||||
|
while (i < limit) {
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
even++;
|
||||||
|
} else {
|
||||||
|
uneven = uneven + 1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ControlStructures cs = new ControlStructures();
|
||||||
|
cs.printNumbersUpTo(5);
|
||||||
|
int result = cs.sum(5, 5);
|
||||||
|
}
|
||||||
|
}
|
11
src/test/resources/input/endabgabeTests/Person.java
Normal file
11
src/test/resources/input/endabgabeTests/Person.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
public class Person {
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
public Person(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return this.age;
|
||||||
|
}
|
||||||
|
}
|
@@ -5,5 +5,18 @@ public class AllFeaturesClassExample {
|
|||||||
while (a > bool) {
|
while (a > bool) {
|
||||||
a--;
|
a--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a == bool) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a < bool) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
public class Test {
|
||||||
|
|
||||||
|
public House h;
|
||||||
|
|
||||||
|
public int test(House h){
|
||||||
|
return h.getW().getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class House {
|
||||||
|
|
||||||
|
private Window w;
|
||||||
|
|
||||||
|
public Window getW(){
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Window{
|
||||||
|
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,9 +4,4 @@ public class Test {
|
|||||||
public House1 h;
|
public House1 h;
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class House {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
public class CorrectRetType {
|
||||||
|
public static int testMethod(int x){
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,4 @@
|
|||||||
|
public class FieldAlreadyDecleared {
|
||||||
|
public int a;
|
||||||
|
public int a;
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
public class MultipleRetTypes {
|
||||||
|
public static int testMethod(int x, char c){
|
||||||
|
return x;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
public class NotDeclared {
|
||||||
|
public void Method() {
|
||||||
|
i = 10;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
public class ParameterAlreadyDecleared {
|
||||||
|
public void Method(int a, int a) {}
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
public class Example {
|
||||||
|
public static int testMethod(char x){
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
public class TypeMismatchIntBool {
|
||||||
|
public void Method() {
|
||||||
|
int intVariable;
|
||||||
|
intVariable = true;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
public class TypeMismatchRefType {
|
||||||
|
public static int Methode(Class1 class1, Class2 class2){
|
||||||
|
class1 = class2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Class1{
|
||||||
|
public int a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Class2{
|
||||||
|
public boolean a;
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8
src/test/resources/input/singleFeatureTests/If.java
Normal file
8
src/test/resources/input/singleFeatureTests/If.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
public class If {
|
||||||
|
public If() {
|
||||||
|
int intValue = 5;
|
||||||
|
if(intValue == 5) {
|
||||||
|
intValue--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/test/resources/input/singleFeatureTests/IfElse.java
Normal file
10
src/test/resources/input/singleFeatureTests/IfElse.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
public class IfElse {
|
||||||
|
public IfElse() {
|
||||||
|
int intValue = 5;
|
||||||
|
if(intValue == 5) {
|
||||||
|
intValue--;
|
||||||
|
} else {
|
||||||
|
intValue++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,12 @@
|
|||||||
|
public class IfElseIfElse {
|
||||||
|
public IfElseIfElse() {
|
||||||
|
int intValue = 5;
|
||||||
|
if(intValue == 5) {
|
||||||
|
intValue--;
|
||||||
|
} else if(intValue ==4) {
|
||||||
|
intValue++;
|
||||||
|
} else {
|
||||||
|
intValue++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,13 +0,0 @@
|
|||||||
// @expected: TypeMismatchException
|
|
||||||
public class Test{
|
|
||||||
|
|
||||||
public void test(boolean b){
|
|
||||||
if(b == 2){
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,9 +1,13 @@
|
|||||||
public class CorrectTest {
|
public class Klasse1 {
|
||||||
|
public int test;
|
||||||
|
|
||||||
int a;
|
public int test1() {
|
||||||
|
test = 5;
|
||||||
public void test(){
|
return 1;
|
||||||
a = 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public void test2() {
|
||||||
|
int testInt;
|
||||||
|
testInt = this.test1();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user