package jfun.yan;
import jfun.util.SerializableField;
import jfun.yan.function.Function;
/**
* For an instance field with the receiver object not fixed.
* <p>
* Zephyr Business Solution
*
* @author Ben Yu
*
*/
final class FloatingFieldFunction implements Function {
private final Class type;
private final SerializableField fld;
public boolean isConcrete(){
return false;
}
FloatingFieldFunction(final Class type,
final java.lang.reflect.Field fld) {
this.type = type;
this.fld = new SerializableField(fld);
}
public Class getReturnType() {
return fld.getField().getType();
}
public Class[] getParameterTypes() {
return new Class[]{type};
}
public Object call(Object[] args)
throws IllegalAccessException{
return fld.getField().get(args[0]);
}
public boolean equals(Object obj) {
if(obj instanceof FloatingFieldFunction){
final FloatingFieldFunction other = (FloatingFieldFunction)obj;
return type.equals(other.type) && fld.equals(other.fld);
}
else return false;
}
public int hashCode() {
return type.hashCode()*31+fld.hashCode();
}
public String toString() {
return jfun.util.Misc.getTypeName(type)
+ "::" + fld.getField().getName();
}
public String getName(){
return fld.getField().getName();
}
}