This commit is contained in:
JanUlrich 2017-02-03 15:21:45 +01:00
commit d064f16de4
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.parser;
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import de.dhbwstuttgart.syntaxtree.*;
@ -23,7 +24,7 @@ public class RunParser{
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry());
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
String pkgName = f.getPkgName();
System.out.println(pkgName);

View File

@ -16,17 +16,24 @@ import java.util.List;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
public class SyntaxTreeGenerator{
JavaClassRegistry reg = new JavaClassRegistry();
String pkgName = "";
List<JavaClassName> imports = null;
private JavaClassRegistry reg;
private String pkgName = "";
List<JavaClassName> imports = new ArrayList();
public void getNames(Java8Parser.CompilationUnitContext ctx){
public SyntaxTreeGenerator(JavaClassRegistry reg){
this.reg = reg;
}
public void setPackageName(Java8Parser.CompilationUnitContext ctx){
if(ctx.packageDeclaration() != null){
for(TerminalNode t : ctx.packageDeclaration().Identifier()){
this.pkgName = this.pkgName + "." + t.toString();
}
this.pkgName = this.pkgName.substring(1);
}
}
public void getNames(Java8Parser.CompilationUnitContext ctx){
String nameString = "";
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
if(typeDecl.interfaceDeclaration() != null){
@ -53,6 +60,10 @@ public class SyntaxTreeGenerator{
}
}
}
public JavaClassRegistry getReg(){
return this.reg;
}
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
List<ClassOrInterface> classes = new ArrayList<>();