forked from JavaTX/JavaCompilerCore
* SyntaxTreeGenerator: Implemented method to get package name of
CompilationUnitCtx (ongoing). * RunParser: test methods
This commit is contained in:
parent
f0028f6aaf
commit
599c8b2573
@ -21,9 +21,10 @@ public class RunParser{
|
|||||||
Java8Lexer lexer = new Java8Lexer(input);
|
Java8Lexer lexer = new Java8Lexer(input);
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
Java8Parser parser = new Java8Parser(tokens);
|
Java8Parser parser = new Java8Parser(tokens);
|
||||||
ParserRuleContext tree = parser.compilationUnit();
|
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(null);
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||||
generator.convert((Java8Parser.CompilationUnitContext) tree);
|
// generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||||
|
generator.getNames(tree);
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||||
|
@ -2,13 +2,27 @@ package de.dhbwstuttgart.parser;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
import de.dhbwstuttgart.typecheck.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
public class SyntaxTreeGenerator{
|
public class SyntaxTreeGenerator{
|
||||||
JavaClassRegistry reg = new JavaClassRegistry();
|
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){
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||||
|
Loading…
Reference in New Issue
Block a user