* Implemented converter for Modifier.
* Missing getters etc. in some classes added.
This commit is contained in:
parent
fbfa407c26
commit
68476f9f96
@ -5,6 +5,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.modifier.*;
|
||||||
import de.dhbwstuttgart.typecheck.*;
|
import de.dhbwstuttgart.typecheck.*;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@ -28,7 +29,11 @@ public class RunParser{
|
|||||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||||
String pkgName = f.getPkgName();
|
String pkgName = f.getPkgName();
|
||||||
System.out.println(pkgName);
|
System.out.println(pkgName);
|
||||||
|
System.out.println("classes:");
|
||||||
for(ClassOrInterface c : f.KlassenVektor){
|
for(ClassOrInterface c : f.KlassenVektor){
|
||||||
|
for(Modifier mod : c.getModifiers().getModifierList()){
|
||||||
|
System.out.println(mod.getClass().getName());
|
||||||
|
}
|
||||||
System.out.println(c.getClassName().toString());
|
System.out.println(c.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,14 @@ public class SyntaxTreeGenerator{
|
|||||||
|
|
||||||
private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx){
|
private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx){
|
||||||
Modifiers modifiers = null;
|
Modifiers modifiers = null;
|
||||||
|
if(ctx.classModifier() != null){
|
||||||
|
List<Modifier> 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());
|
JavaClassName name = convert(ctx.Identifier());
|
||||||
Block class_block = null;
|
Block class_block = null;
|
||||||
List<Field> fielddecl = null;
|
List<Field> fielddecl = null;
|
||||||
@ -89,6 +97,32 @@ public class SyntaxTreeGenerator{
|
|||||||
return new ClassOrInterface(modifiers, name, class_block, fielddecl, genericClassParameters, offset, superClass, isInterface, implementedInterfaces);
|
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.
|
Converts a TerminalNode to JavaClassName. If pkgName is set, it will be included like expected.
|
||||||
**/
|
**/
|
||||||
|
@ -55,5 +55,9 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get modifiers
|
||||||
|
public Modifiers getModifiers(){
|
||||||
|
return this.modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,9 @@ public class Modifiers
|
|||||||
public Modifiers(List<Modifier> modifier){
|
public Modifiers(List<Modifier> modifier){
|
||||||
this.modifier = modifier;
|
this.modifier = modifier;
|
||||||
}
|
}
|
||||||
// ino.end
|
|
||||||
|
|
||||||
|
|
||||||
|
public List<Modifier> getModifierList(){
|
||||||
|
return this.modifier;
|
||||||
}
|
}
|
||||||
// ino.end
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user