private static boolean isGetMagicClass(JMethod target) { return (target.getName().equals("magicClass") && target.getEnclosingType().getName().equals(GwtReflect.class.getName())) || (target.getName().equals("enhanceClass") && target.getEnclosingType().getName().endsWith(ReflectionUtilJava.MAGIC_CLASS_SUFFIX)) ; }
public JMethod getThrowMethod(final TreeLogger logger, final UnifyAstView ast) { if (doThrow == null) { final JDeclaredType gwtReflect = ast.searchForTypeBySource(GwtReflect.class.getName()); for (final JMethod method : gwtReflect.getMethods()) { if (method.getName().equals("doThrow")) { doThrow = method; break; } } } return doThrow; } }
public com.google.gwt.dev.jjs.ast.JMethod initMethod(UnifyAstView ast) { if (initMethod == null) { JDeclaredType type = ast.searchForTypeBySource("com.google.gwt.reflect.shared.JsMemberPool"); for (com.google.gwt.dev.jjs.ast.JMethod method : type.getMethods()) { if (method.getName().equals("getMembers")) { initMethod = method; break; } } } return initMethod; } }
/** * @param methodProvider * @return */ public boolean isThrowStatement(final JExpression methodProvider) { if (methodProvider instanceof JMethodCall) { final JMethod method = ((JMethodCall)methodProvider).getTarget(); return method.getType().getName().equals(GwtReflect.class.getName()) && method.getName().equals("doThrow"); } return false; }
private void findMethods(final UnifyAstView ast) { final JDeclaredType arrayType = ast.searchForTypeBySource(Array.class.getName()); for (final JMethod method : arrayType.getMethods()) { if ("register".equals(method.getName())) { registerArray = ast.translate(method); if (newArrayMethod != null) { return; } } else if ("newMultiDimArray".equals(method.getName())) { newArrayMethod = ast.translate(method); if (registerArray != null) { return; } } } }
private void processEnumType(JEnumType type) { JField valuesField = createEnumValuesField(type); // $clinit, $init, getClass, valueOf, values { JMethod valueOfMethod = type.getMethods().get(3); assert "valueOf".equals(valueOfMethod.getName()); writeEnumValueOfMethod(type, valueOfMethod, valuesField); } { JMethod valuesMethod = type.getMethods().get(4); assert "values".equals(valuesMethod.getName()); writeEnumValuesMethod(type, valuesMethod, valuesField); } }
private void findMethods(final UnifyAstView ast) { if (newArrayMethod == null) { JDeclaredType arrayType = ast .searchForTypeByBinary(Array.class.getName()); arrayType = ast.translate(arrayType); for (final JMethod method : arrayType.getMethods()) { if ("register".equals(method.getName())) { registerArray = ast.translate(method); if (newArrayMethod != null) { return; } } else if ("newSingleDimArray".equals(method.getName())) { newArrayMethod = ast.translate(method); if (registerArray != null) { return; } } } } }
/** * Search for the method {@link JsMemberPool#getMembers(Class)}. This method is used to load * the {@link JsMemberPool} for a given class, to perform runtime reflection lookups. * * @param ast -> The {@link UnifyAstView} used to find the {@link JMethod} we want. * @return -> The JMethod used to invoke {@link JsMemberPool#getMembers(Class)} */ public JMethod findGetMembersMethod(final UnifyAstView ast) { if (getMembers == null) { // First, get the type final JDeclaredType type = ast.searchForTypeBySource(JsMemberPool.class.getCanonicalName()); // Then, iterate through the methers to find .getMembers(). We do not overload this method, // so we don't bother checking the signature. for (final JMethod method : type.getMethods()) { if (method.getName().equals("getMembers")) { getMembers = ast.translate(method); break; } } } return getMembers; }
private JDeclaredType index(final UnifyAstView ast) { if (intToListType != null) { return intToListType; } ast.getProgram().addIndexedTypeName(IntToListGwt.class.getName()); intToListType = ast.searchForTypeBySource(IntToListGwt.class.getName()); for (final JMethod method : intToListType.getMethods()) { if (method.getName().equals("create")) { createMethod = ast.translate(method); if (createForClassMethod != null) { break; } } else if (method.getName().equals("createForClass")) { createForClassMethod = ast.translate(method); if (createMethod != null) { break; } } } return intToListType; }
/** * TODO(scottb): move to UnifyAst and only for non-abstract classes. */ private void implementGetClass(JDeclaredType type) { JMethod method = type.getMethods().get(2); assert ("getClass".equals(method.getName())); SourceInfo info = method.getSourceInfo(); if ("com.google.gwt.lang.Array".equals(type.getName())) { /* * Don't implement, fall through to Object.getClass(). Array emulation code * in com.google.gwt.lang.Array invokes Array.getClass() and expects to get the * class literal for the actual runtime type of the array (e.g. Foo[].class) and * not Array.class. */ type.getMethods().remove(2); } else { implementMethod(method, new JClassLiteral(info, type)); } }
public com.google.gwt.dev.jjs.ast.JMethod findGetterFor(UnifyAstView ast, String memberGetter) throws UnableToCompleteException { com.google.gwt.dev.jjs.ast.JMethod getter = getters.get(memberGetter); if (getter == null) { initMethod(ast); JDeclaredType type = ast.translate((JDeclaredType) initMethod.getOriginalReturnType()); for (com.google.gwt.dev.jjs.ast.JMethod method : type.getMethods()) { if (method.getName().endsWith(memberGetter)) { getters.put(memberGetter, method); return method; } } ast.error(type, "Type "+type.getName()+" does not have member getter method "+memberGetter); throw new UnableToCompleteException(); } return getter; }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod enclosingMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { JExpression ctorProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); // call the newInstance method on the result of our ctorProvider JDeclaredType ctor = ast.searchForTypeBySource(Constructor.class.getName()); for (JMethod method : ctor.getMethods()) { if (method.getName().equals("newInstance")) { JMethodCall call = new JMethodCall(method.getSourceInfo(), ctorProvider, method); call.addArg(methodCall.getArgs().get(2)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.construct from "+methodCall.toSource()); throw new UnableToCompleteException(); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JExpression ctorProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); // Find the invoker method // call the newInstance method on the result of our ctorProvider final JDeclaredType ctor = ast.searchForTypeBySource(Constructor.class.getName()); for (final JMethod method : ctor.getMethods()) { if (method.getName().equals("newInstance")) { final JMethodCall call = new JMethodCall(methodCall.getSourceInfo().makeChild(), ctorProvider, method); call.addArg(methodCall.getArgs().get(2)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.construct from "+methodCall.toSource()); throw new UnableToCompleteException(); }
@Override public boolean visit(JConstructor x, Context ctx) { if (pastRebound) { for (JMethod m : x.getEnclosingType().getMethods()) { if (m.getName().equals("createNewTestCase")) { for (JStatement statement : ((JMethodBody)m.getBody()).getBlock().getStatements()) { if (statement instanceof JIfStatement) { pastConstructor = true; ((JIfStatement)statement).getThenStmt().traverse(this, ctx); return false; } } } } } return super.visit(x, ctx); }
@Override public boolean visit(JConstructor x, Context ctx) { if (pastRebound) { for (JMethod m : x.getEnclosingType().getMethods()) { if (m.getName().equals("createNewTestCase")) { for (JStatement statement : ((JMethodBody)m.getBody()).getBlock().getStatements()) { if (statement instanceof JIfStatement) { pastConstructor = true; ((JIfStatement)statement).getThenStmt().traverse(this, ctx); return false; } } } } } return super.visit(x, ctx); }
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(); }
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(); }