List of usage examples for com.google.gwt.dev.jjs.ast JMethodCall addArg
public void addArg(JExpression toAdd)
From source file:xapi.dev.inject.MagicMethods.java
License:Open Source License
/** * Replaces a call from {@link X_Inject#singletonAsync(Class, xapi.util.api.ReceivesValue)} by first a) * generating an async provider, and then b) sending the value receiver into the async provider as a * callback. See the {@link AsyncProxy} class and {@link AsyncInjectionGenerator} for implementation. * * @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/*from www.j a v a2s. com*/ */ public static JExpression rebindSingletonAsync(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { assert (methodCall.getArgs().size() == 2); JExpression classParam = methodCall.getArgs().get(0); JExpression receiverParam = methodCall.getArgs().get(1); if (!(classParam instanceof JClassLiteral)) { ast.error(methodCall, "Only class literals may be used as arguments to X_Inject.singletonAsync; you sent " + classParam.getClass() + " - " + classParam); return null; } logger.log(logLevel(), receiverParam.toString() + " : " + receiverParam.getClass() + " : " + receiverParam.toSource()); JClassLiteral classLiteral = (JClassLiteral) classParam; JDeclaredType answerType = injectSingletonAsync(logger, classLiteral, methodCall, ast); JDeclaredType receiverType = ast.searchForTypeBySource("xapi.util.api.ReceivesValue"); for (JMethod method : receiverType.getMethods()) { if (method.getName().equals("set")) { SourceInfo info = methodCall.getSourceInfo().makeChild(SourceOrigin.UNKNOWN); JExpression result; result = JGwtCreate.createInstantiationExpression(methodCall.getSourceInfo(), (JClassType) answerType); if (result == null) { ast.error(methodCall, "Rebind result '" + answerType + "' has no default (zero argument) constructors"); return null; } JMethodCall call = new JMethodCall(info, result, method); call.addArg(receiverParam); if (logger.isLoggable(logLevel())) { TreeLogger branch = logger.branch(logLevel(), "Generated asynchronous magic singleton: "); for (String str : call.toSource().split("\n")) { branch.log(logLevel(), str); } } return call; } } throw new InternalCompilerException("Unable to generate asynchronous class injector"); }