* 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());
|
||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
for(ClassOrInterface c : f.KlassenVektor){
|
||||
System.out.println(c.getClassName().toString());
|
||||
}
|
||||
System.out.println(generator.reg.existingClasses.size());
|
||||
}
|
||||
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,7 +45,6 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||
List<ClassOrInterface> classes = new ArrayList<>();
|
||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||
@ -57,7 +55,15 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
|
||||
private ClassOrInterface convert(Java8Parser.ClassDeclarationContext ctx) {
|
||||
//TODO: Implement
|
||||
return null;
|
||||
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,9 +13,7 @@ import java.util.List;
|
||||
/**
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
*/
|
||||
public class ClassOrInterface extends GTVDeclarationContext implements IItemWithOffset, Generic
|
||||
{
|
||||
|
||||
public class ClassOrInterface extends GTVDeclarationContext implements IItemWithOffset, Generic{
|
||||
protected Modifiers modifiers;
|
||||
protected JavaClassName name;
|
||||
private Block class_block;
|
||||
@ -26,5 +24,13 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
||||
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