diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java index 197db8c..cc8992e 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedAssignment.java @@ -16,9 +16,8 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; @Data public class TypedAssignment implements TypedStatement { - private String varName; private TypedExpression value; - private TypedExpression recursiveOwnerChain; + private TypedFieldVarAccess location; private Type type; public TypedAssignment(TypedClass clas, Assignment untyped) { @@ -26,30 +25,29 @@ public class TypedAssignment implements TypedStatement { } public void convertToTypedAssignment(TypedClass clas, Assignment untyped) { - varName = untyped.location().id(); value = convertExpression(clas, untyped.value()); - recursiveOwnerChain = convertExpression( clas, untyped.location().recursiveOwnerChain()); + location = new TypedFieldVarAccess(clas, untyped.location()); } @Override public Type typeCheck(TypedClass clas) { Type typeLeft = null; - if (clas.isThereField(varName)) { - typeLeft = clas.getFieldType(varName); + if (clas.isThereField(location.getName())) { + typeLeft = clas.getFieldType(location.getName()); } else { if (clas.isCurrentMethodPresent() && !clas.isCurrentConstructorPresent()) { - if (clas.getCurrentMethod().isLocalVariableInMethod(varName)) { - typeLeft = clas.getCurrentMethod().getLocalVariableType(varName); + if (clas.getCurrentMethod().isLocalVariableInMethod(location.getName())) { + typeLeft = clas.getCurrentMethod().getLocalVariableType(location.getName()); } else { - throw new RuntimeException("Variable " + varName + " not declared in method"); + throw new RuntimeException("Variable " + location.getName() + " not declared in method"); } } if (!clas.isCurrentMethodPresent() && clas.isCurrentConstructorPresent()) { - if (clas.getCurrentConstructor().isLocalVariableInConstructor(varName)) { - typeLeft = clas.getCurrentConstructor().getLocalVariableType(varName); + if (clas.getCurrentConstructor().isLocalVariableInConstructor(location.getName())) { + typeLeft = clas.getCurrentConstructor().getLocalVariableType(location.getName()); } else { - throw new RuntimeException("Variable " + varName + " not declared in constructor"); + throw new RuntimeException("Variable " + location.getName() + " not declared in constructor"); } } } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java b/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java index a2bdfb9..d3962af 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedMethodCall.java @@ -12,6 +12,8 @@ import java.util.Map; import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression; +//TODO: test this after fixing error from parser + @Data @NoArgsConstructor public class TypedMethodCall implements TypedExpression, TypedStatement { @@ -28,11 +30,33 @@ public class TypedMethodCall implements TypedExpression, TypedStatement { for (Expression arg : unTypedMethodCall.args()) { args.add(convertExpression(clas, arg)); } + recipient.getName(); } @Override public Type typeCheck(TypedClass clas) { - //TODO: implement this + /* if (clas.isCurrentMethodPresent()) { + + List methods = clas.getTypedMethods().stream() + .filter(method -> method.getName().equals(name)) + .toList(); + + for (TypedMethod method : methods) { + if (method.getTypedParameters().size() == args.size()) { + boolean allMatch = true; + for (int i = 0; i < args.size(); i++) { + if (!args.get(i).typeCheck(clas).equals(method.getTypedParameters().get(i).getType())) { + allMatch = false; + break; + } + } + if (allMatch) { + return method.getReturnType(); + } + } + } + + } */ return null; }