@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final List<Statement> statements = new ArrayList<Statement>(); if (decorable.getDecorableDeclaringType().isAnnotationPresent(RestrictedAccess.class)) { final RestrictedAccess annotation = decorable.getDecorableDeclaringType().getAnnotation(RestrictedAccess.class); final String roleListenerVar = "roleListener"; statements.add(controller.setReferenceStmt(roleListenerVar, Stmt.newObject(PageRoleLifecycleListener.class, annotation, Stmt.newObject(ClientRequiredRolesExtractorImpl.class)))); Statement roleListenerRef = controller.getReferenceStmt(roleListenerVar, PageRoleLifecycleListener.class); statements.add(Stmt.invokeStatic(IOC.class, "registerLifecycleListener", Refs.get("instance"), roleListenerRef)); controller.addInitializationStatements(statements); controller.addDestructionStatements(Collections.<Statement> singletonList(Stmt.invokeStatic(IOC.class, "unregisterLifecycleListener", Refs.get("instance"), roleListenerRef))); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final List<Statement> statements = new ArrayList<Statement>(); if (decorable.getDecorableDeclaringType().isAnnotationPresent(RestrictedAccess.class)) { final RestrictedAccess annotation = decorable.getDecorableDeclaringType().getAnnotation(RestrictedAccess.class); final String roleListenerVar = "roleListener"; statements.add(controller.setReferenceStmt(roleListenerVar, Stmt.newObject(PageRoleLifecycleListener.class, annotation, Stmt.newObject(ClientRequiredRolesExtractorImpl.class)))); Statement roleListenerRef = controller.getReferenceStmt(roleListenerVar, PageRoleLifecycleListener.class); statements.add(Stmt.invokeStatic(IOC.class, "registerLifecycleListener", Refs.get("instance"), roleListenerRef)); controller.addInitializationStatements(statements); controller.addDestructionStatements(Collections.<Statement> singletonList(Stmt.invokeStatic(IOC.class, "unregisterLifecycleListener", Refs.get("instance"), roleListenerRef))); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final MetaMethod method = validateExceptionHandlingMethod(decorable); final boolean enclosingTypeDependent = decorable.isEnclosingTypeDependent(); final String handlerVar = method.getName() + "Handler"; final String cleanupRunnableVar = method.getName() + "HandlerCleanup"; final Statement setCleanupRefStmt = controller.setReferenceStmt(cleanupRunnableVar, Refs.get(cleanupRunnableVar)); final Statement getCleanupRefStmt = controller.getReferenceStmt(cleanupRunnableVar, Runnable.class); final List<Statement> initStmts = new ArrayList<>(Arrays.asList( declareAndInitHandlerVar(decorable, controller, handlerVar, enclosingTypeDependent), declareFinalVariable(cleanupRunnableVar, Runnable.class, addHandler(handlerVar)))); if (enclosingTypeDependent) { initStmts.add(setCleanupRefStmt); } final List<Statement> destructionStmts = Collections.singletonList(nestedCall(getCleanupRefStmt).invoke("run")); if (enclosingTypeDependent) { controller.addInitializationStatements(initStmts); controller.addDestructionStatements(destructionStmts); } else { controller.addFactoryInitializationStatements(initStmts); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { MetaMethod method = decorable.getAsMethod(); MetaParameter[] params = method.getParameters(); if (params.length != 1 || !params[0].getType().getErased().equals(MetaClassFactory.get(SyncResponses.class))) { throw new GenerationException("Methods annotated with @" + Sync.class.getName() + " need to have exactly one parameter of type: " + SyncResponses.class.getName() + ". Check method: " + GenUtil.getMethodString(method) + " in class " + method.getDeclaringClass().getFullyQualifiedName()); } Sync syncAnnotation = (Sync) decorable.getAnnotation(); controller.addInitializationStatements(createInitStatements(decorable.getDecorableDeclaringType(), "obj", syncAnnotation, decorable, controller)); final Statement syncWorker = controller.getReferenceStmt("syncWorker", ClientSyncWorker.class); final Statement destruction = Stmt.nestedCall(syncWorker).invoke("stop"); controller.addDestructionStatements(Collections.singletonList(destruction)); }
controller.addDestructionStatements(generateTemplateDestruction(decorable)); controller.addInitializationStatementsToEnd(Collections.<Statement>singletonList(invokeStatic(StyleBindingsRegistry.class, "get") .invoke("updateStyles", Refs.get("instance"))));
controller.addDestructionStatements(Collections.<Statement> singletonList( Stmt.nestedCall(controller.getReferenceStmt(varName, Subscription.class)).invoke("remove")));
controller.addDestructionStatements(generateTemplateDestruction(decorable)); controller.addInitializationStatementsToEnd(Collections.<Statement>singletonList(invokeStatic(StyleBindingsRegistry.class, "get") .invoke("updateStyles", Refs.get("instance"))));
controller.addDestructionStatements(Collections.<Statement> singletonList( Stmt.nestedCall(controller.getReferenceStmt(varName, Subscription.class)).invoke("remove")));
controller.addDestructionStatements(destructionStmts);
controller.addDestructionStatements(destroyStatements); } else { controller.addFactoryInitializationStatements(initStatements);
controller.addDestructionStatements(destructionStmts);
controller.addDestructionStatements(destructionStmts);
controller.addFactoryInitializationStatements(initStmts); controller.addDestructionStatements(destructionStmts);
controller.addFactoryInitializationStatements(initStmts); controller.addDestructionStatements(destructionStmts);
controller.addInitializationStatements(statements); if (!hasRunForType) { controller.addDestructionStatements(Collections.<Statement> singletonList( nestedCall(controller.getReferenceStmt(DataBindingUtil.BINDER_VAR_NAME, DataBinder.class)).invoke("unbind")));
controller.addInitializationStatements(statements); if (!hasRunForType) { controller.addDestructionStatements(Collections.<Statement> singletonList( nestedCall(controller.getReferenceStmt(DataBindingUtil.BINDER_VAR_NAME, DataBinder.class)).invoke("unbind")));
@Override public void generateDecorator(Decorable decorable, FactoryController controller) { controller.addInvokeBefore(decorable.getAsMethod(), Stmt.invokeStatic(TestDataCollector.class, "beforeInvoke", Refs.get("text"), Refs.get("blah"))); controller.addInvokeAfter(decorable.getAsMethod(), Stmt.invokeStatic(TestDataCollector.class, "afterInvoke", Refs.get("text"), Refs.get("blah"))); final Statement foobar = controller.addProxyProperty("foobar", String.class, Stmt.load("foobie!")); controller.addInvokeAfter(decorable.getAsMethod(), Stmt.invokeStatic(TestDataCollector.class, "property", "foobar", foobar) ); controller.addInitializationStatements(Arrays.<Statement>asList(Stmt.loadVariable("instance").invoke("setFlag", true))); controller.addDestructionStatements(Arrays.<Statement>asList(Stmt.loadVariable("instance").invoke("setFlag", false))); } }