diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java index 12a2eb9..621ec43 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java @@ -40,28 +40,34 @@ public class TypedFieldVarAccess implements TypedExpression { throw new RuntimeException("Field " + name + " not declared "); } } else { - if (clas.isThereField(name)) { - type = clas.getFieldType(name); - return type; - } else if (clas.isCurrentConstructorPresent()) { + if (clas.isCurrentConstructorPresent()) { if (clas.isParameterNameInCurrentConstructor(name)) { type = clas.getParameterTypeInCurrentConstructor(name); return type; } else if (clas.getCurrentConstructor().isLocalVariablePresent(name)) { type = clas.getCurrentConstructor().getLocalVariableType(name); return type; - } else { - throw new RuntimeException("Variable " + name + " not declared "); + } else if(clas.isThereField(name)){ + type = clas.getFieldType(name); + return type; } + else { + throw new RuntimeException("Variable " + name + " not declared in constructor"); + } + } else if (clas.isCurrentMethodPresent()) { if (clas.isParameterWitNameInMethod(name)) { type = clas.getParameterTypeInCurrentMethod(name); - return clas.getParameterTypeInCurrentMethod(name); + return type; } else if (clas.getCurrentMethod().isLocalVariablePresent(name)) { type = clas.getCurrentMethod().getLocalVariableType(name); return type; - } else { - throw new RuntimeException("Variable " + name + " not declared "); + } else if(clas.isThereField(name)){ + type = clas.getFieldType(name); + return type; + } + else { + throw new RuntimeException("Variable " + name + " not declared in method"); } } throw new RuntimeException("Variable " + name + " not declared ");