private Statement generateRequest(ClassStructureBuilder<?> classBuilder, MetaMethod method, Statement methodParams, boolean intercepted) { final Statement sendable = Stmt .invokeStatic(MessageBuilder.class, "createCall") .invoke("call", remote.getFullyQualifiedName()) .invoke("endpoint", ProxyUtil.createCallSignature(method), Stmt.loadClassMember("qualifiers"), methodParams) .invoke("respondTo", method.getReturnType().asBoxed(), Stmt.loadVariable("remoteCallback")) .invoke("errorsHandledBy", Stmt.loadVariable("errorCallback")); final BlockStatement requestBlock = new BlockStatement(); requestBlock.addStatement(Stmt.declareVariable("sendable", RemoteCallSendable.class, sendable)); requestBlock.addStatement(Stmt.loadStatic(classBuilder.getClassDefinition(), "this") .invoke("sendRequest", Variable.get("bus"), Variable.get("sendable"))); return requestBlock; } }
private Statement generateInterceptorLogic(ClassStructureBuilder<?> classBuilder, MetaMethod method, Statement requestLogic, List<Statement> parmVars, List<Class<?>> interceptors) { final Statement callContext = ProxyUtil.generateProxyMethodCallContext(context, RemoteCallContext.class, classBuilder.getClassDefinition(), method, requestLogic, interceptors).finish(); return Stmt.try_() .append( Stmt.declareVariable(CallContextStatus.class).asFinal().named("status").initializeWith( Stmt.newObject(CallContextStatus.class).withParameters(interceptors.toArray()))) .append( Stmt.declareVariable(RemoteCallContext.class).asFinal().named("callContext") .initializeWith(callContext)) .append( Stmt.loadVariable("callContext").invoke("setParameters", Stmt.newArray(Object.class).initialize(parmVars.toArray()))) .append( Stmt.loadVariable("callContext").invoke("proceed")) .finish() .catch_(Throwable.class, "throwable") .append( If.cond(Bool.notEquals(Stmt.loadVariable("errorCallback"), Stmt.loadLiteral(null))) .append( If.cond(Stmt.loadVariable("errorCallback").invoke("error", Stmt.load(null), Variable.get("throwable"))) .append(Stmt.loadVariable("this").invoke("invokeDefaultErrorHandlers", Variable.get("throwable"))) .finish() ).finish() .else_() .append(Stmt.loadVariable("this").invoke("invokeDefaultErrorHandlers", Variable.get("throwable"))) .finish()) .finish(); }
@Override public boolean equals(final Object obj) { return obj instanceof Named && CDIAnnotationUtils.equals(this, (Annotation) obj); } };
private static Statement hashArith(final MetaMethod method) { return Arith.expr( Arith.expr(31, ArithmeticOperator.Multiplication, Refs.get("hash")), ArithmeticOperator.Addition, Stmt.invokeStatic(QualifierUtil.class, "hashValueFor", Stmt.loadVariable("a1").invoke(method)) ); } }
.extend() .publicOverridesMethod("getProxy") .append(Stmt.nestedCall(Stmt.newObject(remoteProxy.getClassDefinition())).returnValue()) .finish() .finish(); loadProxies.append(Stmt.invokeStatic(RemoteServiceProxyFactory.class, "addRemoteProxy", remote, proxyProvider));
private void generateMethod(ClassStructureBuilder<?> classBuilder, MetaMethod method) { final List<Class<?>> interceptors = interceptorProvider.getInterceptors(remote, method); final boolean intercepted = !interceptors.isEmpty(); final Parameter[] parms = DefParameters.from(method).getParameters().toArray(new Parameter[0]); final Parameter[] finalParms = new Parameter[parms.length]; final List<Statement> parmVars = new ArrayList<Statement>(); for (int i = 0; i < parms.length; i++) { finalParms[i] = Parameter.of(parms[i].getType().getErased(), parms[i].getName(), true); parmVars.add(Stmt.loadVariable(parms[i].getName())); } final Statement parameters = (intercepted) ? new StringStatement("getParameters()", MetaClassFactory.get(Object[].class)) : Stmt.newArray(Object.class).initialize(parmVars.toArray()); final BlockBuilder<?> methodBlock = classBuilder.publicMethod(method.getReturnType().getErased(), method.getName(), finalParms); if (intercepted) { methodBlock.append(generateInterceptorLogic(classBuilder, method, generateRequest(classBuilder, method, parameters, true), parmVars, interceptors)); } else { methodBlock.append(generateRequest(classBuilder, method, parameters, false)); } final Statement returnStmt = ProxyUtil.generateProxyMethodReturnStatement(method); if (returnStmt != null) { methodBlock.append(returnStmt); } methodBlock.finish(); }
/** * Adds path encoding to the provided statement * * @param s * the statement representing an HTTP path that should be encoded * @return statement with path encoding */ private Statement encodePath(final Statement s) { return Stmt.invokeStatic(URL.class, "encodePathSegment", s); }
private static String getPrivateMemberName(final MetaClassMember member) { if (member instanceof MetaField) { return PrivateAccessUtil.getPrivateFieldAccessorName((MetaField) member); } else { return PrivateAccessUtil.getPrivateMethodName((MetaMethod) member); } }
@Override public ContextualStatementBuilder call(final Statement instance, final HasAnnotations annotated, final BuildMetaClass factory, final Statement... params) { return nestedCall(instance); } };
if (ProxyUtil.isMethodInInterface(remoteIface, method)) { epts.put(ProxyUtil.createCallSignature(intf, method), RPCEndpointFactory.createEndpointFor(genericSvc, method, context.getBus()));
public static void addPrivateAccessStubs(final String type, final ClassStructureBuilder<?> classBuilder, final MetaField f) { addPrivateAccessStubs(PrivateAccessType.Both, type, classBuilder, f); }
public static Class<?> compileAndLoad(final File sourceFile, final String fullyQualifiedName) throws IOException { final String packageName = getPackageFromFQCN(fullyQualifiedName); final String className = getNameFromFQCN(fullyQualifiedName); return compileAndLoad(sourceFile, packageName, className); }
public static Class<?> compileAndLoad(final String sourcePath, final String packageName, final String className, final String outputPath) throws IOException { final String outputLocation = compileClass(sourcePath, packageName, className, outputPath); return loadClassDefinition(outputLocation, packageName, className); }
public ClassStructureBuilder<?> generate() { final String safeProxyClassName = remote.getFullyQualifiedName().replace('.', '_') + "Impl"; final ClassStructureBuilder<?> classBuilder = ClassBuilder.define(safeProxyClassName, AbstractRpcProxy.class) .packageScope() .implementsInterface(remote) .body(); for (final MetaMethod method : remote.getMethods()) { if (ProxyUtil.shouldProxyMethod(method)) { generateMethod(classBuilder, method); } } return classBuilder; }
@Override public boolean equals(final Object o) { return o instanceof MetaConstructor && GenUtil.equals(this, (MetaConstructor) o); } }
@Override public synchronized MetaClass asBoxed() { if (_boxedCache != null) return _boxedCache; return _boxedCache = GenUtil.getPrimitiveWrapper(this); }
private InterceptorProvider getInterceptorProvider(final GeneratorContext context) { final Collection<MetaClass> featureInterceptors = ClassScanner.getTypesAnnotatedWith(FeatureInterceptor.class, RebindUtils.findTranslatablePackages(context), context); addCacheRelevantClasses(featureInterceptors); final Collection<MetaClass> standaloneInterceptors = ClassScanner.getTypesAnnotatedWith(InterceptsRemoteCall.class, RebindUtils.findTranslatablePackages(context), context); addCacheRelevantClasses(standaloneInterceptors); return new InterceptorProvider(featureInterceptors, standaloneInterceptors); }
public static Class<?> compileAndLoad(final File sourceFile, final String fullyQualifiedName) throws IOException { final String packageName = getPackageFromFQCN(fullyQualifiedName); final String className = getNameFromFQCN(fullyQualifiedName); return compileAndLoad(sourceFile, packageName, className); }
@Override public boolean equals(final Object obj) { if (!(obj instanceof AnnotationWrapper)) { return false; } final AnnotationWrapper other = (AnnotationWrapper) obj; return CDIAnnotationUtils.equals(anno, other.anno); }
@Override public boolean equals(final Object obj) { return obj instanceof Named && CDIAnnotationUtils.equals(this, (Annotation) obj); } };