private String getClassAnnotations(Class<?> clazz) { List<String> faultyAnnotations = Stream.of(clazz.getAnnotations()) .map(Annotation::annotationType) .filter(getAnnotations()::contains).map(Class::getSimpleName) .collect(Collectors.toList()); return String.join(", ", faultyAnnotations); } }
/** * Validate the correctness of the annotations returned by the * {@link #getAnnotations()} method applied to the {@code classSet}. * * @param classSet * the classes to validate */ protected void validateClasses(Collection<Class<?>> classSet) { if (classSet == null) { return; } List<String> offendingAnnotations = validateAnnotatedClasses(classSet); if (!offendingAnnotations.isEmpty()) { String message = ERROR_MESSAGE_BEGINNING + String.join("\n", offendingAnnotations); throw new InvalidApplicationConfigurationException(message); } }
private List<String> validateAnnotatedClasses( Collection<Class<?>> classSet) { List<String> offendingAnnotations = new ArrayList<>(); for (Class<?> clazz : classSet) { Route route = clazz.getAnnotation(Route.class); if (route != null) { if (!UI.class.equals(route.layout())) { offendingAnnotations.add(String.format(NON_PARENT, clazz.getName(), getClassAnnotations(clazz))); } RouteAlias routeAlias = clazz.getAnnotation(RouteAlias.class); if (routeAlias != null && !UI.class.equals(routeAlias.layout())) { offendingAnnotations.add(String.format(NON_PARENT_ALIAS, clazz.getName(), getClassAnnotations(clazz))); } } else if (!RouterLayout.class.isAssignableFrom(clazz)) { if (!Modifier.isAbstract(clazz.getModifiers())) { offendingAnnotations.add(String.format(NON_ROUTER_LAYOUT, clazz.getName(), getClassAnnotations(clazz))); } } else if (RouterLayout.class.isAssignableFrom(clazz) && clazz.getAnnotation(ParentLayout.class) != null) { offendingAnnotations.add(String.format(MIDDLE_ROUTER_LAYOUT, clazz.getName(), getClassAnnotations(clazz))); } } return offendingAnnotations; }