|
|
|
@ -210,78 +210,32 @@ public class EndToTypedAstTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void correctRetType(){
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/CorrectRetType.java");
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
|
try {
|
|
|
|
|
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/CorrectRetType.java"));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
|
|
|
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
|
|
|
|
|
|
|
|
|
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
|
|
|
|
ParseTree parseTree = parser.program();
|
|
|
|
|
|
|
|
|
|
ASTBuilder astBuilder = new ASTBuilder();
|
|
|
|
|
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
|
|
|
|
|
|
|
|
|
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
|
|
|
|
|
|
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void retTypeMismatch(){
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/RetTypeMismatch.java");
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
|
try {
|
|
|
|
|
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/retTypeMismatch.java"));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
|
|
|
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
|
|
|
|
|
|
|
|
|
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
|
|
|
|
ParseTree parseTree = parser.program();
|
|
|
|
|
|
|
|
|
|
ASTBuilder astBuilder = new ASTBuilder();
|
|
|
|
|
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
|
|
|
|
|
|
|
|
|
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
|
|
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
|
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
|
|
|
|
|
|
|
|
|
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void multipleRetType(){
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/MultipleRetTypes.java");
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
|
try {
|
|
|
|
|
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/MultipleRetTypes.java"));
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
|
|
|
|
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
|
|
|
|
|
|
|
|
|
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
|
|
|
|
ParseTree parseTree = parser.program();
|
|
|
|
|
|
|
|
|
|
ASTBuilder astBuilder = new ASTBuilder();
|
|
|
|
|
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
|
|
|
|
|
|
|
|
|
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
|
|
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
|
assertInstanceOf(MultipleReturnTypes.class, SemanticAnalyzer.errors.getFirst());
|
|
|
|
|
|
|
|
|
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof MultipleReturnTypes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------ Helpers ------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|