Top Description Inners Fields Constructors Methods
com.google.inject.internal

public Class Annotations

extends Object
Class Inheritance
Static Imports
java.lang.annotation.RetentionPolicy.RUNTIME

Annotation utilities.
Author
[email protected] (Bob Lee)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Annotations.AnnotationChecker

Checks for the presence of annotations.

private static class
private static @interface

Field Summary

Modifier and TypeField and Description
private static final Annotations.AnnotationToStringConfig
private static final Annotations.AnnotationChecker
private static final LoadingCache<Class<? extends Annotation>, Annotation>
private static final Joiner.MapJoiner
private static final Annotations.AnnotationChecker

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
annotationEquals(Class<? extends Annotation> type, Map<String, Object> members, Object other)

Implements Annotation#equals.

private static int
annotationHashCode(Class<? extends Annotation> type, Map<String, Object> members)

Implements Annotation#hashCode.

public static String
annotationInstanceClassString(Class<? extends Annotation> ann, boolean includePackage)

Returns the string representation of the annotation class as it would appear in an annotation instance's toString() method.

private static String
annotationToString(Class<? extends Annotation> type, Map<String, Object> members)

Implements Annotation#toString.

public static Annotation
canonicalizeIfNamed(Annotation annotation)

If the annotation is an instance of jakarta.inject.Named, canonicalizes to com.google.guice.name.Named.

public static Class<? extends Annotation>
canonicalizeIfNamed(Class<? extends Annotation> annotationType)

If the annotation is the class jakarta.inject.Named, canonicalizes to com.google.guice.name.Named.

public static void
checkForMisplacedScopeAnnotations(Class<?> type, Object source, Errors errors)

Adds an error if there is a misplaced annotations on type.

pack-priv static boolean
private static Annotations.AnnotationToStringConfig
private static String
dotSeparatedParentOrPackage(Class<?> ann, boolean includePackage)

public static Annotation
findBindingAnnotation(Errors errors, Member member, Annotation[] annotations)

Returns the binding annotation on member, or null if there isn't one.

public static Class<? extends Annotation>
findScopeAnnotation(Errors errors, Class<?> implementation)

Returns the scope annotation on type, or null if none is specified.

public static Class<? extends Annotation>
findScopeAnnotation(Errors errors, Annotation[] annotations)

Returns the scoping annotation, or null if there isn't one.

public static <T extends Annotation> T
generateAnnotation(Class<T> annotationType)

Generates an Annotation for the annotation class.

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

public static Key<?>
getKey(TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors)

Gets a key for the given type, member and annotations.

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

public static boolean
isBindingAnnotation(Class<? extends Annotation> annotationType)

Returns true if annotations of the specified type are binding annotations.

public static boolean
isMarker(Class<? extends Annotation> annotationType)

Returns true if the given annotation type has no attributes.

public static boolean
isRetainedAtRuntime(Class<? extends Annotation> annotationType)

Returns true if the given annotation is retained at runtime.

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

public static String
memberValueString(String value)

Returns value, quoted if annotation implementations quote their member values.

public static String
memberValueString(String memberName, Object value)

Returns string representation of the annotation memeber.

public static String
nameOf(Key<?> key)

Returns the name the binding should use.

private static ImmutableMap<String, Object>
resolveMembers(Class<? extends Annotation> annotationType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANNOTATION_TO_STRING_CONFIGback to summary
private static final Annotations.AnnotationToStringConfig ANNOTATION_TO_STRING_CONFIG
bindingAnnotationCheckerback to summary
private static final Annotations.AnnotationChecker bindingAnnotationChecker
cacheback to summary
private static final LoadingCache<Class<? extends Annotation>, Annotation> cache
JOINERback to summary
private static final Joiner.MapJoiner JOINER
scopeCheckerback to summary
private static final Annotations.AnnotationChecker scopeChecker

Constructor Detail

Annotationsback to summary
public Annotations()

Method Detail

annotationEqualsback to summary
private static boolean annotationEquals(Class<? extends Annotation> type, Map<String, Object> members, Object other) throws Exception

Implements Annotation#equals.

annotationHashCodeback to summary
private static int annotationHashCode(Class<? extends Annotation> type, Map<String, Object> members) throws Exception

Implements Annotation#hashCode.

annotationInstanceClassStringback to summary
public static String annotationInstanceClassString(Class<? extends Annotation> ann, boolean includePackage)

Returns the string representation of the annotation class as it would appear in an annotation instance's toString() method.

In earlier JDKs, the string representation mirrored Class.getName() (which uses $ to separate outer and inner classes), but newer JDKs use . as the separator).

annotationToStringback to summary
private static String annotationToString(Class<? extends Annotation> type, Map<String, Object> members) throws Exception

Implements Annotation#toString.

canonicalizeIfNamedback to summary
public static Annotation canonicalizeIfNamed(Annotation annotation)

If the annotation is an instance of jakarta.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation otherwise.

canonicalizeIfNamedback to summary
public static Class<? extends Annotation> canonicalizeIfNamed(Class<? extends Annotation> annotationType)

If the annotation is the class jakarta.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation class otherwise.

