private void processThisCallLocalArgs(ReferenceBinding binding, JMethodCall call) { if (binding.syntheticOuterLocalVariables() != null) { for (SyntheticArgumentBinding arg : binding.syntheticOuterLocalVariables()) { JParameter param = (JParameter) curMethod.locals.get(arg); assert param != null; call.addArg(new JParameterRef(call.getSourceInfo(), param)); } } }
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; }
call.addArg(new JFieldRef(info, null, valuesField, mapClass)); JFieldRef mapRef = new JFieldRef(info, null, mapField, mapClass); JDeclarationStatement declStmt = new JDeclarationStatement(info, mapRef, call);
private void processThisCallThisArgs(ReferenceBinding binding, JMethodCall call) { if (binding.syntheticEnclosingInstanceTypes() != null) { Iterator<JParameter> paramIt = curMethod.method.getParams().iterator(); if (curClass.classType.isEnumOrSubclass() != null) { // Skip past the enum args. paramIt.next(); paramIt.next(); } for (@SuppressWarnings("unused") ReferenceBinding argType : binding.syntheticEnclosingInstanceTypes()) { JParameter param = paramIt.next(); call.addArg(new JParameterRef(call.getSourceInfo(), param)); } } }
private void processSuperCallThisArgs(ReferenceBinding superClass, JMethodCall call, JExpression qualifier, Expression qualification) { // Explicit super calls can only happend inside constructors assert curMethod.scope.isInsideConstructor(); if (superClass.syntheticEnclosingInstanceTypes() != null) { // there can only be ONE immediate enclosing instance. assert superClass.syntheticEnclosingInstanceTypes().length == 1; ReferenceBinding targetType = superClass.syntheticEnclosingInstanceTypes()[0]; if (qualification != null) { // Outer object is the qualifier. call.addArg(qualifier); } else { // Get implicit outer object. call.addArg(makeThisReference(call.getSourceInfo(), targetType, false, curMethod.scope)); } } }
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; }
@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(); }
@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 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(); }
private void processSuperCallLocalArgs(ReferenceBinding superClass, JMethodCall call) { if (superClass.syntheticOuterLocalVariables() != null) { for (SyntheticArgumentBinding arg : superClass.syntheticOuterLocalVariables()) { // TODO: use emulation path here. // Got to be one of my params JType varType = typeMap.get(arg.type); String varName = intern(arg.name); JParameter param = null; for (JParameter paramIt : curMethod.method.getParams()) { if (varType == paramIt.getType() && varName.equals(paramIt.getName())) { param = paramIt; } } if (param == null) { throw new InternalCompilerException( "Could not find matching local arg for explicit super ctor call."); } call.addArg(new JParameterRef(call.getSourceInfo(), param)); } } }
if (result.isPresent()) { final JMethodCall call = new JMethodCall(info, result.get(), method); call.addArg(receiverParam); if (logger.isLoggable(logLevel())) { final TreeLogger branch = logger.branch(logLevel(), "Generated asynchronous magic singleton: ");
/** * 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(); }
private JExpression box(JExpression original, int implicitConversion) { int typeId = (implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4; ClassScope scope = curClass.scope; BaseTypeBinding primitiveType = (BaseTypeBinding) TypeBinding.wellKnownType(scope, typeId); ReferenceBinding boxType = (ReferenceBinding) scope.boxing(primitiveType); MethodBinding valueOfMethod = boxType.getExactMethod(VALUE_OF, new TypeBinding[]{primitiveType}, scope .compilationUnitScope()); assert valueOfMethod != null; // Add a cast to the correct primitive type if needed. JType targetPrimitiveType = typeMap.get(primitiveType); if (original.getType() != targetPrimitiveType) { original = new JCastOperation(original.getSourceInfo(), targetPrimitiveType, original); } JMethod boxMethod = typeMap.get(valueOfMethod); JMethodCall call = new JMethodCall(original.getSourceInfo(), null, boxMethod); call.addArg(original); return call; }
JParameter param = bridgeMethod.getParams().get(i); JParameterRef paramRef = new JParameterRef(info, param); call.addArg(maybeCast(implParams.get(i).getType(), paramRef));
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());