Class UnitsRelationsTools
java.lang.Object
org.checkerframework.checker.units.UnitsRelationsTools
A helper class for UnitsRelations, providing numerous methods which help process Annotations and
Annotated Types representing various units.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable AnnotationMirror
buildAnnoMirrorWithDefaultPrefix
(ProcessingEnvironment env, Class<? extends Annotation> annoClass) Creates an AnnotationMirror representing a unit defined by annoClass, with the default Prefix ofPrefix.one
.static @Nullable AnnotationMirror
Creates an AnnotationMirror representing a unit defined by annoClass, with no prefix.static @Nullable AnnotationMirror
buildAnnoMirrorWithSpecificPrefix
(ProcessingEnvironment env, @FullyQualifiedName CharSequence annoClass, Prefix p) Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.static @Nullable AnnotationMirror
buildAnnoMirrorWithSpecificPrefix
(ProcessingEnvironment env, Class<? extends Annotation> annoClass, Prefix p) Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.getPrefix
(AnnotationMirror unitsAnnotation) Retrieves the SI Prefix of an Annotation.getPrefix
(AnnotatedTypeMirror annoType) Retrieves the SI Prefix of an Annotated Type.static boolean
hasNoPrefix
(AnnotationMirror unitsAnnotation) Checks to see if an Annotation has no prefix (ie, no value element).static boolean
hasNoPrefix
(AnnotatedTypeMirror annoType) Checks to see if an Annotated Type has no prefix.static boolean
hasNoUnits
(AnnotatedTypeMirror annoType) Checks to see if a particular Annotated Type has no units, such as scalar constants in calculations.static boolean
hasSpecificUnit
(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a specific unit (represented by its Annotation).static boolean
hasSpecificUnitIgnoringPrefix
(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a particular base unit (represented by its Annotation).static @Nullable AnnotationMirror
removePrefix
(Elements elements, AnnotationMirror unitsAnnotation) Removes the prefix value from an Annotation, by constructing and returning a copy of its base SI unit's Annotation.static AnnotatedTypeMirror
removePrefix
(Elements elements, AnnotatedTypeMirror annoType) Removes the Prefix value from an Annotated Type, by constructing and returning a copy of the Annotated Type without the prefix.
-
Constructor Details
-
UnitsRelationsTools
public UnitsRelationsTools()
-
-
Method Details
-
buildAnnoMirrorWithSpecificPrefix
public static @Nullable AnnotationMirror buildAnnoMirrorWithSpecificPrefix(ProcessingEnvironment env, @FullyQualifiedName CharSequence annoClass, Prefix p) Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.- Parameters:
env
- the Checker Processing Environment, provided as a parameter in init() of a UnitsRelations implementationannoClass
- the fully-qualified name of an Annotation representing a Unit (eg m.class for meters)p
- a Prefix value- Returns:
- an AnnotationMirror of the Unit with the Prefix p, or null if it cannot be constructed
-
buildAnnoMirrorWithNoPrefix
public static @Nullable AnnotationMirror buildAnnoMirrorWithNoPrefix(ProcessingEnvironment env, @FullyQualifiedName CharSequence annoClass) Creates an AnnotationMirror representing a unit defined by annoClass, with no prefix.- Parameters:
env
- checker Processing Environment, provided as a parameter in init() of a UnitsRelations implementationannoClass
- the getElementValueClassname of an Annotation representing a Unit (eg m.class for meters)- Returns:
- an AnnotationMirror of the Unit with no prefix, or null if it cannot be constructed
-
getPrefix
Retrieves the SI Prefix of an Annotated Type.- Parameters:
annoType
- an AnnotatedTypeMirror representing a Units Annotated Type- Returns:
- a Prefix value (including Prefix.one), or null if it has none
-
getPrefix
Retrieves the SI Prefix of an Annotation.- Parameters:
unitsAnnotation
- an AnnotationMirror representing a Units Annotation- Returns:
- a Prefix value (including Prefix.one), or null if it has none
-
hasNoPrefix
Checks to see if an Annotated Type has no prefix.- Parameters:
annoType
- an AnnotatedTypeMirror representing a Units Annotated Type- Returns:
- true if it has no prefix, false otherwise
-
hasNoPrefix
Checks to see if an Annotation has no prefix (ie, no value element).- Parameters:
unitsAnnotation
- an AnnotationMirror representing a Units Annotation- Returns:
- true if it has no prefix, false otherwise
-
removePrefix
public static @Nullable AnnotationMirror removePrefix(Elements elements, AnnotationMirror unitsAnnotation) Removes the prefix value from an Annotation, by constructing and returning a copy of its base SI unit's Annotation.- Parameters:
elements
- the Element Utilities from a checker's processing environment, typically obtained by calling env.getElementUtils() in init() of a Units Relations implementationunitsAnnotation
- an AnnotationMirror representing a Units Annotation- Returns:
- the base SI Unit's AnnotationMirror, or null if the base SI Unit cannot be constructed
-
removePrefix
Removes the Prefix value from an Annotated Type, by constructing and returning a copy of the Annotated Type without the prefix.- Parameters:
elements
- the Element Utilities from a checker's processing environment, typically obtained by calling env.getElementUtils() in init() of a Units Relations implementationannoType
- an AnnotatedTypeMirror representing a Units Annotated Type- Returns:
- a copy of the Annotated Type without the prefix
-
hasNoUnits
Checks to see if a particular Annotated Type has no units, such as scalar constants in calculations.Any number that isn't assigned a unit will automatically get the Annotation UnknownUnits. eg: int x = 5; // x has @UnknownUnits
- Parameters:
annoType
- an AnnotatedTypeMirror representing a Units Annotated Type- Returns:
- true if the Type has no units, false otherwise
-
hasSpecificUnit
public static boolean hasSpecificUnit(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a specific unit (represented by its Annotation).- Parameters:
annoType
- an AnnotatedTypeMirror representing a Units Annotated TypeunitsAnnotation
- an AnnotationMirror representing a Units Annotation of a specific unit- Returns:
- true if the Type has the specific unit, false otherwise
-
hasSpecificUnitIgnoringPrefix
public static boolean hasSpecificUnitIgnoringPrefix(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a particular base unit (represented by its Annotation).- Parameters:
annoType
- an AnnotatedTypeMirror representing a Units Annotated TypeunitsAnnotation
- an AnnotationMirror representing a Units Annotation of the base unit- Returns:
- true if the Type has the specific unit, false otherwise
-
buildAnnoMirrorWithSpecificPrefix
public static @Nullable AnnotationMirror buildAnnoMirrorWithSpecificPrefix(ProcessingEnvironment env, Class<? extends Annotation> annoClass, Prefix p) Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.This interface is intended only for subclasses of UnitsRelations; other clients should use
buildAnnoMirrorWithSpecificPrefix(ProcessingEnvironment, CharSequence, Prefix)
- Parameters:
env
- the Checker Processing Environment, provided as a parameter in init() of a UnitsRelations implementationannoClass
- the Class of an Annotation representing a Unit (eg m.class for meters)p
- a Prefix value- Returns:
- an AnnotationMirror of the Unit with the Prefix p, or null if it cannot be constructed
-
buildAnnoMirrorWithDefaultPrefix
public static @Nullable AnnotationMirror buildAnnoMirrorWithDefaultPrefix(ProcessingEnvironment env, Class<? extends Annotation> annoClass) Creates an AnnotationMirror representing a unit defined by annoClass, with the default Prefix ofPrefix.one
.This interface is intended only for subclasses of UnitsRelations; other clients should not use it.
- Parameters:
env
- the Checker Processing Environment, provided as a parameter in init() of a UnitsRelations implementationannoClass
- the Class of an Annotation representing a Unit (eg m.class for meters)- Returns:
- an AnnotationMirror of the Unit with Prefix.one, or null if it cannot be constructed
-