private void saveDataField(final Decorable decorable, final MetaClass type, final String name, final String fieldName, final Statement instance) { dataFieldMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, instance); dataFieldTypeMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, type); dataFieldAnnotationMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, (DataField) decorable.getAnnotation()); }
private void saveDataField(final Decorable decorable, final MetaClass type, final String name, final String fieldName, final Statement instance) { dataFieldMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, instance); dataFieldTypeMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, type); dataFieldAnnotationMap(decorable.getInjectionContext(), decorable.getDecorableDeclaringType()).put(name, (DataField) decorable.getAnnotation()); }
/** * Translates the template using the module's i18n message bundle (only if * i18n is enabled for the module). * @param decorable * @param initStmts * @param rootTemplateElement */ private void translateTemplate(final Decorable decorable, final List<Statement> initStmts, final Statement rootTemplateElement) { initStmts.add( Stmt.invokeStatic( TemplateUtil.class, "translateTemplate", getTemplateFileName(decorable.getDecorableDeclaringType()), rootTemplateElement )); }
/** * Translates the template using the module's i18n message bundle (only if * i18n is enabled for the module). * @param decorable * @param initStmts * @param rootTemplateElement */ private void translateTemplate(final Decorable decorable, final List<Statement> initStmts, final Statement rootTemplateElement) { initStmts.add( Stmt.invokeStatic( TemplateUtil.class, "translateTemplate", getTemplateFileName(decorable.getDecorableDeclaringType()), rootTemplateElement )); }
/** * Generates a {@link DestructionCallback} for the {@link Templated} component. * * @return statement representing the template destruction logic. */ private List<Statement> generateTemplateDestruction(final Decorable decorable) { final List<Statement> destructionStatements = new ArrayList<>(); final Map<String, Statement> dataFields = DataFieldCodeDecorator.aggregateDataFieldMap(decorable, decorable.getDecorableDeclaringType()); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); for (final String fieldName : dataFields.keySet()) { final Statement field = dataFields.get(fieldName); final MetaClass fieldType = dataFieldTypes.get(fieldName); if (fieldType.isAssignableTo(Element.class)) { destructionStatements.add(Stmt.invokeStatic(ElementWrapperWidget.class, "removeWidget", field)); } } if (decorable.getDecorableDeclaringType().isAssignableTo(Composite.class)) { destructionStatements.add(Stmt.invokeStatic(TemplateUtil.class, "cleanupWidget", decorable.getAccessStatement())); } else { destructionStatements.add(Stmt.invokeStatic(TemplateUtil.class, "cleanupTemplated", decorable.getAccessStatement())); } return destructionStatements; }
/** * Generates a {@link DestructionCallback} for the {@link Templated} component. * * @return statement representing the template destruction logic. */ private List<Statement> generateTemplateDestruction(final Decorable decorable) { final List<Statement> destructionStatements = new ArrayList<>(); final Map<String, Statement> dataFields = DataFieldCodeDecorator.aggregateDataFieldMap(decorable, decorable.getDecorableDeclaringType()); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); for (final String fieldName : dataFields.keySet()) { final Statement field = dataFields.get(fieldName); final MetaClass fieldType = dataFieldTypes.get(fieldName); if (fieldType.isAssignableTo(Element.class)) { destructionStatements.add(Stmt.invokeStatic(ElementWrapperWidget.class, "removeWidget", field)); } } if (decorable.getDecorableDeclaringType().isAssignableTo(Composite.class)) { destructionStatements.add(Stmt.invokeStatic(TemplateUtil.class, "cleanupWidget", decorable.getAccessStatement())); } else { destructionStatements.add(Stmt.invokeStatic(TemplateUtil.class, "cleanupTemplated", decorable.getAccessStatement())); } return destructionStatements; }
@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))); } }
private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller, final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) { final Statement instance = Refs.get("instance"); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); dataFieldTypes.put("this", decorable.getDecorableDeclaringType()); final MetaClass declaringClass = decorable.getDecorableDeclaringType(); /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */ final Set<String> processedNativeHandlers = new HashSet<>(); final Set<String> processedEventHandlers = new HashSet<>(); for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) { final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value(); validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames); final MetaClass eventType = assertEventType(declaringClass, method); if (eventType.isAssignableTo(Event.class)) { processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) { processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else { processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method, targetDataFieldNames, eventType, controller); } } }
private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller, final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) { final Statement instance = Refs.get("instance"); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); dataFieldTypes.put("this", decorable.getDecorableDeclaringType()); final MetaClass declaringClass = decorable.getDecorableDeclaringType(); /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */ final Set<String> processedNativeHandlers = new HashSet<>(); final Set<String> processedEventHandlers = new HashSet<>(); for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) { final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value(); validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames); final MetaClass eventType = assertEventType(declaringClass, method); if (eventType.isAssignableTo(Event.class)) { processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) { processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else { processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method, targetDataFieldNames, eventType, controller); } } }
initStmts.add(invokeStatic(TemplateUtil.class, "compositeComponentReplace", decorable.getDecorableDeclaringType() .getFullyQualifiedName(), getTemplateFileName(decorable.getDecorableDeclaringType()), supplierOf(Cast.to(Widget.class, field.getValue())), dataFieldElements, fieldsMetaMap, field.getKey()));
initStmts.add(invokeStatic(TemplateUtil.class, "compositeComponentReplace", decorable.getDecorableDeclaringType() .getFullyQualifiedName(), getTemplateFileName(decorable.getDecorableDeclaringType()), supplierOf(Cast.to(Widget.class, field.getValue())), dataFieldElements, fieldsMetaMap, field.getKey()));
final List<MetaField> modelFields = decorable.getDecorableDeclaringType().getFieldsAnnotatedWith(Model.class); if (!modelFields.isEmpty()) { throw new GenerationException("Found one or more fields annotated with @Model but missing @Inject " final List<MetaParameter> modelParameters = decorable.getDecorableDeclaringType().getParametersAnnotatedWith(Model.class); if (!modelParameters.isEmpty()) { throw new GenerationException(
final List<MetaField> modelFields = decorable.getDecorableDeclaringType().getFieldsAnnotatedWith(Model.class); if (!modelFields.isEmpty()) { throw new GenerationException("Found one or more fields annotated with @Model but missing @Inject " final List<MetaParameter> modelParameters = decorable.getDecorableDeclaringType().getParametersAnnotatedWith(Model.class); if (!modelParameters.isEmpty()) { throw new GenerationException(
@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)); }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final MetaClass declaringClass = decorable.getDecorableDeclaringType();
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { final MetaClass declaringClass = decorable.getDecorableDeclaringType();
if (val.startsWith("{") && val.endsWith("}")) { String fieldName = val.substring(1, val.length() - 1); MetaField field = decorable.getDecorableDeclaringType().getInheritedField(fieldName); fieldValueStmt = InjectUtil.getPublicOrPrivateFieldValue(controller, field);
} else { if ( !isWidget ) { throw new GenerationException( "Unable to use [" + name + "] in class [" + decorable.getDecorableDeclaringType() + "] as a @DataField. The field must be a Widget, IsWidget, or a DOM element as either a JavaScriptObject, native @JsType, or IsElement." );
} else { if ( !isWidget ) { throw new GenerationException( "Unable to use [" + name + "] in class [" + decorable.getDecorableDeclaringType() + "] as a @DataField. The field must be a Widget, IsWidget, or a DOM element as either a JavaScriptObject, native @JsType, or IsElement." );