NichtHaskell/Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java
2024-05-02 15:31:31 +02:00

43 lines
1.2 KiB
Java

package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Datatype.RefType;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
import java.util.List;
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
String methodName;
List<IExpression> arguments;
RefType classThatHasTheMethodIfNotThis;
RefType thisClass;
public MethodCallStatementExpression(String methodName, List<IExpression> arguments) {
this.methodName = methodName;
this.arguments = arguments;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();
RefType searchMethodHere;
if(classThatHasTheMethodIfNotThis == null){
searchMethodHere = thisClass;
} else {
searchMethodHere = classThatHasTheMethodIfNotThis;
}
List<MethodDecl> methods = searchMethodHere.methodDecls;
if(!methods.contains(methodName)){
throw new Exception("method not found");
}
return result;
}
}