JMethod method = x.getTarget();
JsInvocation jsInvocation = new JsInvocation();
popList(jsInvocation.getArguments(), x.getArgs().size()); // args
JsNameRef qualifier;
JsExpression unnecessaryQualifier = null;
if (method.isStatic()) {
if (x.getInstance() != null) {
unnecessaryQualifier = (JsExpression) pop(); // instance
}
qualifier = getName(method).makeRef();
} else {
if (x.isStaticDispatchOnly()) {
/*
* Dispatch statically (odd case). This happens when a call that must
* be static is targeting an instance method that could not be
* transformed into a static. For example, making a super call into a
* native method currently causes this, because we cannot currently
* staticify native methods.
*
* Have to use a "call" construct.
*/
JsName callName = objectScope.declareName("call");
callName.setObfuscatable(false);
qualifier = callName.makeRef();
qualifier.setQualifier(getName(method).makeRef());
jsInvocation.getArguments().add(0, (JsExpression) pop()); // instance
} else {
// Dispatch polymorphically (normal case).
qualifier = getPolyName(method).makeRef();
qualifier.setQualifier((JsExpression) pop()); // instance
}
}
jsInvocation.setQualifier(qualifier);
push(createCommaExpression(unnecessaryQualifier, jsInvocation));
}