public static GeneratorMappingContext getFor(GeneratorContext context, MarshallerOutputTarget target) { GeneratorMappingContext mappingContext = null; if (target == MarshallerOutputTarget.GWT) { mappingContext = gwtContexts.get(context); } else if (target == MarshallerOutputTarget.Java) { mappingContext = javaContext; } if (mappingContext == null) { throw new GenerationException("Generation context for output target " + target + " was not created!"); } return mappingContext; }
public static GeneratorMappingContext getFor(GeneratorContext context, MarshallerOutputTarget target) { GeneratorMappingContext mappingContext = null; if (target == MarshallerOutputTarget.GWT) { mappingContext = gwtContexts.get(context); } else if (target == MarshallerOutputTarget.Java) { mappingContext = javaContext; } if (mappingContext == null) { throw new GenerationException("Generation context for output target " + target + " was not created!"); } return mappingContext; }
public static GeneratorMappingContext getFor(GeneratorContext context, MarshallerOutputTarget target) { GeneratorMappingContext mappingContext = null; if (target == MarshallerOutputTarget.GWT) { mappingContext = gwtContexts.get(context); } else if (target == MarshallerOutputTarget.Java) { mappingContext = javaContext; } if (mappingContext == null) { throw new GenerationException("Generation context for output target " + target + " was not created!"); } return mappingContext; }
private void validateDefaultPagePresent(Collection<MetaClass> pages, Multimap<Class<?>, MetaClass> pageRoles) { Collection<MetaClass> defaultPages = pageRoles.get(DefaultPage.class); if (!pages.isEmpty() && defaultPages.isEmpty()) { throw new GenerationException( "No @Page classes have role = DefaultPage. Exactly one @Page class" + " must be designated as the default starting page."); } }
private void validateDefaultPagePresent(Collection<MetaClass> pages, Multimap<Class<?>, MetaClass> pageRoles) { Collection<MetaClass> defaultPages = pageRoles.get(DefaultPage.class); if (!pages.isEmpty() && defaultPages.isEmpty()) { throw new GenerationException( "No @Page classes have role = DefaultPage. Exactly one @Page class" + " must be designated as the default starting page."); } }
private void createValidationError(Collection<MetaClass> pages, Class<?> role) { StringBuilder builder = new StringBuilder(); for (MetaClass mc : pages) { builder.append("\n ").append(mc.getFullyQualifiedName()); } throw new GenerationException( "Found more than one @Page with role = '" + role + "': " + builder + "\nExactly one @Page class must be designated with this unique role."); }
private void createValidationError(Collection<MetaClass> pages, Class<?> role) { StringBuilder builder = new StringBuilder(); for (MetaClass mc : pages) { builder.append("\n ").append(mc.getFullyQualifiedName()); } throw new GenerationException( "Found more than one @Page with role = '" + role + "': " + builder + "\nExactly one @Page class must be designated with this unique role."); }
private void validateSafePagePath(Collection<MetaClass> pages) { for (final MetaClass page : pages) { String pageName = getPageName(page); String path = getPageURL(page, pageName); if (!path.equals(pageName)) { if (path.contains(";") || path.contains("=") || path.contains("&")) { throw new GenerationException("Invalid page path for page " + pageName + ". Page paths must not contain " + "semicolons(;), ampersands(&) or equal signs(=)."); } } } }
private void validateSafePagePath(Collection<MetaClass> pages) { for (final MetaClass page : pages) { String pageName = getPageName(page); String path = getPageURL(page, pageName); if (!path.equals(pageName)) { if (path.contains(";") || path.contains("=") || path.contains("&")) { throw new GenerationException("Invalid page path for page " + pageName + ". Page paths must not contain " + "semicolons(;), ampersands(&) or equal signs(=)."); } } } }
private Class<? extends UniquePageRole> assertRoleExistsAndIsValid(final InjectionSite injectionSite, final InjectionContext injectionContext) { final Class<? extends UniquePageRole> candidateRole = injectionSite.getAnnotation(TransitionToRole.class).value(); if (pagesByRole.get(candidateRole).size() == 1) { return candidateRole; } else if (pagesByRole.get(candidateRole).isEmpty()) { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but no @%s exists with that role.", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName())); } else { throw new GenerationException( String.format("An @%s Anchor was found for the role %s but multiple @%ss pages exist with that role: %s", TransitionToRole.class.getSimpleName(), candidateRole.getName(), Page.class.getSimpleName(), pagesByRole.get(candidateRole).toString())); } }
private void validateNonEmptyEventHandlerTargets(final MetaClass declaringClass, final MetaMethod method, final String[] targetDataFieldNames) { if (targetDataFieldNames.length == 0) { throw new GenerationException("@EventHandler annotation on method [" + declaringClass.getFullyQualifiedName() + "." + method.getName() + "] must specify at least one data-field target."); } }
/** * Ensured the provided type is bindable and throws a * {@link GenerationException} in case it's not. * * @param type * the type to check */ private static void assertTypeIsBindable(final MetaClass type) { if (!isBindableType(type)) { throw new GenerationException(type.getName() + " must be a @Bindable type when used as @Model"); } }
/** * Ensured the provided type is bindable and throws a * {@link GenerationException} in case it's not. * * @param type * the type to check */ private static void assertTypeIsBindable(final MetaClass type) { if (!isBindableType(type)) { throw new GenerationException(type.getName() + " must be a @Bindable type when used as @Model"); } }
private void validateNonEmptyEventHandlerTargets(final MetaClass declaringClass, final MetaMethod method, final String[] targetDataFieldNames) { if (targetDataFieldNames.length == 0) { throw new GenerationException("@EventHandler annotation on method [" + declaringClass.getFullyQualifiedName() + "." + method.getName() + "] must specify at least one data-field target."); } }
/** * Gets the bundle name from the @Bundle annotation. * * @param bundleAnnotatedClass */ private String getMessageBundlePath(final MetaClass bundleAnnotatedClass) { final Bundle annotation = bundleAnnotatedClass.getAnnotation(Bundle.class); final String name = annotation.value(); if (name == null) { throw new GenerationException("@Bundle: bundle name must not be null]."); } // Absolute path vs. relative path. if (name.startsWith("/")) { return name.substring(1); } else { final String packageName = bundleAnnotatedClass.getPackageName(); return packageName.replace('.', '/') + "/" + name; } }
/** * Ensures the provided type is a {@link DataBinder} and throws a * {@link GenerationException} in case it's not. * * @param type * the type to check */ private static void assertTypeIsDataBinder(final MetaClass type) { final MetaClass databinderMetaClass = MetaClassFactory.get(DataBinder.class); if (!databinderMetaClass.isAssignableFrom(type)) { throw new GenerationException("Type of @AutoBound element must be " + DataBinder.class.getName() + " but is: " + type.getFullyQualifiedName()); } }
/** * Ensures the provided type is a {@link DataBinder} and throws a * {@link GenerationException} in case it's not. * * @param type * the type to check */ private static void assertTypeIsDataBinder(final MetaClass type) { final MetaClass databinderMetaClass = MetaClassFactory.get(DataBinder.class); if (!databinderMetaClass.isAssignableFrom(type)) { throw new GenerationException("Type of @AutoBound element must be " + DataBinder.class.getName() + " but is: " + type.getFullyQualifiedName()); } }
private MetaClass getGwtHandlerType(final MetaClass declaringClass, final MetaClass eventType) { try { return getHandlerForEvent(eventType); } catch (final GenerationException e) { /* * see ERRAI-373 for details on this crazy inference (without this message, the cause of the * problem is nearly impossible to diagnose) */ if (declaringClass.getClass() == JavaReflectionClass.class) { throw new GenerationException( "The type " + declaringClass.getFullyQualifiedName() + " looks like a client-side" + " @Templated class, but it is not known to GWT. This probably means that " + declaringClass.getName() + " or one of its supertypes contains non-translatable code." + " Run the GWT compiler with logLevel=DEBUG to pinpoint the problem.", e); } throw e; } }
private MetaMethod validateExceptionHandlingMethod(final Decorable decorable) { // Ensure that method has exactly one parameter of type Throwable final MetaMethod method = decorable.getAsMethod(); final MetaParameter[] parms = method.getParameters(); if (!(parms.length == 1 && parms[0].getType().equals(MetaClassFactory.get(Throwable.class)))) { throw new GenerationException("Methods annotated with " + UncaughtExceptionHandler.class.getName() + " must have exactly one parameter of type " + Throwable.class.getName() + ". Invalid parameters in method: " + GenUtil.getMethodString(method) + " of type " + method.getDeclaringClass() + "."); } return method; }
@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)); }