/** * Check to make sure there is only one factory class referenced. * * @param factoryTypeMirror the {@link TypeMirror} of the {@link ValidatorFactory}. * @param type the {@link TypeElement} of the class that referenced the {@link ValidatorFactory}. */ private void checkFactoryClass(TypeMirror factoryTypeMirror, TypeElement type) { if (seenFactoryTypeMirror == null) { seenFactoryTypeMirror = factoryTypeMirror; return; } if (!types.isSameType(factoryTypeMirror, seenFactoryTypeMirror)) { String errorMsg = "More than one factory class referenced by models " + seenFactoryTypeMirror.toString() + " and " + factoryTypeMirror.toString(); abortWithError(errorMsg, type); } }
/** * Verify that the annotations on methods in a model are not conflicting. * * @param typeElement the {@link TypeElement} of the model being verified. */ private void verifyAnnotationConflicts(TypeElement typeElement) { List<String> annotationList = new LinkedList<>(); List<ExecutableElement> methodElements = new ImmutableList.Builder<ExecutableElement>() .addAll(ElementFilter.methodsIn(typeElement.getEnclosedElements())).build(); for (ExecutableElement executableElement : methodElements) { annotationList.clear(); for (AnnotationMirror mirror : elements.getAllAnnotationMirrors(executableElement)) { String annotationName = mirror.getAnnotationType().toString(); if (CompilerUtils.isSupportedAnnotation(mirror.getAnnotationType().toString())) { for (String a : annotationList) { if (CompilerUtils.areConflicting(a, annotationName)) { abortWithError("Annotations " + annotationName + " cannot be used with " + a, typeElement); } } annotationList.add(annotationName); } } } }
if (size != null) { if (size.multiple() < 1) { abortWithError("Multiple value is less than 1 with value:" + size.multiple() + " on method " + executableElement.getSimpleName(), type); TypeKind kind = executableElement.getReturnType().getKind(); if (!(kind == TypeKind.FLOAT || kind == TypeKind.DOUBLE)) { abortWithError(executableElement.getSimpleName().toString() + FLOAT_RANGE_BAD_RETURN_TYPE_ERROR, type); TypeKind kind = executableElement.getReturnType().getKind(); if (!(kind == TypeKind.INT || kind == TypeKind.LONG)) { abortWithError(executableElement.getSimpleName().toString() + INT_RANGE_BAD_RETURN_TYPE_ERROR, type); TypeKind kind = executableElement.getReturnType().getKind(); if (annotation != null && !(kind == TypeKind.INT)) { abortWithError(executableElement.getSimpleName().toString() + INTDEF_BAD_RETURN_TYPE_ERROR, type); TypeKind kind = executableElement.getReturnType().getKind(); if (annotation != null && !(kind == TypeKind.LONG)) { abortWithError(executableElement.getSimpleName().toString() + LONGDEF_BAD_RETURN_TYPE_ERROR, type);
Validated validatedAnnotation = type.getAnnotation(Validated.class); if (validatedAnnotation == null) { abortWithError("Annotation processor for @" + Validated.class.getSimpleName() + " was invoked with a type that does not have the annotation.", type); return; abortWithError("Class is private. It must be at least package private", type); abortWithError(type.getSimpleName() + " is not visible to " + factoryMirror.toString(), type); abortWithError("@" + Validated.class.getSimpleName() + " may not be used to implement an " + "annotation interface.", type);