diff --git a/src/de/dhbwstuttgart/parser/RunParser.java b/src/de/dhbwstuttgart/parser/RunParser.java index b557f0a1d..10e4ea8bb 100644 --- a/src/de/dhbwstuttgart/parser/RunParser.java +++ b/src/de/dhbwstuttgart/parser/RunParser.java @@ -5,6 +5,7 @@ import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.tree.ParseTreeWalker; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.modifier.*; import de.dhbwstuttgart.typecheck.*; import java.util.Scanner; @@ -28,7 +29,11 @@ public class RunParser{ SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree); String pkgName = f.getPkgName(); System.out.println(pkgName); + System.out.println("classes:"); for(ClassOrInterface c : f.KlassenVektor){ + for(Modifier mod : c.getModifiers().getModifierList()){ + System.out.println(mod.getClass().getName()); + } System.out.println(c.getClassName().toString()); } } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 2da9691e0..32c721e78 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -78,6 +78,14 @@ public class SyntaxTreeGenerator{ private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx){ Modifiers modifiers = null; + if(ctx.classModifier() != null){ + List modList = new ArrayList(); + for(Java8Parser.ClassModifierContext mod : ctx.classModifier()){ + Modifier newModifier = convert(mod); + modList.add(newModifier); + } + modifiers = new Modifiers(modList); + } JavaClassName name = convert(ctx.Identifier()); Block class_block = null; List fielddecl = null; @@ -89,6 +97,32 @@ public class SyntaxTreeGenerator{ return new ClassOrInterface(modifiers, name, class_block, fielddecl, genericClassParameters, offset, superClass, isInterface, implementedInterfaces); } + private Modifier convert(Java8Parser.ClassModifierContext ctx){ + Modifier newModifier = null; + if(ctx.annotation() == null){ + TerminalNode t = (TerminalNode)ctx.getChild(0); + if(t.getText().equals("public")){ + newModifier = new Public(); + } + else if(t.getText().equals("private")){ + newModifier = new Private(); + } + else if(t.getText().equals("protected")){ + newModifier = new Protected(); + } + else if(t.getText().equals("abstract")){ + newModifier = new Abstract(); + } + else if(t.getText().equals("static")){ + newModifier = new Static(); + } + else{ + newModifier = new Final(); + } + } + return newModifier; + } + /** Converts a TerminalNode to JavaClassName. If pkgName is set, it will be included like expected. **/ diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index e160972b7..89fe9daa5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -55,5 +55,9 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith return this.name; } + // Get modifiers + public Modifiers getModifiers(){ + return this.modifiers; + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java b/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java index 101622035..dfb4785f9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java +++ b/src/de/dhbwstuttgart/syntaxtree/modifier/Modifiers.java @@ -18,9 +18,10 @@ public class Modifiers public Modifiers(List modifier){ this.modifier = modifier; - } - // ino.end - - + } + + public List getModifierList(){ + return this.modifier; + } } -// ino.end +