@Override protected List<Statement> generateDestroyInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { final List<Statement> destroyInstanceStmts = new ArrayList<>(); final Multimap<DependencyType, Dependency> depsByType = separateByType(injectable.getDependencies()); final Collection<Dependency> producerMemberDeps = depsByType.get(DependencyType.ProducerMember); if (producerMemberDeps.size() != 1) { throw new RuntimeException("A produced type must have exactly 1 producing instance but " + producerMemberDeps.size() + " were found."); } final Collection<Dependency> disposerMethodDeps = depsByType.get(DependencyType.DisposerMethod); if (disposerMethodDeps.size() > 1) { // TODO error message with matching disposer names. throw new RuntimeException(); } else if (disposerMethodDeps.size() == 1) { final DisposerMethodDependency disposerDep = (DisposerMethodDependency) disposerMethodDeps.iterator().next(); final MetaMethod disposer = disposerDep.getDisposerMethod(); controller.ensureMemberExposed(disposer); final Statement invocation = controller.exposedMethodStmt( controller.getReferenceStmt(PRODUCER_INSTANCE, disposer.getDeclaringClass()), disposer, getDisposerParams(disposer, depsByType.get(DependencyType.DisposerParameter), bodyBlockBuilder.getClassDefinition())); destroyInstanceStmts.add(invocation); } return destroyInstanceStmts; }
private static void addCleanup(final Decorable decorable, final FactoryController controller, final List<Statement> destructionStmts) { final DataBindingUtil.DataBinderRef dataBinder = DataBindingUtil.lookupDataBinderRef(decorable, controller); if (!controller.hasAttribute(STYLE_BINDING_HOUSEKEEPING_ATTR)) { destructionStmts.add( Stmt.invokeStatic(StyleBindingsRegistry.class, "get").invoke("cleanAllForBean", Refs.get("instance"))); if (dataBinder != null) { destructionStmts.add(controller.getReferenceStmt("styleBindingChangeHandlerUnsub", PropertyChangeUnsubscribeHandle.class).invoke("unsubscribe")); } controller.setAttribute(STYLE_BINDING_HOUSEKEEPING_ATTR, Boolean.TRUE); } }
private static void addCleanup(final Decorable decorable, final FactoryController controller, final List<Statement> destructionStmts) { final DataBindingUtil.DataBinderRef dataBinder = DataBindingUtil.lookupDataBinderRef(decorable, controller); if (!controller.hasAttribute(STYLE_BINDING_HOUSEKEEPING_ATTR)) { destructionStmts.add( Stmt.invokeStatic(StyleBindingsRegistry.class, "get").invoke("cleanAllForBean", Refs.get("instance"))); if (dataBinder != null) { destructionStmts.add(controller.getReferenceStmt("styleBindingChangeHandlerUnsub", PropertyChangeUnsubscribeHandle.class).invoke("unsubscribe")); } controller.setAttribute(STYLE_BINDING_HOUSEKEEPING_ATTR, Boolean.TRUE); } }
@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.setReferenceStmt(MODEL_VAR_NAME, DecorableType.PARAM.getAccessStatement(mp, decorable.getFactoryMetaClass())))); dataBinderRef = controller.getInstancePropertyStmt( controller.getReferenceStmt(MODEL_VAR_NAME, dataModelType), BINDER_VAR_NAME, DataBinder.class);
controller.setReferenceStmt(MODEL_VAR_NAME, DecorableType.PARAM.getAccessStatement(mp, decorable.getFactoryMetaClass())))); dataBinderRef = controller.getInstancePropertyStmt( controller.getReferenceStmt(MODEL_VAR_NAME, dataModelType), BINDER_VAR_NAME, DataBinder.class);
Stmt.nestedCall(controller.getReferenceStmt(varName, Subscription.class)).invoke("remove")));
Stmt.nestedCall(controller.getReferenceStmt(varName, Subscription.class)).invoke("remove")));
syncAnnotation.query(), Stmt.loadVariable("objectClass"), null))); final Statement syncWorkerRef = controller.getReferenceStmt("syncWorker", ClientSyncWorker.class); statements.add( Stmt.nestedCall(syncWorkerRef).invoke("addSyncCallback", createSyncCallback(decorable)));
final Statement timerVar = controller.getReferenceStmt(timerVarName, Timer.class);
controller.getReferenceStmt(handlerVarName, StyleBindingChangeHandler.class))));
controller.getReferenceStmt(handlerVarName, StyleBindingChangeHandler.class))));
controller.getReferenceStmt(registrationHandleVar, RefHolder.class).invoke("get")) .invoke("cleanup")); if (enclosingTypeIsDependent) {
controller.getReferenceStmt(registrationHandleVar, RefHolder.class).invoke("get")) .invoke("cleanup")); if (enclosingTypeIsDependent) {
if (!hasRunForType) { controller.addDestructionStatements(Collections.<Statement> singletonList( nestedCall(controller.getReferenceStmt(DataBindingUtil.BINDER_VAR_NAME, DataBinder.class)).invoke("unbind")));
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { if (decorable.getAsMethod().getParameters() == null || decorable.getAsMethod().getParameters().length != 1) throw new GenerationException("@ModelSetter method needs to have exactly one parameter: " + decorable.getAsMethod()); final MetaClass modelType = (MetaClass) controller.getAttribute(DataBindingUtil.BINDER_MODEL_TYPE_VALUE); if (!decorable.getAsMethod().getParameters()[0].getType().equals(modelType)) { throw new GenerationException("@ModelSetter method parameter must be of type: " + modelType); } final Statement dataBinder = controller.getReferenceStmt(DataBindingUtil.BINDER_VAR_NAME, DataBinder.class); final Statement proxyProperty = controller.addProxyProperty("dataBinder", DataBinder.class, dataBinder); final String modelParamName = decorable.getAsMethod().getParameters()[0].getName(); controller.addInvokeBefore(decorable.getAsMethod(), nestedCall(proxyProperty) .invoke("setModel", Refs.get(modelParamName), loadStatic(StateSync.class, "FROM_MODEL"))); controller.addInvokeBefore( decorable.getAsMethod(), loadVariable(modelParamName).assignValue( Cast.to(decorable.getAsMethod().getParameters()[0].getType(), nestedCall( proxyProperty).invoke("getModel")))); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { if (decorable.getAsMethod().getParameters() == null || decorable.getAsMethod().getParameters().length != 1) throw new GenerationException("@ModelSetter method needs to have exactly one parameter: " + decorable.getAsMethod()); final MetaClass modelType = (MetaClass) controller.getAttribute(DataBindingUtil.BINDER_MODEL_TYPE_VALUE); if (!decorable.getAsMethod().getParameters()[0].getType().equals(modelType)) { throw new GenerationException("@ModelSetter method parameter must be of type: " + modelType); } final Statement dataBinder = controller.getReferenceStmt(DataBindingUtil.BINDER_VAR_NAME, DataBinder.class); final Statement proxyProperty = controller.addProxyProperty("dataBinder", DataBinder.class, dataBinder); final String modelParamName = decorable.getAsMethod().getParameters()[0].getName(); controller.addInvokeBefore(decorable.getAsMethod(), nestedCall(proxyProperty) .invoke("setModel", Refs.get(modelParamName), loadStatic(StateSync.class, "FROM_MODEL"))); controller.addInvokeBefore( decorable.getAsMethod(), loadVariable(modelParamName).assignValue( Cast.to(decorable.getAsMethod().getParameters()[0].getType(), nestedCall( proxyProperty).invoke("getModel")))); } }