package net.sourceforge.javautil.bytecode.api.type.method.invocation;
import net.sourceforge.javautil.bytecode.api.IBytecodeReferenceable;
import net.sourceforge.javautil.bytecode.api.BytecodeReferenceableAbstract;
import net.sourceforge.javautil.bytecode.api.TypeDescriptor;
import net.sourceforge.javautil.bytecode.api.type.method.BytecodeContextMethod;
import net.sourceforge.javautil.bytecode.api.type.method.IBytecodeMethod;
/**
* This represents a method invocation.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class MethodInvocation extends BytecodeReferenceableAbstract<BytecodeContextMethod> {
protected final IBytecodeReferenceable parent;
protected final IBytecodeMethod method;
protected final IBytecodeReferenceable[] parameters;
public MethodInvocation(IBytecodeReferenceable parent, IBytecodeMethod method, IBytecodeReferenceable[] parameters) {
super(method.getDescriptor().getReturnType());
this.parent = parent;
this.method = method;
this.parameters = parameters;
}
/**
* @return The method this invocation is for
*/
public IBytecodeMethod getMethod() { return method; }
public int getParameterCount () { return parameters.length; }
public IBytecodeReferenceable getParameter (int idx) { return parameters[idx]; }
public void load(BytecodeContextMethod context) {
if (parent != null) parent.load(context);
TypeDescriptor[] types = new TypeDescriptor[parameters.length];
for (int p=0; p<parameters.length; p++) {
IBytecodeReferenceable parameter = parameters[p];
parameter.load(context);
types[p] = parameter.getType();
}
context.getWriter().invoke(context, parent == null ? method.getDeclaringType() :
context.getResolutionPool().resolve(parent.getType().getClassName()), method);
}
}