From 9e45c65ea35acec5f51acfb24e3230f014478113 Mon Sep 17 00:00:00 2001 From: ahmad Date: Sat, 11 May 2024 13:52:55 +0200 Subject: [PATCH] Update the typeCheck of methods TypedFieldVarAccess --- .../typedclass/TypedFieldVarAccess.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java index 490a11a..168aaef 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedFieldVarAccess.java @@ -28,38 +28,36 @@ public class TypedFieldVarAccess implements TypedExpression { recursiveOwnerChain = getKindOfExpression(localVar, clas, unTypedFieldVarAccess.recursiveOwnerChain()); name = unTypedFieldVarAccess.id(); - if(field) { - if (clas.isThereField(name)) { - type = clas.getFieldType(name); - } - } else if(localVar.containsKey(name)){ - type = localVar.get(name); - }else{ - throw new RuntimeException("Variable not declared"); - } - - - } @Override public Type typeCheck(Map localVar, TypedClass clas) { - - - if(field){ - if(clas.isThereField(name)){ - type = clas.getFieldType(name); + if(field){ + if (clas.isThereField(name)) { + type = clas.getFieldType(name); + return clas.getFieldType(name); + } + }else{ + if (clas.isThereField(name)) { + type = clas.getFieldType(name); + return clas.getFieldType(name); + }else if(clas.isCurrentConstructorPresent()){ + if(clas.isParameterNameInCurrentConstructor(name)){ + type = clas.getParameterTypeInCurrentConstructor(name); + return clas.getParameterTypeInCurrentConstructor(name); + } + }else if(clas.isCurrentMethodPresent()){ + if(clas.isParameterWitNameInMethod(name)){ + type = clas.getParameterTypeInCurrentMethod(name); + return clas.getParameterTypeInCurrentMethod(name); + } + } + if(localVar.containsKey(name)) { + type = localVar.get(name); + return localVar.get(name); + } } - }else{ - if(clas.isParameterWitNameInMethod(name)){ - type = clas.getParameterType(name); - }else if(localVar.containsKey(name)){ - type = localVar.get(name); - } - } - - - return type; + throw new RuntimeException("Variable "+name+" not declared "); } @Override