@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final ShadowService shadowService = (ShadowService) decorable.getAnnotation(); String serviceName = null; Statement subscribeShadowStatement = null; final Class<?> javaClass = decorable.getType().asClass(); for (final Class<?> intf : javaClass.getInterfaces()) { if (intf.isAnnotationPresent(Remote.class)) { serviceName = intf.getName() + ":RPC"; final AnonymousClassStructureBuilder builder = generateMethodDelegates(intf, decorable, controller); subscribeShadowStatement = Stmt.castTo(ClientMessageBus.class, Stmt.invokeStatic(ErraiBus.class, "get")) .invoke("subscribeShadow", serviceName, builder.finish()); } if (serviceName == null) { if (shadowService.value().equals("")) { serviceName = decorable.getName(); } else { serviceName = shadowService.value(); } subscribeShadowStatement = Stmt.castTo(ClientMessageBus.class, Stmt.invokeStatic(ErraiBus.class, "get")) .invoke("subscribeShadow", serviceName, controller.contextGetInstanceStmt()); } controller.addFactoryInitializationStatements(Collections.singletonList(subscribeShadowStatement)); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final ShadowService shadowService = (ShadowService) decorable.getAnnotation(); String serviceName = null; Statement subscribeShadowStatement = null; final Class<?> javaClass = decorable.getType().asClass(); for (final Class<?> intf : javaClass.getInterfaces()) { if (intf.isAnnotationPresent(Remote.class)) { serviceName = intf.getName() + ":RPC"; final AnonymousClassStructureBuilder builder = generateMethodDelegates(intf, decorable, controller); subscribeShadowStatement = Stmt.castTo(ClientMessageBus.class, Stmt.invokeStatic(ErraiBus.class, "get")) .invoke("subscribeShadow", serviceName, builder.finish()); } if (serviceName == null) { if (shadowService.value().equals("")) { serviceName = decorable.getName(); } else { serviceName = shadowService.value(); } subscribeShadowStatement = Stmt.castTo(ClientMessageBus.class, Stmt.invokeStatic(ErraiBus.class, "get")) .invoke("subscribeShadow", serviceName, controller.contextGetInstanceStmt()); } controller.addFactoryInitializationStatements(Collections.singletonList(subscribeShadowStatement)); } }
private BlockBuilder<AnonymousClassStructureBuilder> getSubscriptionCallback(final Decorable decorable, final FactoryController controller) { final MetaParameter parm = decorable.getAsParameter(); final MetaClass eventType = parm.getType().asBoxed(); final String parmClassName = eventType.getFullyQualifiedName(); final List<Annotation> annotations = InjectUtil.extractQualifiers(parm); final Annotation[] qualifiers = annotations.toArray(new Annotation[annotations.size()]); final Set<String> qualifierNames = new HashSet<>(CDI.getQualifiersPart(qualifiers)); final MetaClass callBackType = parameterizedAs(AbstractCDIEventCallback.class, typeParametersOf(eventType)); AnonymousClassStructureBuilder callBack = Stmt.newObject(callBackType).extend(); BlockBuilder<AnonymousClassStructureBuilder> callBackBlock; if (!qualifierNames.isEmpty()) { callBackBlock = callBack.initialize(); for (final String qualifierName : qualifierNames) { callBackBlock.append(Stmt.loadClassMember("qualifierSet").invoke("add", qualifierName)); } callBack = callBackBlock.finish(); } final List<Statement> fireEventStmts = new ArrayList<>(); if (!decorable.isEnclosingTypeDependent()) { fireEventStmts.add(Stmt.declareFinalVariable("instance", decorable.getEnclosingInjectable().getInjectedType(), Stmt.invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt()))); } fireEventStmts.add(decorable.call(Refs.get("event"))); callBackBlock = callBack.publicOverridesMethod("fireEvent", Parameter.finalOf(eventType, "event")) .appendAll(fireEventStmts) .finish() .publicOverridesMethod("toString") ._(Stmt.load("Observer: " + parmClassName + " " + Arrays.toString(qualifiers)).returnValue()); return callBackBlock; }
private BlockBuilder<AnonymousClassStructureBuilder> getJsTypeSubscriptionCallback(final Decorable decorable, final FactoryController controller) { final MetaParameter parm = decorable.getAsParameter(); final MetaClass eventType = parm.getType().asBoxed(); final String parmClassName = eventType.getFullyQualifiedName(); final MetaClass callBackType = parameterizedAs(JsTypeEventObserver.class, typeParametersOf(eventType)); final AnonymousClassStructureBuilder callBack = Stmt.newObject(callBackType).extend(); BlockBuilder<AnonymousClassStructureBuilder> callBackBlock; final List<Statement> fireEventStmts = new ArrayList<>(); if (!decorable.isEnclosingTypeDependent()) { fireEventStmts.add(Stmt.declareFinalVariable("instance", decorable.getEnclosingInjectable().getInjectedType(), Stmt.invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt()))); } fireEventStmts.add(decorable.call(Refs.get("event"))); callBackBlock = callBack.publicOverridesMethod("onEvent", Parameter.finalOf(eventType, "event")) .appendAll(fireEventStmts) .finish() .publicOverridesMethod("toString") ._(Stmt.load("JsTypeObserver: " + parmClassName).returnValue()); return callBackBlock; } }
bindExecStmts.add(declareFinalVariable("instance", decorable.getEnclosingInjectable().getInjectedType(), castTo(decorable.getEnclosingInjectable().getInjectedType(), invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt()))));
callbackStatements .add(declareFinalVariable("instance", decorable.getDecorableDeclaringType(), castTo(decorable.getEnclosingInjectable().getInjectedType(), invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt()))));
bindExecStmts.add(declareFinalVariable("instance", decorable.getEnclosingInjectable().getInjectedType(), castTo(decorable.getEnclosingInjectable().getInjectedType(), invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt()))));
private Statement declareAndInitHandlerVar(final Decorable decorable, final FactoryController controller, final String name, final boolean enclosingTypeDependent) { final MetaClass throwableConsumerClass = parameterizedAs(Consumer.class, typeParametersOf(Throwable.class)); final BlockBuilder<AnonymousClassStructureBuilder> initBuilder = newObject(throwableConsumerClass) .extend().publicOverridesMethod("accept", Parameter.of(Throwable.class, "t")); if (!enclosingTypeDependent) { final MetaClass enclosingType = decorable.getEnclosingInjectable().getInjectedType(); initBuilder.append(declareFinalVariable("instance", enclosingType, castTo(enclosingType, invokeStatic(Factory.class, "maybeUnwrapProxy", controller.contextGetInstanceStmt())))); } final ObjectBuilder initStmt = initBuilder.append(decorable.call(Refs.get("t"))).finish().finish(); final Statement handlerStatement = declareFinalVariable(name, throwableConsumerClass, initStmt); return handlerStatement; } }
.cond(Stmt.loadLiteral(ProxyUtil.createCallSignature(method)).invoke("equals", Stmt.loadVariable("commandType"))); blockBuilder.append(Stmt.declareFinalVariable("instance", intf, controller.contextGetInstanceStmt()));
.cond(Stmt.loadLiteral(ProxyUtil.createCallSignature(method)).invoke("equals", Stmt.loadVariable("commandType"))); blockBuilder.append(Stmt.declareFinalVariable("instance", intf, controller.contextGetInstanceStmt()));