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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic @Nullable AnnotationMirrorbuildAnnoMirrorWithDefaultPrefix(ProcessingEnvironment env, Class<? extends Annotation> annoClass) Creates an AnnotationMirror representing a unit defined by annoClass, with the default Prefix ofPrefix.one.static @Nullable AnnotationMirrorCreates an AnnotationMirror representing a unit defined by annoClass, with no prefix.static @Nullable AnnotationMirrorbuildAnnoMirrorWithSpecificPrefix(ProcessingEnvironment env, @FullyQualifiedName CharSequence annoClass, Prefix p) Creates an AnnotationMirror representing a unit defined by annoClass, with the specific Prefix p.static @Nullable AnnotationMirrorbuildAnnoMirrorWithSpecificPrefix(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 booleanhasNoPrefix(AnnotationMirror unitsAnnotation) Checks to see if an Annotation has no prefix (ie, no value element).static booleanhasNoPrefix(AnnotatedTypeMirror annoType) Checks to see if an Annotated Type has no prefix.static booleanhasNoUnits(AnnotatedTypeMirror annoType) Checks to see if a particular Annotated Type has no units, such as scalar constants in calculations.static booleanhasSpecificUnit(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a specific unit (represented by its Annotation).static booleanhasSpecificUnitIgnoringPrefix(AnnotatedTypeMirror annoType, AnnotationMirror unitsAnnotation) Checks to see if a particular Annotated Type has a particular base unit (represented by its Annotation).static AnnotationMirrorremovePrefix(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 AnnotatedTypeMirrorremovePrefix(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- 
UnitsRelationsToolspublic UnitsRelationsTools()
 
- 
- 
Method Details- 
buildAnnoMirrorWithSpecificPrefixpublic 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 implementation
- annoClass- 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
 
- 
buildAnnoMirrorWithNoPrefixpublic 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 implementation
- annoClass- 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
 
- 
getPrefixRetrieves 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
 
- 
getPrefixRetrieves 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
 
- 
hasNoPrefixChecks 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
 
- 
hasNoPrefixChecks 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
 
- 
removePrefixRemoves 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 implementation
- unitsAnnotation- an AnnotationMirror representing a Units Annotation
- Returns:
- the base SI Unit's AnnotationMirror, or null if the base SI Unit cannot be constructed
 
- 
removePrefixRemoves 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 implementation
- annoType- an AnnotatedTypeMirror representing a Units Annotated Type
- Returns:
- a copy of the Annotated Type without the prefix
 
- 
hasNoUnitsChecks 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
 
- 
hasSpecificUnitpublic 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 Type
- unitsAnnotation- an AnnotationMirror representing a Units Annotation of a specific unit
- Returns:
- true if the Type has the specific unit, false otherwise
 
- 
hasSpecificUnitIgnoringPrefixpublic 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 Type
- unitsAnnotation- an AnnotationMirror representing a Units Annotation of the base unit
- Returns:
- true if the Type has the specific unit, false otherwise
 
- 
buildAnnoMirrorWithSpecificPrefixpublic 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 implementation
- annoClass- 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
 
- 
buildAnnoMirrorWithDefaultPrefixpublic 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 implementation
- annoClass- 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
 
 
-