/** * @param methodProvider * @return */ public boolean isThrowStatement(final JExpression methodProvider) { if (methodProvider instanceof JMethodCall) { final JMethod method = ((JMethodCall)methodProvider).getTarget(); return method.getType().getName().equals(GwtReflect.class.getName()) && method.getName().equals("doThrow"); } return false; }
@Override public boolean visit(JMethodCall x, Context ctx) { JMethod target = translate(x.getTarget()); x.resolve(target); // Special handling. return !magicMethodCalls.contains(target); }
private JExpression handleMagicMethodCall(JMethodCall x, Context ctx) { JMethod target = x.getTarget(); String sig = target.getEnclosingType().getName() + '.' + target.getSignature(); if (GWT_CREATE.equals(sig) || OLD_GWT_CREATE.equals(sig)) { return handleGwtCreate(x); } else if (IMPL_GET_NAME_OF.equals(sig)) { return handleImplNameOf(x); } else if (magicMethodMap.containsKey(sig)){ MagicMethodGenerator method = magicMethodMap.get(sig); try { JExpression expr = method.injectMagic(logger, x, currentMethod, ctx, UnifyAst.this); if (logger.isLoggable(Type.DEBUG)){ logger.log(Type.DEBUG, "Magic method "+method +" converted:\n"+x+"\ninto: "+expr); } if (expr instanceof JMethodCall) { flowInto(((JMethodCall)expr).getTarget()); } return expr; } catch (Exception e) { logger.log(Type.ERROR, "Fatal error calling magic method "+method+" on "+x, e); throw new InternalCompilerException("Unable to implement magic method "+method+"()", e); } } throw new InternalCompilerException("Unknown magic method error"); } }
public static JClassLiteral extractClassLiteral(TreeLogger logger, JMethodCall methodCall, int paramPosition, UnifyAstView ast) throws UnableToCompleteException { List<JExpression> args = methodCall.getArgs(); JExpression arg = args.get(paramPosition); JClassLiteral classLit = extractClassLiteral(logger, arg, ast, false); if (classLit == null) { logger.log(Type.ERROR, "The method " + methodCall.getTarget().toSource() + " only accepts class literals." + " You sent a " + arg.getClass() + " : " + arg.toSource()+" from method " + methodCall.toSource()+ " with argumetsn " + methodCall.getArgs()+ ";"); throw new UnableToCompleteException(); } return classLit; }
@Override public void endVisit(JMethodCall x, Context ctx) { // Already resolved during visit(). JMethod target = x.getTarget(); if (target.isExternal()) { assert errorsFound; return; } if (magicMethodCalls.contains(target)) { JExpression result = handleMagicMethodCall(x, ctx); if (result == null) { // Error of some sort. result = JNullLiteral.INSTANCE; } result = this.accept(result); ctx.replaceMe(result); return; } if (!(x instanceof JNewInstance)) { // Should not have an overridden type at this point. assert x.getType() == target.getType(); } flowInto(target); }
JMethod target = (call).getTarget(); if (ReflectionUtilAst.isGetMagicClass(target)) { return extractImmutableNode(logger, type, call.getArgs().get(0), ast, strict);
JMethod newMethod = new JMethod(methodSource, "enhanceAll", methodCall.getTarget().getEnclosingType(), ast.getProgram().getTypeVoid(), false, true, true, AccessModifier.PUBLIC); newMethod.setOriginalTypes(ast.getProgram().getTypeVoid(), methodCall.getTarget().getOriginalParamTypes()); JMethodBody body = new JMethodBody(methodSource); newMethod.setBody(body); block.addStmt(invoke.makeStatement()); block.addStmts(((JMethodBody)methodCall.getTarget().getBody()).getStatements()); methodCall.getTarget().getEnclosingType().addMethod(newMethod); JMethodCall call = new JMethodCall(methodSource, null, newMethod);
methodCall.getTarget().getEnclosingType(), ast.getProgram().getTypeVoid(), false, true, true, AccessModifier.PUBLIC); .getTarget().getOriginalParamTypes()); final JMethodBody body = new JMethodBody(methodSource); newMethod.setBody(body); block.addStmts(((JMethodBody) methodCall.getTarget().getBody()) .getStatements()); methodCall.getTarget().getEnclosingType().addMethod(newMethod); final JMethodCall call = new JMethodCall(methodSource, null, newMethod);