Idea to resolve the problem with initial fields.

This commit is contained in:
Jakob Herrmann 2017-02-15 00:51:34 +01:00
parent cca2da8018
commit 7f05966093

View File

@ -5,7 +5,7 @@ import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.modifier.*; import de.dhbwstuttgart.syntaxtree.modifier.*;
import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.*; import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.*;
import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier; import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier;
import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
@ -198,22 +198,26 @@ public class SyntaxTreeGenerator{
List<Field> ret = new ArrayList<>(); List<Field> ret = new ArrayList<>();
List<FieldModifier> modifiers = new ArrayList<>(); List<FieldModifier> modifiers = new ArrayList<>();
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){ for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
//TODO modifiers.add(convert(fieldModifierContext));
} }
RefTypeOrTPH fieldType = convert(fieldDeclarationContext.unannType()); RefTypeOrTPH fieldType = convert(fieldDeclarationContext.unannType());
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){ for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
String fieldName = varCtx.variableDeclaratorId().getText(); String fieldName = varCtx.variableDeclaratorId().getText();
if(varCtx.variableInitializer() != null){ if(varCtx.variableInitializer() != null){
//Feld mit Initialwert initializeField(fieldDeclarationContext);
//TODO }
}else{ else{
//Feld ohne Initialwert
ret.add(new Field(fieldName,fieldType,modifiers,varCtx.getStart())); ret.add(new Field(fieldName,fieldType,modifiers,varCtx.getStart()));
} }
} }
return ret; return ret;
} }
// Initialize a field by creating implicit constructor.
private void initializeField(Java8Parser.FieldDeclarationContext ctx){
//TODO
}
private RefTypeOrTPH convert(Java8Parser.UnannTypeContext unannTypeContext) { private RefTypeOrTPH convert(Java8Parser.UnannTypeContext unannTypeContext) {
if(unannTypeContext.unannPrimitiveType()!=null){ if(unannTypeContext.unannPrimitiveType()!=null){
throw new NotImplementedException(); throw new NotImplementedException();