List of usage examples for com.google.gwt.dev.jjs.ast JMethodCall getType
public JType getType()
From source file:xapi.dev.inject.MagicMethods.java
License:Open Source License
/** * 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// w ww.j ava 2s. co m */ public static JExpression rebindInstance(TreeLogger logger, JMethodCall x, JMethod currentMethod, Context context, final UnifyAstView ast) throws UnableToCompleteException { assert (x.getArgs().size() == 1); JExpression arg = x.getArgs().get(0); if (!(arg instanceof JClassLiteral)) { //uh-oh; our class argument isn't actually a literal. //it may be a reference to a magic class, //in which case it will have java.lang.Class as a supertype. //our search semantics (for methods) are as follows: //first check the first arguments of methods for magic class or class lit. //if one is found, emit log and use it //if not, throw UnableToComplete (TODO a xinject.strict flag to disallow type search) if (arg instanceof JVariableRef) { JVariableRef local = (JVariableRef) arg; JExpression init = local.getTarget().getDeclarationStatement().initializer; if (init instanceof JVariableRef) { JVariableRef ref = (JVariableRef) init; String fromSourceInfo = ref.getSourceInfo().getFileName().replace("gen/", "") .replace("_MC.java", "").replaceAll("/", "."); JDeclaredType type; //TODO error handling type = ast.searchForTypeBySource(fromSourceInfo); arg = new JClassLiteral(type.getSourceInfo(), type); } } else if (arg instanceof JMethodCall) { JMethodCall call = (JMethodCall) arg; System.out.println(call.getType()); arg = call.getArgs().get(0); } if (!(arg instanceof JClassLiteral)) { logger.log(Type.ERROR, "Could not generate X_Inject.instance for " + arg.getType().getName()); } } JClassLiteral classLiteral = (JClassLiteral) arg; return injectInstance(logger, classLiteral, x, currentMethod, ast); }