* Start implementing "getters and setters" for
symtaxtree.ClassOrInterface (=no choice!!!). * Start implementing converters TypeDeclerytion -> Class.
This commit is contained in:
parent
3c6ffcf4d8
commit
647196bf16
@ -24,12 +24,11 @@ public class RunParser{
|
||||
Java8Parser parser = new Java8Parser(tokens);
|
||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||
// generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
generator.getNames(tree);
|
||||
for(JavaClassName name : generator.reg.existingClasses){
|
||||
System.out.println(name.toString());
|
||||
}
|
||||
System.out.println(generator.reg.existingClasses.size());
|
||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
for(ClassOrInterface c : f.KlassenVektor){
|
||||
System.out.println(c.getClassName().toString());
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||
|
@ -7,17 +7,16 @@ import de.dhbwstuttgart.typecheck.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
public class SyntaxTreeGenerator{
|
||||
JavaClassRegistry reg = new JavaClassRegistry();
|
||||
String packageDecl = "";
|
||||
|
||||
public void getNames(Java8Parser.CompilationUnitContext ctx){
|
||||
String packageDecl = "";
|
||||
if(ctx.packageDeclaration() != null){
|
||||
for(TerminalNode t : ctx.packageDeclaration().Identifier()){
|
||||
packageDecl = packageDecl + "." + t.toString();
|
||||
this.packageDecl = this.packageDecl + "." + t.toString();
|
||||
}
|
||||
packageDecl = packageDecl.substring(1);
|
||||
this.packageDecl = this.packageDecl.substring(1);
|
||||
}
|
||||
String nameString = "";
|
||||
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
@ -46,18 +45,25 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||
List<ClassOrInterface> classes = new ArrayList<>();
|
||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
ClassOrInterface newClass = convert(typeDecl.classDeclaration());
|
||||
classes.add(newClass);
|
||||
}
|
||||
return new SourceFile(classes);
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||
List<ClassOrInterface> classes = new ArrayList<>();
|
||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
ClassOrInterface newClass = convert(typeDecl.classDeclaration());
|
||||
classes.add(newClass);
|
||||
}
|
||||
return new SourceFile(classes);
|
||||
}
|
||||
|
||||
private ClassOrInterface convert(Java8Parser.ClassDeclarationContext ctx) {
|
||||
//TODO: Implement
|
||||
return null;
|
||||
private ClassOrInterface convert(Java8Parser.ClassDeclarationContext ctx) {
|
||||
ClassOrInterface newClass = new ClassOrInterface();
|
||||
String name = "";
|
||||
if(this.packageDecl != ""){
|
||||
name = packageDecl + "." + ctx.normalClassDeclaration().Identifier().toString();
|
||||
}
|
||||
else{
|
||||
name = ctx.normalClassDeclaration().Identifier().toString();
|
||||
}
|
||||
newClass.setClassName(new JavaClassName(name));
|
||||
return newClass;
|
||||
}
|
||||
}
|
||||
|
@ -13,18 +13,24 @@ import java.util.List;
|
||||
/**
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
*/
|
||||
public class ClassOrInterface extends GTVDeclarationContext implements IItemWithOffset, Generic
|
||||
{
|
||||
|
||||
protected Modifiers modifiers;
|
||||
protected JavaClassName name;
|
||||
private Block class_block;
|
||||
private List<Field> fielddecl = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private int offset;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
|
||||
|
||||
public class ClassOrInterface extends GTVDeclarationContext implements IItemWithOffset, Generic{
|
||||
protected Modifiers modifiers;
|
||||
protected JavaClassName name;
|
||||
private Block class_block;
|
||||
private List<Field> fielddecl = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private int offset;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
|
||||
// Gets class name
|
||||
public JavaClassName getClassName(){
|
||||
return this.name;
|
||||
}
|
||||
|
||||
// Sets class name.
|
||||
public void setClassName(JavaClassName name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user