* 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 parser = new Java8Parser(tokens);
|
||||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||||
// generator.convert((Java8Parser.CompilationUnitContext) tree);
|
|
||||||
generator.getNames(tree);
|
generator.getNames(tree);
|
||||||
for(JavaClassName name : generator.reg.existingClasses){
|
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||||
System.out.println(name.toString());
|
for(ClassOrInterface c : f.KlassenVektor){
|
||||||
}
|
System.out.println(c.getClassName().toString());
|
||||||
System.out.println(generator.reg.existingClasses.size());
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
public class SyntaxTreeGenerator{
|
public class SyntaxTreeGenerator{
|
||||||
JavaClassRegistry reg = new JavaClassRegistry();
|
JavaClassRegistry reg = new JavaClassRegistry();
|
||||||
|
String packageDecl = "";
|
||||||
|
|
||||||
public void getNames(Java8Parser.CompilationUnitContext ctx){
|
public void getNames(Java8Parser.CompilationUnitContext ctx){
|
||||||
String packageDecl = "";
|
|
||||||
if(ctx.packageDeclaration() != null){
|
if(ctx.packageDeclaration() != null){
|
||||||
for(TerminalNode t : ctx.packageDeclaration().Identifier()){
|
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 = "";
|
String nameString = "";
|
||||||
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||||
@ -46,18 +45,25 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
||||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
|
List<ClassOrInterface> classes = new ArrayList<>();
|
||||||
List<ClassOrInterface> classes = new ArrayList<>();
|
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
ClassOrInterface newClass = convert(typeDecl.classDeclaration());
|
||||||
ClassOrInterface newClass = convert(typeDecl.classDeclaration());
|
classes.add(newClass);
|
||||||
classes.add(newClass);
|
|
||||||
}
|
|
||||||
return new SourceFile(classes);
|
|
||||||
}
|
}
|
||||||
|
return new SourceFile(classes);
|
||||||
|
}
|
||||||
|
|
||||||
private ClassOrInterface convert(Java8Parser.ClassDeclarationContext ctx) {
|
private ClassOrInterface convert(Java8Parser.ClassDeclarationContext ctx) {
|
||||||
//TODO: Implement
|
ClassOrInterface newClass = new ClassOrInterface();
|
||||||
return null;
|
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
|
* 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;
|
||||||
protected Modifiers modifiers;
|
private Block class_block;
|
||||||
protected JavaClassName name;
|
private List<Field> fielddecl = new ArrayList<>();
|
||||||
private Block class_block;
|
private GenericDeclarationList genericClassParameters;
|
||||||
private List<Field> fielddecl = new ArrayList<>();
|
private int offset;
|
||||||
private GenericDeclarationList genericClassParameters;
|
private RefType superClass;
|
||||||
private int offset;
|
protected boolean isInterface;
|
||||||
private RefType superClass;
|
private List<RefType> implementedInterfaces;
|
||||||
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