Class UnitsRelationsTools
- java.lang.Object
-
- org.checkerframework.checker.units.UnitsRelationsTools
-
public class UnitsRelationsTools extends java.lang.Object
A helper class for UnitsRelations, providing numerous methods which help process Annotations and Annotated Types representing various units.
-
-
Constructor Summary
Constructors Constructor Description UnitsRelationsTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable javax.lang.model.element.AnnotationMirror
buildAnnoMirrorWithDefaultPrefix(javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<? extends java.lang.annotation.Annotation> annoClass)
Creates an AnnotationMirror representing a unit defined by annoClass, with the default Prefix ofPrefix.one
.static @Nullable javax.lang.model.element.AnnotationMirror
buildAnnoMirrorWithNoPrefix(javax.annotation.processing.ProcessingEnvironment env, @FullyQualifiedName java.lang.CharSequence annoClass)
Creates an AnnotationMirror representing a unit defined by annoClass, with no prefix.static @Nullable javax.lang.model.element.AnnotationMirror
buildAnnoMirrorWithSpecificPrefix(javax.annotation.processing.ProcessingEnvironment env, @FullyQualifiedName java.lang.CharSequence annoClass, Prefix p)
Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.static @Nullable javax.lang.model.element.AnnotationMirror
buildAnnoMirrorWithSpecificPrefix(javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<? extends java.lang.annotation.Annotation> annoClass, Prefix p)
Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.static @Nullable Prefix
getPrefix(javax.lang.model.element.AnnotationMirror unitsAnnotation)
Retrieves the SI Prefix of an Annotation.static @Nullable Prefix
getPrefix(AnnotatedTypeMirror annoType)
Retrieves the SI Prefix of an Annotated Type.static boolean
hasNoPrefix(javax.lang.model.element.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, javax.lang.model.element.AnnotationMirror unitsAnnotation)
Checks to see if a particular Annotated Type has a specific unit (represented by its Annotation).static boolean
hasSpecificUnitIgnoringPrefix(AnnotatedTypeMirror annoType, javax.lang.model.element.AnnotationMirror unitsAnnotation)
Checks to see if a particular Annotated Type has a particular base unit (represented by its Annotation).static javax.lang.model.element.AnnotationMirror
removePrefix(javax.lang.model.util.Elements elements, javax.lang.model.element.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(javax.lang.model.util.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.
-
-
-
Method Detail
-
buildAnnoMirrorWithSpecificPrefix
public static @Nullable javax.lang.model.element.AnnotationMirror buildAnnoMirrorWithSpecificPrefix(javax.annotation.processing.ProcessingEnvironment env, @FullyQualifiedName java.lang.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 javax.lang.model.element.AnnotationMirror buildAnnoMirrorWithNoPrefix(javax.annotation.processing.ProcessingEnvironment env, @FullyQualifiedName java.lang.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
public static @Nullable Prefix getPrefix(AnnotatedTypeMirror annoType)
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
public static @Nullable Prefix getPrefix(javax.lang.model.element.AnnotationMirror unitsAnnotation)
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
public static boolean hasNoPrefix(AnnotatedTypeMirror annoType)
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
public static boolean hasNoPrefix(javax.lang.model.element.AnnotationMirror unitsAnnotation)
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 javax.lang.model.element.AnnotationMirror removePrefix(javax.lang.model.util.Elements elements, javax.lang.model.element.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
public static AnnotatedTypeMirror removePrefix(javax.lang.model.util.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.- 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
public static boolean hasNoUnits(AnnotatedTypeMirror annoType)
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, javax.lang.model.element.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, javax.lang.model.element.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 javax.lang.model.element.AnnotationMirror buildAnnoMirrorWithSpecificPrefix(javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<? extends java.lang.annotation.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 javax.lang.model.element.AnnotationMirror buildAnnoMirrorWithDefaultPrefix(javax.annotation.processing.ProcessingEnvironment env, java.lang.Class<? extends java.lang.annotation.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
-
-