@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall callSite, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final boolean isFromGwtReflect = callSite.getArgs().size() == 2; final JExpression inst = isFromGwtReflect ? callSite.getArgs().get(0) : callSite.getInstance(); final JClassLiteral classLit = ReflectionUtilAst.extractClassLiteral(logger, inst, ast, false); final List<JExpression> args = callSite.getArgs(); final JExpression arg0 = args.get(isFromGwtReflect?1:0); // and return a call to the generated Method provider return getFactoryMethod(logger, callSite, enclosingMethod, context, classLit, inst, arg0, ast) .makeStatement().getExpr(); }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall callSite, JMethod enclosingMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { boolean isFromGwtReflect = callSite.getArgs().size() == 2; JExpression inst = isFromGwtReflect ? callSite.getArgs().get(0) : callSite.getInstance(); JClassLiteral classLit = ReflectionUtilAst.extractClassLiteral(logger, inst, ast, false); List<JExpression> args = callSite.getArgs(); JExpression arg0 = args.get(isFromGwtReflect?1:0); // and return a call to the generated Method provider return getFactoryMethod(logger, callSite, enclosingMethod, context, classLit, inst, arg0, ast) .makeStatement().getExpr(); }
/** * Replaces a call from {@link X_Inject#singleton(Class)} by first a-0) generating a provider which will be * synchronous if an async call hasn't already been made, or a-1) generating a provider which will route * through the async provider, and return null before inited. then b) creates a lazy provider to call into * the synchronous provider finally c) calls .get() on the provider and return the value. If you use the * {@link X_Inject#singletonAsync(Class, xapi.util.api.ReceivesValue)} once, you should not use the * other two synchronous provider methods, as they may return null if you happen to request them before the * code split containing the service is downloaded. * * @param logger - The logger to log to. * @param methodCall - The method call we are overwriting * @param currentMethod - The encapsulated method itself * @param context - The method call context, so you can insert clinits / whatnot * @param ast - A view over UnifyAst, exposing our basic needs * @return - A JExpression to replace this method call with * @throws UnableToCompleteException */ public static JExpression rebindSingleton(final TreeLogger logger, final JMethodCall x, final JMethod currentMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { assert (x.getArgs().size() == 1); final JExpression arg = x.getArgs().get(0); if (!(arg instanceof JClassLiteral)) { ast.error(x, "Only class literals may be used as arguments to X_Inject.lazySingleton; you sent " + arg.getClass() + " - " + arg); return null; } final JClassLiteral classLiteral = (JClassLiteral)arg; return injectSingleton(logger, classLiteral, x, ast); }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { if (methodCall.getArgs().size() != 1) { logger.log(Type.ERROR, "X_Reflect.magicClass accepts one and only one argument: a class literal."); throw new UnableToCompleteException(); } if (!(methodCall.getArgs().get(0) instanceof JClassLiteral)) { logger.log(Type.ERROR, "X_Reflect.magicClass accepts one and only one argument: a class literal." + " You sent a " + methodCall.getArgs().get(0).getClass() + " : " + methodCall.getArgs().get(0).toSource()); throw new UnableToCompleteException(); } JClassLiteral clazz = (JClassLiteral)methodCall.getArgs().get(0); return mappedClasses.get(clazz.getRefType().getName(), new ReflectionGeneratorContext(logger, clazz, methodCall, currentMethod, context, ast)); }
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 JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod enclosingMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { JExpression methodProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); if (methodCall.getArgs().size() != 5) { logger.log(Type.ERROR, "Method call provided to replace GwtReflect.invoke(" + "Class<?> cls, String name, Class<?>[] paramTypes, Object inst, Object ... params" + ") supplied incorrect number of arguments; you supplied "+methodCall.getArgs().size() +" arguments: "+methodCall.getArgs()); throw new UnableToCompleteException(); } // call the invoke method on the result of our methodProvider JDeclaredType ctor = ast.searchForTypeBySource(Method.class.getName()); for (JMethod method : ctor.getMethods()) { if (method.getName().equals("invoke")) { JMethodCall call = new JMethodCall(method.getSourceInfo(), methodProvider, method); call.addArg(methodCall.getArgs().get(3)); call.addArg(methodCall.getArgs().get(4)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.invoke from "+methodCall.toSource()); throw new UnableToCompleteException(); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JExpression methodProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); if (isThrowStatement(methodProvider)) { return methodProvider; } if (methodCall.getArgs().size() != 5) { logger.log(Type.ERROR, "Method call provided to replace GwtReflect.invoke(" + "Class<?> cls, String name, Class<?>[] paramTypes, Object inst, Object ... params" + ") supplied incorrect number of arguments; you supplied "+methodCall.getArgs().size() +" arguments: "+methodCall.getArgs()); throw new UnableToCompleteException(); } // call the invoke method on the result of our methodProvider final JDeclaredType ctor = ast.searchForTypeBySource(Method.class.getName()); for (final JMethod method : ctor.getMethods()) { if (method.getName().equals("invoke")) { final JMethodCall call = new JMethodCall(method.getSourceInfo(), methodProvider, method); call.addArg(methodCall.getArgs().get(3)); call.addArg(methodCall.getArgs().get(4)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.invoke from "+methodCall.toSource()); throw new UnableToCompleteException(); }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod enclosingMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { JExpression ctorProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); // call the newInstance method on the result of our ctorProvider JDeclaredType ctor = ast.searchForTypeBySource(Constructor.class.getName()); for (JMethod method : ctor.getMethods()) { if (method.getName().equals("newInstance")) { JMethodCall call = new JMethodCall(method.getSourceInfo(), ctorProvider, method); call.addArg(methodCall.getArgs().get(2)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.construct from "+methodCall.toSource()); throw new UnableToCompleteException(); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JExpression ctorProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); // Find the invoker method // call the newInstance method on the result of our ctorProvider final JDeclaredType ctor = ast.searchForTypeBySource(Constructor.class.getName()); for (final JMethod method : ctor.getMethods()) { if (method.getName().equals("newInstance")) { final JMethodCall call = new JMethodCall(methodCall.getSourceInfo().makeChild(), ctorProvider, method); call.addArg(methodCall.getArgs().get(2)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.construct from "+methodCall.toSource()); throw new UnableToCompleteException(); }
JClassLiteral clazz = ReflectionUtilAst.extractClassLiteral(logger, methodCall, 0, ast); JProgram prog = ast.getProgram(); List<JExpression> args = methodCall.getArgs(); List<JExpression> emptyDims = Lists.create(), sizedDims; JType type = clazz.getRefType();
final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final List<JExpression> args = methodCall.getArgs(); final JClassLiteral uiOptionsLiteral = ReflectionUtilAst.extractClassLiteral(logger, args.get(1), ast, true); final JClassLiteral uiTypeLiteral = ReflectionUtilAst.extractClassLiteral(logger, args.get(2), ast, true);
final JExpression[] args = methodCall.getArgs() .toArray(new JExpression[2]); return new JMethodCall(info, null, newArrayMethod, args); final JType type = cur = ast.translate(clazz.getRefType()); final JIntLiteral size = ReflectionUtilAst.extractImmutableNode(logger, JIntLiteral.class, methodCall.getArgs().get(1), ast, false);
final JExpression classArg = methodCall.getArgs().get(0); final JClassLiteral classLit = ReflectionUtilAst.extractClassLiteral( logger, classArg, ast, false);
JType cur, type = cur =clazz.getRefType(); JIntLiteral size = ReflectionUtilAst.extractImmutableNode(logger, JIntLiteral.class, methodCall.getArgs().get(1), ast, false);