@Override public boolean visit(JClassLiteral x, Context ctx) { result = (JClassType)x.getRefType(); return false; }
@Override public boolean visit(JClassLiteral x, Context ctx) { result = (JClassType)x.getRefType(); return false; }
public static IsQualified generatedAnnotationProviderName( final JClassLiteral classLit, final JClassLiteral annoLit) { final JType refType = classLit.getRefType(); return new IsQualified(refType.getPackageName(), toFlatSimpleName(refType)+"__"+toFlatName(annoLit.getRefType().getName())); }
@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)); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod currentMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JClassLiteral clazz = ReflectionUtilAst.extractClassLiteral(logger, methodCall, 0, ast); final JType type = clazz.getRefType(); if (type == null) { logger.log(Type.WARN, "ClassLiteral with null reftype: "+clazz.toSource()); return null; } return get(type.getName(), new ReflectionGeneratorContext( logger, clazz, methodCall, currentMethod, context, ast)); }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { JClassLiteral clazz = ReflectionUtilAst.extractClassLiteral(logger, methodCall, 0, ast); JType type = clazz.getRefType(); if (type == null) { logger.log(Type.WARN, "ClassLiteral with null reftype: "+clazz.toSource()); return null; } return get(type.getName(), new ReflectionGeneratorContext( logger, clazz, methodCall, currentMethod, context, ast)); }
@Override public void endVisit(JClassLiteral x, Context ctx) { JType refType = translate(x.getRefType()); x.resolve(refType); // ImplementClassLiteralsAsFields: rescue enumType.values()/valueOf(). if (refType instanceof JArrayType) { JType leafType = ((JArrayType) refType).getLeafType(); if (leafType instanceof JReferenceType) { refType = leafType; } } if (refType instanceof JClassType) { JClassType classType = (JClassType) refType; JEnumType enumType = classType.isEnumOrSubclass(); if (enumType != null) { for (JMethod method : enumType.getMethods()) { if (method.isStatic()) { if (method.getSignature().startsWith("values()")) { flowInto(method); } else if (method.getSignature().startsWith("valueOf(Ljava/lang/String;)")) { flowInto(method); } } } } } }
public synchronized int[] getSeedArray(final TreeLogger logger, final JClassLiteral classLit) { int[] result = arraySeeds.get(classLit); if (result == null) { final int constId = initBuffer(); result = new int[] {constId, arraySeeds.size()}; final ClassBuffer into = out.getClassBuffer(); final String typeName = classLit.getRefType().getName(); if (classLit.getRefType().getDefaultValue() != JNullLiteral.INSTANCE) { // primitive fields have defaults, and require special handling into.print(typeName+"[] array"+result[1]+" = "); into.print("("+typeName+"[])setPrimitiveArray("); into.println(typeName+".class, new "+typeName+"[0]);"); } else { into.print(typeName+"[] array"+result[1]+" = setArray("); into.println(typeName+".class, new "+typeName+"[0]);"); } arraySeeds.put(classLit, result); } return result; }
public synchronized int[] getSeedArray(TreeLogger logger, JClassLiteral classLit) { int[] result = arraySeeds.get(classLit); if (result == null) { int constId = initBuffer(); result = new int[] {constId, arraySeeds.size()}; ClassBuffer into = out.getClassBuffer(); String typeName = classLit.getRefType().getName(); if (classLit.getRefType().getDefaultValue() != JNullLiteral.INSTANCE) { // primitive fields have defaults, and require special handling into.print(typeName+"[] array"+result[1]+" = "); into.print("("+typeName+"[])setPrimitiveArray("); into.println(typeName+".class, new "+typeName+"[0]);"); } else { into.print(typeName+"[] array"+result[1]+" = setArray("); into.println(typeName+".class, new "+typeName+"[0]);"); } arraySeeds.put(classLit, result); } return result; }
@Override public 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, so we test for that state on every get(). JDeclaredType type = params.getAst().searchForTypeBySource(params.getClazz().getRefType().getName()); String typeName = JGwtCreate.nameOf(type); String generatedName = ReflectionUtilJava.generatedMagicClassName(typeName); try { params.getAst().searchForTypeBySource(generatedName); }catch(NoClassDefFoundError e) { removeValue(key); } return super.get(key, params); }
/** * 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(); }
public JMethodCall getFieldProvider(final TreeLogger logger, final ReflectionGeneratorContext ctx, final com.google.gwt.core.ext.typeinfo.JField field, final JClassLiteral classLit, final boolean declaredOnly) throws UnableToCompleteException { final String clsName = classLit.getRefType().getName(); final ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ctx.getGeneratorContext()); final String factoryCls = getOrMakeFieldFactory(logger, ctx, field, field.getEnclosingType(), manifest, declaredOnly); ctx.finish(logger); final UnifyAstView ast = ctx.getAst(); final JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (final JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Field subclass "+factoryCls); throw new UnableToCompleteException(); }
/** * 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(); }
public JMethodCall getConstructorProvider(final TreeLogger logger, final ReflectionGeneratorContext ctx, final JConstructor ctor, final boolean declared) throws UnableToCompleteException { final JClassLiteral classLit = ctx.getClazz(); final UnifyAstView ast = ctx.getAst(); final String clsName = classLit.getRefType().getName(); final ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); final String factoryCls = getOrMakeConstructorFactory(logger, ctx, ctor, ctor.getEnclosingType(), manifest, declared); ctx.finish(logger); final JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (final JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Constructor subclass "+factoryCls); throw new UnableToCompleteException(); }
public JMethodCall getFieldProvider(TreeLogger logger, UnifyAstView ast, com.google.gwt.core.ext.typeinfo.JField field, JClassLiteral classLit, boolean declaredOnly) throws UnableToCompleteException { String clsName = classLit.getRefType().getName(); ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); String factoryCls = getOrMakeFieldFactory(logger, ast.getRebindPermutationOracle().getGeneratorContext(), field, field.getEnclosingType(), manifest, declaredOnly); ast.getGeneratorContext().finish(logger); JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Field subclass "+factoryCls); throw new UnableToCompleteException(); }
public JMethodCall getMethodProvider(final TreeLogger logger, final ReflectionGeneratorContext ctx, final com.google.gwt.core.ext.typeinfo.JMethod method, final JClassLiteral classLit, final boolean declaredOnly) throws UnableToCompleteException { final String clsName = classLit.getRefType().getName(); final ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ctx.getGeneratorContext()); final String factoryCls = getOrMakeMethodFactory(logger, ctx, method, method.getEnclosingType(), manifest, declaredOnly); ctx.finish(logger); JDeclaredType factory = ctx.getAst().searchForTypeBySource(factoryCls); factory = ctx.getAst().translate(factory); // pull out the static accessor method for (final JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Method subclass "+factoryCls); throw new UnableToCompleteException(); }
public JMethodCall getMethodProvider(TreeLogger logger, UnifyAstView ast, com.google.gwt.core.ext.typeinfo.JMethod method, JClassLiteral classLit, boolean declaredOnly) throws UnableToCompleteException { String clsName = classLit.getRefType().getName(); ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); String factoryCls = getOrMakeMethodFactory(logger, ast.getRebindPermutationOracle().getGeneratorContext(), method, method.getEnclosingType(), manifest, declaredOnly); ast.getRebindPermutationOracle().getGeneratorContext().finish(logger); JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Method subclass "+factoryCls); throw new UnableToCompleteException(); }
public JMethodCall getConstructorProvider(TreeLogger logger, ReflectionGeneratorContext ctx, JConstructor ctor, boolean declared) throws UnableToCompleteException { // // TODO Auto-generated method stub // return null; // } // // public JMethodCall getConstructorProvider(TreeLogger logger, UnifyAstView ast, // JConstructor ctor, // JClassLiteral classLit, boolean declaredOnly) throws UnableToCompleteException { JClassLiteral classLit = ctx.getClazz(); UnifyAstView ast = ctx.getAst(); String clsName = classLit.getRefType().getName(); ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); String factoryCls = getOrMakeConstructorFactory(logger, ctx, ctor, ctor.getEnclosingType(), manifest, declared); ast.getRebindPermutationOracle().getGeneratorContext().finish(logger); JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Constructor subclass "+factoryCls); throw new UnableToCompleteException(); }
Context context, UnifyAstView ast) throws UnableToCompleteException { JClassLiteral clazz = ReflectionUtilAst.extractClassLiteral(logger, methodCall, 0, ast); JType cur, type = cur =clazz.getRefType(); JIntLiteral size = ReflectionUtilAst.extractImmutableNode(logger, JIntLiteral.class, methodCall.getArgs().get(1), ast, false);
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(); }