update the typeCheck of TypedParameter

This commit is contained in:
ahmad 2024-05-11 13:54:12 +02:00
parent 9f4b158237
commit e49691ff29

View File

@ -6,7 +6,6 @@ import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.Map; import java.util.Map;
@ -24,15 +23,23 @@ public class TypedParameter implements TypedNode {
public void convertToTypedParameter(Map<String, Type> localVar, TypedClass clas, Parameter unTypedParameter) { public void convertToTypedParameter(Map<String, Type> localVar, TypedClass clas, Parameter unTypedParameter) {
paraName = unTypedParameter.name(); paraName = unTypedParameter.name();
type = unTypedParameter.type(); type = unTypedParameter.type();
localVar.put(paraName, type); //localVar.put(paraName, type);
} }
@Override @Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) { public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
if (localVar.containsKey(paraName)) {
if(clas.isCurrentMethodPresent()){
if(clas.isParameterWitNameInMethod(paraName)) {
throw new RuntimeException("Parameter " + paraName + " already exists"); throw new RuntimeException("Parameter " + paraName + " already exists");
} }
localVar.put(paraName, type); }else if(clas.isCurrentConstructorPresent()){
if(clas.isParameterWitNameInConstructor(paraName)) {
throw new RuntimeException("Parameter " + paraName + " already exists");
}
}
return type; return type;
} }