From 50a618ee4b2b3218f509d8f00f90eae947ca3243 Mon Sep 17 00:00:00 2001 From: Jakob Herrmann Date: Tue, 7 Feb 2017 22:12:40 +0100 Subject: [PATCH] SyntaxTreeGenerator.setPackageName() is now used properly. --- src/de/dhbwstuttgart/parser/RunParser.java | 2 +- src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/RunParser.java b/src/de/dhbwstuttgart/parser/RunParser.java index 7412bb42..660720f6 100644 --- a/src/de/dhbwstuttgart/parser/RunParser.java +++ b/src/de/dhbwstuttgart/parser/RunParser.java @@ -27,7 +27,7 @@ public class RunParser{ SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry()); SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree); String pkgName = f.getPkgName(); - System.out.println(pkgName); + System.out.println("package: " + pkgName); System.out.println("classes:"); for(ClassOrInterface c : f.KlassenVektor){ for(Modifier mod : c.getModifiers().getModifierList()){ diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index d16da9f3..87010abf 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -34,11 +34,12 @@ public class SyntaxTreeGenerator{ } public void getNames(Java8Parser.CompilationUnitContext ctx){ + if(this.pkgName == "") this.setPackageName(ctx); String nameString = ""; for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){ if(typeDecl.interfaceDeclaration() != null){ if(typeDecl.interfaceDeclaration().normalInterfaceDeclaration() != null){ - if(this.pkgName != null){ + if(this.pkgName != ""){ nameString = this.pkgName + "." + typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString(); } else{ @@ -116,9 +117,9 @@ public class SyntaxTreeGenerator{ private List convertFields(Java8Parser.ClassBodyContext classBodyContext) { List ret = new ArrayList<>(); for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){ - if(classMember.classMemberDeclaration()!= null){ + if(classMember.classMemberDeclaration() != null){ Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration(); - if(classMemberDeclarationContext.fieldDeclaration()!=null){ + if(classMemberDeclarationContext.fieldDeclaration() != null){ ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration())); }else if(classMemberDeclarationContext.methodDeclaration()!= null){ ret.add(convert(classMemberDeclarationContext.methodDeclaration())); @@ -134,8 +135,9 @@ public class SyntaxTreeGenerator{ RefType retType; if(header.result() != null){ - if(header.result().unannType() != null) + if(header.result().unannType() != null){ retType = convert(header.result().unannType()); + } else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart()); }else{ retType = TypePlaceholder.fresh(header.getStart());