@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(); }
/** * Implements a caching layer guarding the {@link #initialize(String, ReflectionGeneratorContext)} method * * @param key * @param params * @return */ protected JExpression get(String key, ReflectionGeneratorContext params) { //because we cache results, super dev mode recompiles need to skip the //cache if the magic class does not exist, thus we test type presence on every get(). JDeclaredType type = params.getAst().searchForTypeByBinary(params.getClazz().getRefType().getName()); String typeName = JGwtCreate.nameOf(type); String generatedName = ReflectionUtilJava.generatedMagicClassName(typeName); try { params.getAst().searchForTypeBySource(generatedName); }catch(NoClassDefFoundError e) { classEnhancers.remove(key); } if (classEnhancers.containsKey(key)) { JMethodCall previous = classEnhancers.get(key); previous = new JMethodCall(previous, previous.getInstance()); previous.addArg(params.getClazz().makeStatement().getExpr()); return previous.makeStatement().getExpr(); } JMethodCall expr = initialize(key, params); classEnhancers.put(key, expr); expr.setArg(0, params.getClazz().makeStatement().getExpr()); return expr.makeStatement().getExpr(); }
/** * Implements a caching layer guarding the {@link #initialize(String, ReflectionGeneratorContext)} method * * @param key * @param params * @return * @throws UnableToCompleteException */ protected JExpression get(final String key, final ReflectionGeneratorContext params) throws UnableToCompleteException { //because we cache results, super dev mode recompiles need to skip the //cache if the magic class does not exist, thus we test type presence on every get(). final JDeclaredType type = params.getAst().searchForTypeByBinary(params.getClazz().getRefType().getName()); final String typeName = BinaryName.toSourceName(type.getName()); final String generatedName = ReflectionUtilJava.generatedMagicClassName(typeName); if (null == params.getAst().searchForTypeBySource(generatedName)) { classEnhancers.remove(key); } if (classEnhancers.containsKey(key)) { JMethodCall previous = classEnhancers.get(key); previous = new JMethodCall(previous, previous.getInstance()); previous.addArg(params.getClazz().makeStatement().getExpr()); return previous.makeStatement().getExpr(); } final JMethodCall expr = initialize(key, params); classEnhancers.put(key, expr); expr.setArg(0, params.getClazz().makeStatement().getExpr()); return expr.makeStatement().getExpr(); }
assert (JProgram.isClinit(clinitMethod)); final JMethodCall doClinit = new JMethodCall(clinit.getSourceInfo(), null, clinitMethod); body.getBlock().addStmt(doClinit.makeStatement());
return constructorFactory.makeStatement().getExpr();
return constructorFactory.makeStatement().getExpr();
return methodFactory.makeStatement().getExpr();
return methodFactory.makeStatement().getExpr();
return call.makeStatement().getExpr();
JMethodCall superClinitCall = new JMethodCall(myClinit.getSourceInfo(), null, superClinit); JMethodBody body = (JMethodBody) myClinit.getBody(); body.getBlock().addStmt(0, superClinitCall.makeStatement());
return call.makeStatement().getExpr();
body.getBlock().addStmt(call.makeStatement()); } else { body.getBlock().addStmt(new JReturnStatement(info, call));
push(call.makeStatement()); } catch (Throwable e) { throw translateException(x, e);
JMethod initMethod = curClass.type.getInitMethod(); JMethodCall initCall = new JMethodCall(info, makeThisRef(info), initMethod); block.addStmt(initCall.makeStatement());