|
|
@ -207,76 +207,31 @@ public class EndToTypedAstTest {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void correctRetType(){
|
|
|
|
public void correctRetType(){
|
|
|
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/CorrectRetType.java");
|
|
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
assertTrue(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void retTypeMismatch(){
|
|
|
|
public void retTypeMismatch(){
|
|
|
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/johnsTests/RetTypeMismatch.java");
|
|
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
assertInstanceOf(TypeMismatchException.class, SemanticAnalyzer.errors.getFirst());
|
|
|
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof TypeMismatchException));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void multipleRetType(){
|
|
|
|
public void multipleRetType(){
|
|
|
|
|
|
|
|
ASTNode tast = SemanticHelper.generateTypedASTFrom("src/test/resources/input/singleFeatureSemanticTests/MultipleRetTypes.java");
|
|
|
|
|
|
|
|
|
|
|
|
CharStream codeCharStream = null;
|
|
|
|
SemanticAnalyzer.generateTast(tast);
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
assertFalse(SemanticAnalyzer.errors.isEmpty());
|
|
|
|
assertInstanceOf(MultipleReturnTypes.class, SemanticAnalyzer.errors.getFirst());
|
|
|
|
assertTrue(SemanticAnalyzer.errors.stream().anyMatch(c -> c instanceof MultipleReturnTypes));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|