Package org.antlr.v4.runtime.misc
Class NullUsageProcessor
java.lang.Object
javax.annotation.processing.AbstractProcessor
org.antlr.v4.runtime.misc.NullUsageProcessor
- All Implemented Interfaces:
Processor
@SupportedAnnotationTypes({"org.antlr.v4.runtime.misc.NotNull","org.antlr.v4.runtime.misc.Nullable"})
public class NullUsageProcessor
extends AbstractProcessor
A compile-time validator for correct usage of the
NotNull and
Nullable annotations.
The validation process checks the following items.
- Error: an element is annotated with both
NotNullandNullable. - Error: an method which returns
voidis annotated withNotNullorNullable. - Error: an element with a primitive type is annotated with
Nullable. - Error: a parameter is annotated with
NotNull, but the method overrides or implements a method where the parameter is annotatedNullable. - Error: a method is annotated with
Nullable, but the method overrides or implements a method that is annotated withNotNull. - Warning: an element with a primitive type is annotated with
NotNull. - Warning: a parameter is annotated with
NotNull, but the method overrides or implements a method where the parameter is not annotated. - Warning: a method is annotated with
Nullable, but the method overrides or implements a method that is not annotated.
In the future, the validation process may be updated to check the following additional items.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate TypeElementstatic final Stringprivate TypeElementFields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddElementsToNamedMethodMap(Set<? extends Element> elements, Map<String, Map<ExecutableElement, List<Element>>> namedMethodMap) private booleancheckClassNameConstant(String className, Class<?> clazz) private booleanprivate voidcheckOverriddenMethod(ExecutableElement overrider, ExecutableElement overridden, Set<Element> errorElements, Set<Element> warnedElements) private voidprivate voidcheckPrimitiveTypeAnnotations(Set<? extends Element> elements, Diagnostic.Kind kind, TypeElement annotationType) private voidcheckVoidMethodAnnotations(Set<? extends Element> elements, TypeElement annotationType) private List<? extends TypeMirror>getAllSupertypes(TypeMirror type) private AnnotationMirrorgetAnnotationMirror(Element element, TypeElement annotationType) private AnnotationMirrorgetNotNullAnnotationMirror(Element element) private AnnotationMirrorgetNullableAnnotationMirror(Element element) private booleanprivate booleanisNullable(Element element) booleanprocess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, init, isInitialized
-
Field Details
-
NotNullClassName
- See Also:
-
NullableClassName
- See Also:
-
notNullType
-
nullableType
-
-
Constructor Details
-
NullUsageProcessor
public NullUsageProcessor()
-
-
Method Details
-
getSupportedSourceVersion
- Specified by:
getSupportedSourceVersionin interfaceProcessor- Overrides:
getSupportedSourceVersionin classAbstractProcessor
-
process
- Specified by:
processin interfaceProcessor- Specified by:
processin classAbstractProcessor
-
checkClassNameConstants
private boolean checkClassNameConstants() -
checkClassNameConstant
-
checkVoidMethodAnnotations
private void checkVoidMethodAnnotations(Set<? extends Element> elements, TypeElement annotationType) -
checkPrimitiveTypeAnnotations
private void checkPrimitiveTypeAnnotations(Set<? extends Element> elements, Diagnostic.Kind kind, TypeElement annotationType) -
addElementsToNamedMethodMap
-
checkOverriddenMethods
-
getAllSupertypes
-
checkOverriddenMethod
private void checkOverriddenMethod(ExecutableElement overrider, ExecutableElement overridden, Set<Element> errorElements, Set<Element> warnedElements) -
isNotNull
-
isNullable
-
getNotNullAnnotationMirror
-
getNullableAnnotationMirror
-
getAnnotationMirror
-