Field Initialisierungen anfügen

This commit is contained in:
JanUlrich 2018-08-29 02:43:32 +02:00
parent 72e128d3f3
commit 1a8115bf07
3 changed files with 30 additions and 1 deletions

View File

@ -445,7 +445,7 @@ public class StatementGenerator {
} }
return (new Assign(new AssignToField( return (new Assign(new AssignToField(
new FieldVar(new This(varDecl.getStart()), name.getText(), new FieldVar(new This(varDecl.getStart()), name.getText(),
new Void(varDecl.getStart()), varDecl.getStart())), type, varDecl.getStart())),
initValue, name.getSymbol())); initValue, name.getSymbol()));
} }

View File

@ -5,6 +5,7 @@ import de.dhbwstuttgart.exceptions.NotImplementedException;
import java.lang.ClassNotFoundException; import java.lang.ClassNotFoundException;
import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.parser.scope.GatherNames; import de.dhbwstuttgart.parser.scope.GatherNames;
import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.scope.GenericsRegistry;
@ -195,6 +196,7 @@ public class SyntaxTreeGenerator{
superClass = new RefType(ASTFactory.createObjectClass().getClassName(), ctx.getStart()); superClass = new RefType(ASTFactory.createObjectClass().getClassName(), ctx.getStart());
} }
List<Field> fielddecl = convertFields(ctx.classBody(), generics); List<Field> fielddecl = convertFields(ctx.classBody(), generics);
//fieldInitializations = generateFieldInitializations(ctx.classBody(), generics);
List<Method> methods = convertMethods(ctx.classBody(), name, superClass, generics); List<Method> methods = convertMethods(ctx.classBody(), name, superClass, generics);
List<Constructor> konstruktoren = new ArrayList<>(); List<Constructor> konstruktoren = new ArrayList<>();
for(int i = 0; i<methods.size();i++){ for(int i = 0; i<methods.size();i++){
@ -218,6 +220,32 @@ public class SyntaxTreeGenerator{
isInterface, implementedInterfaces, offset); isInterface, implementedInterfaces, offset);
} }
/*
private List<Statement> generateFieldInitializations(Java8Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
List<Statement> ret = new ArrayList<>();
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
if(classMember.classMemberDeclaration() != null){
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
if(classMemberDeclarationContext.fieldDeclaration() != null
&& classMemberDeclarationContext.fieldDeclaration().variableDeclaratorList() != null){
for(Java8Parser.VariableDeclaratorContext ctx : classMemberDeclarationContext.fieldDeclaration().variableDeclaratorList().variableDeclarator()) {
String fieldName = ctx.variableDeclaratorId().Identifier().getText();
if(ctx.variableDeclaratorId().dims() != null)throw new NotImplementedException();
Token offset = ctx.getStart();
RefTypeOrTPHOrWildcardOrGeneric fieldType;
for(Field f : fields)
AssignToField leftSide = new AssignToField(new FieldVar(new This(offset), fieldName, ));
ret.addAll();
}
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
//Do nothing!
}
}
}
return ret;
}
*/
private List<RefType> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) { private List<RefType> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
if(ctx == null)return new ArrayList<>(); if(ctx == null)return new ArrayList<>();
return convert(ctx.interfaceTypeList(), generics); return convert(ctx.interfaceTypeList(), generics);

View File

@ -28,6 +28,7 @@ public class Constructor extends Method {
protected static Block prepareBlock(Block constructorBlock, List<Statement> fieldInitializations){ protected static Block prepareBlock(Block constructorBlock, List<Statement> fieldInitializations){
List<Statement> statements = constructorBlock.getStatements(); List<Statement> statements = constructorBlock.getStatements();
statements.add(0, new SuperCall(constructorBlock.getOffset())); statements.add(0, new SuperCall(constructorBlock.getOffset()));
statements.addAll(fieldInitializations);
return new Block(statements, constructorBlock.getOffset()); return new Block(statements, constructorBlock.getOffset());
} }