Record Class Restriction

java.lang.Object
java.lang.Record
com.google.errorprone.bugpatterns.restrictedapi.Restriction

public record Restriction(String explanation, String link, com.google.common.collect.ImmutableList<String> allowedPaths, String allowedOnPath, com.google.common.collect.ImmutableList<TypeMirror> allowlistAnnotations, Optional<TypeMirror> suggestedAllowlistAnnotation, boolean allowedInTestonlyTargets, boolean warningOnlyForRefactoring) extends Record
Details of a restriction declared via an annotation like @RestrictedApi.
  • Constructor Details

    • Restriction

      public Restriction(String explanation, String link, com.google.common.collect.ImmutableList<String> allowedPaths, String allowedOnPath, com.google.common.collect.ImmutableList<TypeMirror> allowlistAnnotations, Optional<TypeMirror> suggestedAllowlistAnnotation, boolean allowedInTestonlyTargets, boolean warningOnlyForRefactoring)
      Creates an instance of a Restriction record class.
      Parameters:
      explanation - the value for the explanation record component
      link - the value for the link record component
      allowedPaths - the value for the allowedPaths record component
      allowedOnPath - the value for the allowedOnPath record component
      allowlistAnnotations - the value for the allowlistAnnotations record component
      suggestedAllowlistAnnotation - the value for the suggestedAllowlistAnnotation record component
      allowedInTestonlyTargets - the value for the allowedInTestonlyTargets record component
      warningOnlyForRefactoring - the value for the warningOnlyForRefactoring record component
  • Method Details

    • validateAnnotation

      public static Optional<String> validateAnnotation(AnnotationMirror attribute, com.sun.tools.javac.code.Symbol annotationSymbol)
      Validates path restrictions on an annotation, returning an error message if both allowedPaths and allowedOnPath are specified.
    • from

      public static Optional<Restriction> from(AnnotationMirror attribute)
      Parses a Restriction from an AnnotationMirror.
    • isPathOrTestonlyExempt

      public boolean isPathOrTestonlyExempt(Tree where, VisitorState state)
      Returns true if usage at where is exempt by path or test-only target rules.
    • isAllowlisted

      public boolean isAllowlisted(Tree where, VisitorState state)
      Returns true if usage at where is permitted by an allowlist annotation.
    • isAllowed

      public boolean isAllowed(Tree where, VisitorState state)
      Returns true if usage at where is exempt by path, test-only target, or allowlist.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • explanation

      public String explanation()
      Returns the value of the explanation record component.
      Returns:
      the value of the explanation record component
    • link

      public String link()
      Returns the value of the link record component.
      Returns:
      the value of the link record component
    • allowedPaths

      public com.google.common.collect.ImmutableList<String> allowedPaths()
      Returns the value of the allowedPaths record component.
      Returns:
      the value of the allowedPaths record component
    • allowedOnPath

      public String allowedOnPath()
      Returns the value of the allowedOnPath record component.
      Returns:
      the value of the allowedOnPath record component
    • allowlistAnnotations

      public com.google.common.collect.ImmutableList<TypeMirror> allowlistAnnotations()
      Returns the value of the allowlistAnnotations record component.
      Returns:
      the value of the allowlistAnnotations record component
    • suggestedAllowlistAnnotation

      public Optional<TypeMirror> suggestedAllowlistAnnotation()
      Returns the value of the suggestedAllowlistAnnotation record component.
      Returns:
      the value of the suggestedAllowlistAnnotation record component
    • allowedInTestonlyTargets

      public boolean allowedInTestonlyTargets()
      Returns the value of the allowedInTestonlyTargets record component.
      Returns:
      the value of the allowedInTestonlyTargets record component
    • warningOnlyForRefactoring

      public boolean warningOnlyForRefactoring()
      Returns the value of the warningOnlyForRefactoring record component.
      Returns:
      the value of the warningOnlyForRefactoring record component