Package com.google.inject.internal
Class Annotations
java.lang.Object
com.google.inject.internal.Annotations
Annotation utilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Checks for the presence of annotations.private static class
private static @interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Annotations.AnnotationToStringConfig
private static final Annotations.AnnotationChecker
private static final com.google.common.cache.LoadingCache<Class<? extends Annotation>,
Annotation> private static final com.google.common.base.Joiner.MapJoiner
private static final Annotations.AnnotationChecker
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
annotationEquals
(Class<? extends Annotation> type, Map<String, Object> members, Object other) ImplementsAnnotation.equals(java.lang.Object)
.private static int
annotationHashCode
(Class<? extends Annotation> type, Map<String, Object> members) ImplementsAnnotation.hashCode()
.private static String
annotationToString
(Class<? extends Annotation> type, Map<String, Object> members) ImplementsAnnotation.toString()
.static Annotation
canonicalizeIfNamed
(Annotation annotation) If the annotation is an instance ofjavax.inject.Named
, canonicalizes to com.google.guice.name.Named.static Class<? extends Annotation>
canonicalizeIfNamed
(Class<? extends Annotation> annotationType) If the annotation is the classjavax.inject.Named
, canonicalizes to com.google.guice.name.Named.static void
checkForMisplacedScopeAnnotations
(Class<?> type, Object source, Errors errors) Adds an error if there is a misplaced annotations ontype
.(package private) static boolean
containsComponentAnnotation
(Annotation[] annotations) private static Annotations.AnnotationToStringConfig
static Annotation
findBindingAnnotation
(Errors errors, Member member, Annotation[] annotations) Returns the binding annotation onmember
, or null if there isn't one.static Class<? extends Annotation>
findScopeAnnotation
(Errors errors, Annotation[] annotations) Returns the scoping annotation, or null if there isn't one.static Class<? extends Annotation>
findScopeAnnotation
(Errors errors, Class<?> implementation) Returns the scope annotation ontype
, or null if none is specified.static <T extends Annotation>
TgenerateAnnotation
(Class<T> annotationType) Generates an Annotation for the annotation class.private static <T extends Annotation>
TgenerateAnnotationImpl
(Class<T> annotationType) static Key<?>
getKey
(TypeLiteral<?> type, Member member, Annotation[] annotations, Errors errors) Gets a key for the given type, member and annotations.static boolean
isAllDefaultMethods
(Class<? extends Annotation> annotationType) static boolean
isBindingAnnotation
(Class<? extends Annotation> annotationType) Returns true if annotations of the specified type are binding annotations.static boolean
isMarker
(Class<? extends Annotation> annotationType) Returnstrue
if the given annotation type has no attributes.static boolean
isRetainedAtRuntime
(Class<? extends Annotation> annotationType) Returns true if the given annotation is retained at runtime.static boolean
isScopeAnnotation
(Class<? extends Annotation> annotationType) static String
memberValueString
(String value) Returnsvalue
, quoted if annotation implementations quote their member values.static String
memberValueString
(String memberName, Object value) Returns string representation of the annotation memeber.static String
Returns the name the binding should use.resolveMembers
(Class<? extends Annotation> annotationType)
-
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 -
ANNOTATION_TO_STRING_CONFIG
-
scopeChecker
-
bindingAnnotationChecker
-
-
Constructor Details
-
Annotations
public Annotations()
-
-
Method Details
-
isMarker
Returnstrue
if the given annotation type has no attributes. -
isAllDefaultMethods
-
generateAnnotation
Generates an Annotation for the annotation class. Requires that the annotation is all optionals. -
generateAnnotationImpl
-
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 ExceptionImplementsAnnotation.equals(java.lang.Object)
.- Throws:
Exception
-
annotationHashCode
private static int annotationHashCode(Class<? extends Annotation> type, Map<String, Object> members) throws ExceptionImplementsAnnotation.hashCode()
.- Throws:
Exception
-
annotationToString
private static String annotationToString(Class<? extends Annotation> type, Map<String, Object> members) throws ExceptionImplementsAnnotation.toString()
.- Throws:
Exception
-
isRetainedAtRuntime
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 ontype
, 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
-
memberValueString
Returnsvalue
, quoted if annotation implementations quote their member values. In Java 9, annotations quote their string members. -
memberValueString
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.
-
determineAnnotationToStringConfig
-
isScopeAnnotation
-
checkForMisplacedScopeAnnotations
Adds an error if there is a misplaced annotations ontype
. 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 onmember
, or null if there isn't one. -
isBindingAnnotation
Returns true if annotations of the specified type are binding annotations. -
canonicalizeIfNamed
If the annotation is an instance ofjavax.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 classjavax.inject.Named
, canonicalizes to com.google.guice.name.Named. Returns the given annotation class otherwise. -
nameOf
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.
-