Class Annotations

java.lang.Object
com.google.inject.internal.Annotations

public class Annotations extends Object
Annotation utilities.
  • Field Details

    • cache

      private static final com.google.common.cache.LoadingCache<Class<? extends Annotation>,Annotation> cache
    • JOINER

      private static final com.google.common.base.Joiner.MapJoiner JOINER
    • QUOTE_MEMBER_VALUES

      private static final boolean QUOTE_MEMBER_VALUES
    • scopeChecker

      private static final Annotations.AnnotationChecker scopeChecker
    • bindingAnnotationChecker

      private static final Annotations.AnnotationChecker bindingAnnotationChecker
  • Constructor Details

    • Annotations

      public Annotations()
  • Method Details

    • isMarker

      public static boolean isMarker(Class<? extends Annotation> annotationType)
      Returns true if the given annotation type has no attributes.
    • isAllDefaultMethods

      public static boolean isAllDefaultMethods(Class<? extends Annotation> annotationType)
    • generateAnnotation

      public static <T extends Annotation> T generateAnnotation(Class<T> annotationType)
      Generates an Annotation for the annotation class. Requires that the annotation is all optionals.
    • generateAnnotationImpl

      private static <T extends Annotation> T generateAnnotationImpl(Class<T> annotationType)
    • resolveMembers

      private static com.google.common.collect.ImmutableMap<String,Object> resolveMembers(Class<? extends Annotation> annotationType)
    • annotationEquals

      private static boolean annotationEquals(Class<? extends Annotation> type, Map<String,Object> members, Object other) throws Exception
      Throws:
      Exception
    • annotationHashCode

      private static int annotationHashCode(Class<? extends Annotation> type, Map<String,Object> members) throws Exception
      Throws:
      Exception
    • annotationToString

      private static String annotationToString(Class<? extends Annotation> type, Map<String,Object> members) throws Exception
      Throws:
      Exception
    • isRetainedAtRuntime

      public static boolean isRetainedAtRuntime(Class<? extends Annotation> annotationType)
      Returns true if the given annotation is retained at runtime.
    • findScopeAnnotation

      public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Class<?> implementation)
      Returns the scope annotation on type, or null if none is specified.
    • findScopeAnnotation

      public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations)
      Returns the scoping annotation, or null if there isn't one.
    • containsComponentAnnotation

      static boolean containsComponentAnnotation(Annotation[] annotations)
    • memberValueString

      public static String memberValueString(String value)
      Returns value, quoted if annotation implementations quote their member values. In Java 9, annotations quote their string members.
    • determineWhetherToQuote

      private static boolean determineWhetherToQuote()
    • isScopeAnnotation

      public static boolean isScopeAnnotation(Class<? extends Annotation> annotationType)
    • checkForMisplacedScopeAnnotations

      public static void checkForMisplacedScopeAnnotations(Class<?> type, Object source, Errors errors)
      Adds an error if there is a misplaced annotations on type. Scoping annotations are not allowed on abstract classes or interfaces.
    • getKey

      public static Key<?> getKey(TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors) throws ErrorsException
      Gets a key for the given type, member and annotations.
      Throws:
      ErrorsException
    • findBindingAnnotation

      public static Annotation findBindingAnnotation(Errors errors, Member member, Annotation[] annotations)
      Returns the binding annotation on member, or null if there isn't one.
    • isBindingAnnotation

      public static boolean isBindingAnnotation(Class<? extends Annotation> annotationType)
      Returns true if annotations of the specified type are binding annotations.
    • canonicalizeIfNamed

      public static Annotation canonicalizeIfNamed(Annotation annotation)
      If the annotation is an instance of javax.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation otherwise.
    • canonicalizeIfNamed

      public static Class<? extends Annotation> canonicalizeIfNamed(Class<? extends Annotation> annotationType)
      If the annotation is the class javax.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation class otherwise.
    • nameOf

      public static String nameOf(Key<?> key)
      Returns the name the binding should use. This is based on the annotation. If the annotation has an instance and is not a marker annotation, we ask the annotation for its toString. If it was a marker annotation or just an annotation type, we use the annotation's name. Otherwise, the name is the empty string.