use of kalang.ast.StaticInvokeExpr in project kalang by kasonyang.
the class Ast2Class method visitInvocationExpr.
@Override
public Object visitInvocationExpr(InvocationExpr node) {
int opc;
ExecutableDescriptor method = node.getMethod();
// = internalName(node.getMethod().classNode);
String ownerClass;
if (node instanceof StaticInvokeExpr) {
opc = INVOKESTATIC;
ownerClass = internalName(((StaticInvokeExpr) node).getInvokeClass().getReferencedClassNode());
} else if (node instanceof ObjectInvokeExpr) {
ObjectInvokeExpr oie = (ObjectInvokeExpr) node;
ObjectType targetType = (ObjectType) oie.getInvokeTarget().getType();
ownerClass = internalName(targetType);
ExprNode target = oie.getInvokeTarget();
visit(target);
if (Modifier.isPrivate(method.getModifier()) || (target instanceof SuperExpr) || method.getName().equals("<init>")) {
opc = INVOKESPECIAL;
} else {
opc = ModifierUtil.isInterface(targetType.getClassNode().modifier) ? INVOKEINTERFACE : INVOKEVIRTUAL;
}
} else {
throw Exceptions.unsupportedTypeException(node);
}
visitAll(node.getArguments());
md.visitMethodInsn(opc, ownerClass, method.getName(), getMethodDescriptor(method.getMethodNode()));
return null;
}
use of kalang.ast.StaticInvokeExpr in project kalang by kasonyang.
the class AstBuilder method getImplicitInvokeExpr.
@Nullable
private ExprNode getImplicitInvokeExpr(String methodName, ExprNode[] args, ParserRuleContext ctx) {
ExprNode expr = null;
try {
ObjectType clazzType = getThisType();
InvocationExpr.MethodSelection ms = InvocationExpr.applyMethod(clazzType, methodName, args, clazzType.getMethodDescriptors(thisClazz, true, true));
if (Modifier.isStatic(ms.selectedMethod.getModifier())) {
expr = new StaticInvokeExpr(new ClassReference(thisClazz), ms.selectedMethod, ms.appliedArguments);
} else {
expr = new ObjectInvokeExpr(new ThisExpr(getThisType()), ms.selectedMethod, ms.appliedArguments);
}
} catch (MethodNotFoundException ex) {
if (args.length == 1 && (methodName.equals("print") || methodName.equals("println"))) {
try {
StaticFieldExpr fieldExpr = StaticFieldExpr.create(new ClassReference(Types.requireClassType("java.lang.System").getClassNode()), "out", null);
expr = getObjectInvokeExpr(fieldExpr, methodName, args, ctx);
} catch (FieldNotFoundException fnfEx) {
throw Exceptions.unexceptedException(fnfEx);
}
}
if (expr == null) {
this.methodNotFound(ctx.getStart(), className, methodName, args);
expr = new UnknownInvocationExpr(null, methodName, args);
}
} catch (AmbiguousMethodException ex) {
methodIsAmbiguous(ctx.start, ex);
return null;
}
mapAst(expr, ctx);
return expr;
}
Aggregations