* SyntaxTreeGenerator: Implemented method to get package name of

CompilationUnitCtx (ongoing).
* RunParser: test methods
This commit is contained in:
Jakob Herrmann 2017-01-10 17:42:20 +01:00
parent f0028f6aaf
commit 599c8b2573
2 changed files with 19 additions and 4 deletions

View File

@ -21,9 +21,10 @@ public class RunParser{
Java8Lexer lexer = new Java8Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
ParserRuleContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(null);
generator.convert((Java8Parser.CompilationUnitContext) tree);
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
// generator.convert((Java8Parser.CompilationUnitContext) tree);
generator.getNames(tree);
}
catch(Exception e){
System.out.println("An exception occured which is unknown and on our TODO list.");

View File

@ -2,13 +2,27 @@ package de.dhbwstuttgart.parser;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
import de.dhbwstuttgart.typecheck.*;
import java.util.ArrayList;
import java.util.List;
import org.antlr.v4.runtime.tree.TerminalNode;
public class SyntaxTreeGenerator{
JavaClassRegistry reg = new JavaClassRegistry();
public void getNames(Java8Parser.CompilationUnitContext ctx){
List<JavaClassName> names = new ArrayList();
String packageDecl = "";
List<TerminalNode> decls = ctx.packageDeclaration().Identifier();
if(decls != null){
for(TerminalNode t : decls){
packageDecl = packageDecl + "." + t.toString();
}
packageDecl = packageDecl.substring(1);
System.out.println(packageDecl);
}
}
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){