Class UnitsRelationsTools

java.lang.Object
org.checkerframework.checker.units.UnitsRelationsTools

public class UnitsRelationsTools extends Object
A helper class for UnitsRelations, providing numerous methods which help process Annotations and Annotated Types representing various units.
  • 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 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
    • 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 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
    • 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(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(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 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 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
    • removePrefix

      public 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.
      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
    • 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, 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
    • 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 Type
      unitsAnnotation - 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 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
    • 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 of Prefix.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