2014-06-09 20:33:30 +02:00
|
|
|
/*
|
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
|
* and open the template in the editor.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package stanhebben.zenscript.expression.partial;
|
|
|
|
|
|
2014-08-20 11:59:49 +02:00
|
|
|
import java.util.Arrays;
|
2014-06-09 20:33:30 +02:00
|
|
|
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
|
|
|
|
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
|
|
|
|
import stanhebben.zenscript.expression.Expression;
|
2014-08-20 11:59:49 +02:00
|
|
|
import stanhebben.zenscript.expression.ExpressionCallStatic;
|
2014-06-09 20:33:30 +02:00
|
|
|
import stanhebben.zenscript.expression.ExpressionInvalid;
|
|
|
|
|
import stanhebben.zenscript.symbols.IZenSymbol;
|
|
|
|
|
import stanhebben.zenscript.symbols.SymbolJavaStaticMethod;
|
|
|
|
|
import stanhebben.zenscript.type.ZenType;
|
2014-08-20 11:59:49 +02:00
|
|
|
import stanhebben.zenscript.type.natives.IJavaMethod;
|
2014-06-09 20:33:30 +02:00
|
|
|
import stanhebben.zenscript.util.ZenPosition;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Stanneke
|
|
|
|
|
*/
|
|
|
|
|
public class PartialStaticMethod implements IPartialExpression {
|
|
|
|
|
private final ZenPosition position;
|
2014-08-20 11:59:49 +02:00
|
|
|
private final IJavaMethod method;
|
2014-06-09 20:33:30 +02:00
|
|
|
|
2014-08-20 11:59:49 +02:00
|
|
|
public PartialStaticMethod(ZenPosition position, IJavaMethod method) {
|
2014-06-09 20:33:30 +02:00
|
|
|
this.position = position;
|
|
|
|
|
this.method = method;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Expression eval(IEnvironmentGlobal environment) {
|
|
|
|
|
environment.error(position, "not a valid expression");
|
|
|
|
|
return new ExpressionInvalid(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Expression assign(ZenPosition position, IEnvironmentGlobal environment, Expression other) {
|
|
|
|
|
environment.error(position, "cannot alter this final");
|
|
|
|
|
return new ExpressionInvalid(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IPartialExpression getMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
|
|
|
|
|
environment.error(position, "methods have no members");
|
|
|
|
|
return new ExpressionInvalid(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Expression call(ZenPosition position, IEnvironmentMethod environment, Expression... values) {
|
|
|
|
|
if (method.accepts(environment, values)) {
|
2014-08-20 11:59:49 +02:00
|
|
|
return new ExpressionCallStatic(position, environment, method, values);
|
2014-06-09 20:33:30 +02:00
|
|
|
} else {
|
|
|
|
|
environment.error(position, "parameter count mismatch");
|
|
|
|
|
return new ExpressionInvalid(position, method.getReturnType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 11:59:49 +02:00
|
|
|
@Override
|
|
|
|
|
public ZenType[] predictCallTypes(int numArguments) {
|
|
|
|
|
return Arrays.copyOf(method.getParameterTypes(), numArguments);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 20:33:30 +02:00
|
|
|
@Override
|
|
|
|
|
public IZenSymbol toSymbol() {
|
|
|
|
|
return new SymbolJavaStaticMethod(method);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 11:59:49 +02:00
|
|
|
@Override
|
|
|
|
|
public ZenType getType() {
|
|
|
|
|
return method.getReturnType();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 20:33:30 +02:00
|
|
|
@Override
|
|
|
|
|
public ZenType toType(IEnvironmentGlobal environment) {
|
|
|
|
|
return ZenType.ANY;
|
|
|
|
|
}
|
|
|
|
|
}
|