checkForMisplacedScopeAnnotationsback to summary
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.

containsComponentAnnotationback to summary
pack-priv static boolean containsComponentAnnotation(Annotation[] annotations)
determineAnnotationToStringConfigback to summary
private static Annotations.AnnotationToStringConfig determineAnnotationToStringConfig()
Annotations
@TestAnnotation:determineAnnotationToStringConfig
dotSeparatedParentOrPackageback to summary
private static String dotSeparatedParentOrPackage(Class<?> ann, boolean includePackage)
findBindingAnnotationback to summary
public static Annotation findBindingAnnotation(Errors errors, Member member, Annotation[] annotations)

Returns the binding annotation on member, or null if there isn't one.

findScopeAnnotationback to summary
public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Class<?> implementation)

Returns the scope annotation on type, or null if none is specified.

findScopeAnnotationback to summary
public static Class<? extends Annotation> findScopeAnnotation(Errors errors, Annotation[] annotations)

Returns the scoping annotation, or null if there isn't one.

generateAnnotationback to summary
public static <T extends Annotation> T generateAnnotation(Class<T> annotationType)

Generates an Annotation for the annotation class. Requires that the annotation is all optionals.

Annotations
@SuppressWarnings:unchecked
generateAnnotationImplback to summary
private static <T extends Annotation> T generateAnnotationImpl(final Class<T> annotationType)
getKeyback to summary
public static Key<?> getKey(TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors) throws ErrorsException

Gets a key for the given type, member and annotations.

isAllDefaultMethodsback to summary
public static boolean isAllDefaultMethods(Class<? extends Annotation> annotationType)
isBindingAnnotationback to summary
public static boolean isBindingAnnotation(Class<? extends Annotation> annotationType)

Returns true if annotations of the specified type are binding annotations.

isMarkerback to summary
public static boolean isMarker(Class<? extends Annotation> annotationType)

Returns true if the given annotation type has no attributes.

isRetainedAtRuntimeback to summary
public static boolean isRetainedAtRuntime(Class<? extends Annotation> annotationType)

Returns true if the given annotation is retained at runtime.

isScopeAnnotationback to summary
public static boolean isScopeAnnotation(Class<? extends Annotation> annotationType)
memberValueStringback to summary
public static String memberValueString(String value)

Returns value, quoted if annotation implementations quote their member values. In Java 9, annotations quote their string members.

memberValueStringback to summary
public static String memberValueString(String memberName, Object value)

Returns string representation of the annotation memeber.

The value of the member is prefixed with `memberName=` unless the runtime omits the member name. The value of the member is quoted if annotation implementations quote their member values and the value type is String.

In Java 9, annotations quote their string members and in Java 15, the member name is omitted.

nameOfback to summary
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.

resolveMembersback to summary
private static ImmutableMap<String, Object> resolveMembers(Class<? extends Annotation> annotationType)
com.google.inject.internal back to summary

pack-priv Class Annotations.AnnotationChecker

extends Object
Class Inheritance

Checks for the presence of annotations. Caches results because Android doesn't.

Field Summary

Modifier and TypeField and Description
private final Collection<Class<? extends Annotation>>
pack-priv final LoadingCache<Class<? extends Annotation>, Boolean>
private CacheLoader<Class<? extends Annotation>, Boolean>
hasAnnotations

Returns true if the given class has one of the desired annotations.

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationChecker(Collection<Class<? extends Annotation>> annotationTypes)

Constructs a new checker that looks for annotations of the given types.

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
hasAnnotations(Class<? extends Annotation> annotated)

Returns true if the given type has one of the desired annotations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationTypesback to summary
private final Collection<Class<? extends Annotation>> annotationTypes
cacheback to summary
pack-priv final LoadingCache<Class<? extends Annotation>, Boolean> cache
hasAnnotationsback to summary
private CacheLoader<Class<? extends Annotation>, Boolean> hasAnnotations

Returns true if the given class has one of the desired annotations.

Constructor Detail

AnnotationCheckerback to summary
pack-priv AnnotationChecker(Collection<Class<? extends Annotation>> annotationTypes)

Constructs a new checker that looks for annotations of the given types.

Method Detail

hasAnnotationsback to summary
pack-priv boolean hasAnnotations(Class<? extends Annotation> annotated)

Returns true if the given type has one of the desired annotations.

com.google.inject.internal back to summary

private Class Annotations.AnnotationToStringConfig

extends Object
Class Inheritance
  • java.lang.Object
  • com.google.inject.internal.Annotations.AnnotationToStringConfig

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final boolean
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationToStringConfig(boolean quote, boolean includeMemberName, boolean dollarSeparator)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dollarSeparatorback to summary
pack-priv final boolean dollarSeparator
includeMemberNameback to summary
pack-priv final boolean includeMemberName
quoteback to summary
pack-priv final boolean quote

Constructor Detail

AnnotationToStringConfigback to summary
pack-priv AnnotationToStringConfig(boolean quote, boolean includeMemberName, boolean dollarSeparator)
com.google.inject.internal back to summary

private @Interface Annotations.TestAnnotation

extends Annotation
Annotations
@Retention:RUNTIME

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()