@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(); }
return constructorFactory.makeStatement().getExpr();
return constructorFactory.makeStatement().getExpr();
return methodFactory.makeStatement().getExpr();
return methodFactory.makeStatement().getExpr();
return call.makeStatement().getExpr();
return call.makeStatement().getExpr();
List<JExpression> dims = Lists.create(size.makeStatement().getExpr()); while (cur instanceof JArrayType) { dims = Lists.add(dims, JAbsentArrayDimension.INSTANCE);
public JExpression doRebind(String clsName, ReflectionGeneratorContext params) throws UnableToCompleteException { // generate params.getLogger().log(Type.INFO, "Binding magic class for " + clsName); // JType type = params.getClazz().getRefType(); JDeclaredType type = params.getAst().searchForTypeBySource(params.getClazz().getRefType().getName()); StandardGeneratorContext ctx = params.getGeneratorContext(); Class<? extends Generator> generator = MagicClassGenerator.class; String result = ctx.runGenerator(params.getLogger(), generator, SourceUtil.toSourceName(type.getName())); ctx.finish(params.getLogger()); params.getLogger().log(Type.INFO, "Generated Class Enhancer: " + result); JDeclaredType success = params.getAst().searchForTypeBySource(result); //Okay, we've generated the correct magic class subtype; //Now pull off its static accessor method to grab our generated class. for (JMethod method : success.getMethods()) { if (method.isStatic() && method.getName().equals("enhanceClass")) { JMethodCall call = new JMethodCall(method.getSourceInfo(), null, method); call.addArg(params.getClazz().makeStatement().getExpr()); return call; } } params.getLogger().log(Type.ERROR, "Unable to load "+result+".enhanceClass()"); throw new UnableToCompleteException(); }
if (method.isStatic() && method.getName().equals("enhanceClass")) { JMethodCall call = new JMethodCall(method.getSourceInfo().makeChild(SourceOrigin.UNKNOWN), null, method); call.addArg(params.getClazz().makeStatement().getExpr()); return call;
if (method.isStatic() && method.getName().equals("enhanceClass")) { final JMethodCall call = new JMethodCall(method.getSourceInfo().makeChild(SourceOrigin.UNKNOWN), null, ast.translate(method)); call.addArg(params.getClazz().makeStatement().getExpr());