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; }
protected void blameAndRethrow(GenerationException e) { if (!blameDetailsEnabled) { final RuntimeException blamePlaceHolder = new RuntimeException( "Problem during Errai code generation. Please set system property -Derrai.codegen.details=true for more details."); blamePlaceHolder.initCause(e); throw blamePlaceHolder; } if (e.getCause() == null) { GenUtil.rewriteBlameStackTrace(blame); e.initCause(blame); } throw e; } }
throw new GenerationException("Method " + method + " in " + typeToSnapshot + " takes parameters. Such methods must be handled by the MethodBodyCallback," + " because they cannot be snapshotted."); e.appendFailureInfo("In attempt to snapshot return value of " + typeToExtend.getFullyQualifiedName() + "." + method.getName() + "()"); throw e; throw new GenerationException("Failed to extract value for snapshot", e); e.appendFailureInfo("While generating a snapshot of " + o.toString() + " (actual type: " + o.getClass().getName() + "; type to extend: " + typeToExtend.getFullyQualifiedName() + ")");
public static Statement[] generateCallParameters(final MetaMethod method, final Context context, final Object... parameters) { if (parameters.length != method.getParameters().length && !method.isVarArgs()) { throw new UndefinedMethodException("Wrong number of parameters"); } final MetaParameter[] methParms = method.getParameters(); final Statement[] statements = new Statement[parameters.length]; int i = 0; for (Object parameter : parameters) { if (parameter instanceof Statement) { if (((Statement) parameter).getType() == null) { parameter = generate(context, parameter); } } try { statements[i] = convert(context, parameter, methParms[i++].getType()); } catch (final GenerationException t) { t.appendFailureInfo("in method call: " + method.getDeclaringClass().getFullyQualifiedName() + "." + method.getName() + "(" + Arrays.toString(methParms) + ")"); throw t; } } return statements; }
throw new GenerationException("Method " + method + " in " + typeToSnapshot + " takes parameters. Such methods must be handled by the MethodBodyCallback," + " because they cannot be snapshotted."); e.appendFailureInfo("In attempt to snapshot return value of " + typeToExtend.getFullyQualifiedName() + "." + method.getName() + "()"); throw e; throw new GenerationException("Failed to extract value for snapshot", e); e.appendFailureInfo("While generating a snapshot of " + o.toString() + " (actual type: " + o.getClass().getName() + "; type to extend: " + typeToExtend.getFullyQualifiedName() + ")");
public static Statement[] generateCallParameters(final MetaMethod method, final Context context, final Object... parameters) { if (parameters.length != method.getParameters().length && !method.isVarArgs()) { throw new UndefinedMethodException("Wrong number of parameters"); } final MetaParameter[] methParms = method.getParameters(); final Statement[] statements = new Statement[parameters.length]; int i = 0; for (Object parameter : parameters) { if (parameter instanceof Statement) { if (((Statement) parameter).getType() == null) { parameter = generate(context, parameter); } } try { statements[i] = convert(context, parameter, methParms[i++].getType()); } catch (final GenerationException t) { t.appendFailureInfo("in method call: " + method.getDeclaringClass().getFullyQualifiedName() + "." + method.getName() + "(" + Arrays.toString(methParms) + ")"); throw t; } } return statements; }
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; }
protected void blameAndRethrow(GenerationException e) { if (!blameDetailsEnabled) { final RuntimeException blamePlaceHolder = new RuntimeException( "Problem during Errai code generation. Please set system property -Derrai.codegen.details=true for more details."); blamePlaceHolder.initCause(e); throw blamePlaceHolder; } if (e.getCause() == null) { GenUtil.rewriteBlameStackTrace(blame); e.initCause(blame); } throw e; } }
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 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"); } }
private void addUrlsFromBundleAnnotations(final Collection<MetaClass> bundleAnnotatedClasses, final Collection<URL> urls) { final Set<String> completedPaths = new HashSet<>(); for (final MetaClass bundleClass : bundleAnnotatedClasses) { final String bundlePath = getMessageBundlePath(bundleClass); if (bundlePath != null && !completedPaths.contains(bundlePath)) { final URL resource = getClass().getClassLoader().getResource(bundlePath); if (resource == null) { throw new GenerationException("Failed to load bundle " + bundlePath + " defined on class " + bundleClass.getFullyQualifiedName()); } final URL classpathElement; final String pathRoot = getPathRoot(bundleClass, resource); try { final String urlString = new URI(pathRoot).toURL().toString(); // URLs returned by the classloader are UTF-8 encoded. The URLDecoder assumes // a HTML form encoded String, which is why we escape the plus symbols here. // Otherwise, they would be decoded into space characters. // The pound character still must not appear anywhere in the path! classpathElement = new URL(URLDecoder.decode(urlString.replaceAll("\\+", "%2b"), "UTF-8")); } catch (final Exception e) { log.warn("Failed to construct URL for i18n bundle defined in " + bundleClass); continue; } urls.add(classpathElement); completedPaths.add(bundlePath); } } }