private void writeEnumValuesMethod(JEnumType type, JMethod method, JField valuesField) { // return $VALUES; JFieldRef valuesRef = new JFieldRef(method.getSourceInfo(), null, valuesField, type); implementMethod(method, valuesRef); } }
protected JMethodCall checkConstPool(UnifyAstView ast, JMethodCall callSite, JExpression classRef, JExpression ... args) throws UnableToCompleteException { com.google.gwt.dev.jjs.ast.JMethod initPool = getMemberPoolInit(ast); JMethodCall getMemberPool = new JMethodCall(initPool.getSourceInfo(), null, initPool); getMemberPool.addArg(classRef); ManifestMap map = manifests.get(); com.google.gwt.dev.jjs.ast.JMethod getter = map.findGetterFor(ast, memberGetter()); JMethodCall checkPool = new JMethodCall(initPool.getSourceInfo(), getMemberPool, getter); for (JExpression arg : args) { checkPool.addArg(arg); } return checkPool; }
/** * 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)); } }
protected JMethodCall checkConstPool(final UnifyAstView ast, final JMethodCall callSite, final JExpression classRef, final JExpression... args) throws UnableToCompleteException { final JMethod initPool = getMemberPoolInit(ast); final JMethodCall getMemberPool = new JMethodCall(initPool.getSourceInfo(), null, initPool); getMemberPool.addArg(classRef); final MemberPoolMethods map = memberPoolMethods.get(); final JMethod getter = map.findGetterFor(ast, memberGetter()); final JMethodCall checkPool = new JMethodCall(initPool.getSourceInfo(), getMemberPool, getter); for (final JExpression arg : args) { checkPool.addArg(arg); } return checkPool; }
private void implementMagicMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
private void implementMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
@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 boolean visit(MethodDeclaration x, ClassScope scope) { try { JMethod method = typeMap.get(x.binding); assert !method.isExternal(); JMethodBody body = null; if (!method.isNative()) { body = new JMethodBody(method.getSourceInfo()); method.setBody(body); } pushMethodInfo(new MethodInfo(method, body, x.scope)); // Map user arguments. Iterator<JParameter> it = method.getParams().iterator(); if (x.arguments != null) { for (Argument argument : x.arguments) { curMethod.locals.put(argument.binding, it.next()); } } x.statements = reduceToReachable(x.statements); return true; } catch (Throwable e) { throw translateException(x, e); } }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod enclosingMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { JExpression methodProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); if (methodCall.getArgs().size() != 5) { logger.log(Type.ERROR, "Method call provided to replace GwtReflect.invoke(" + "Class<?> cls, String name, Class<?>[] paramTypes, Object inst, Object ... params" + ") supplied incorrect number of arguments; you supplied "+methodCall.getArgs().size() +" arguments: "+methodCall.getArgs()); throw new UnableToCompleteException(); } // call the invoke method on the result of our methodProvider JDeclaredType ctor = ast.searchForTypeBySource(Method.class.getName()); for (JMethod method : ctor.getMethods()) { if (method.getName().equals("invoke")) { JMethodCall call = new JMethodCall(method.getSourceInfo(), methodProvider, method); call.addArg(methodCall.getArgs().get(3)); call.addArg(methodCall.getArgs().get(4)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.invoke from "+methodCall.toSource()); throw new UnableToCompleteException(); }
private void processNativeMethod(MethodDeclaration x) { JMethod method = curMethod.method; JsniMethod jsniMethod = jsniMethods.get(x); assert jsniMethod != null; SourceInfo info = method.getSourceInfo(); JsFunction jsFunction = jsniMethod.function(); JsniMethodBody body = new JsniMethodBody(info); method.setBody(body); jsFunction.setFromJava(true); body.setFunc(jsFunction); // Resolve locals, params, and JSNI. JsParameterResolver localResolver = new JsParameterResolver(jsFunction); localResolver.accept(jsFunction); JsniResolver jsniResolver = new JsniResolver(body); jsniResolver.accept(jsFunction); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JExpression methodProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); if (isThrowStatement(methodProvider)) { return methodProvider; } if (methodCall.getArgs().size() != 5) { logger.log(Type.ERROR, "Method call provided to replace GwtReflect.invoke(" + "Class<?> cls, String name, Class<?>[] paramTypes, Object inst, Object ... params" + ") supplied incorrect number of arguments; you supplied "+methodCall.getArgs().size() +" arguments: "+methodCall.getArgs()); throw new UnableToCompleteException(); } // call the invoke method on the result of our methodProvider final JDeclaredType ctor = ast.searchForTypeBySource(Method.class.getName()); for (final JMethod method : ctor.getMethods()) { if (method.getName().equals("invoke")) { final JMethodCall call = new JMethodCall(method.getSourceInfo(), methodProvider, method); call.addArg(methodCall.getArgs().get(3)); call.addArg(methodCall.getArgs().get(4)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.invoke from "+methodCall.toSource()); throw new UnableToCompleteException(); }
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(); }
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(); }
SourceInfo info = implmeth.getSourceInfo(); JMethod bridgeMethod = new JMethod(info, implmeth.getName(), curClass.type, typeMap
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(); }
JMethodCall call = new JMethodCall(method.getSourceInfo().makeChild(SourceOrigin.UNKNOWN), null, method); call.addArg(params.getClazz().makeStatement().getExpr()); return call;