Package com.google.inject.internal
Class Annotations
- java.lang.Object
-
- com.google.inject.internal.Annotations
-
public class Annotations extends java.lang.ObjectAnnotation utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAnnotations.AnnotationCheckerChecks for the presence of annotations.private static classAnnotations.AnnotationToStringConfigprivate static interfaceAnnotations.TestAnnotation
-
Field Summary
Fields Modifier and Type Field Description private static Annotations.AnnotationToStringConfigANNOTATION_TO_STRING_CONFIGprivate static Annotations.AnnotationCheckerbindingAnnotationCheckerprivate static com.google.common.cache.LoadingCache<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation>cacheprivate static com.google.common.base.Joiner.MapJoinerJOINERprivate static Annotations.AnnotationCheckerscopeChecker
-
Constructor Summary
Constructors Constructor Description Annotations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanannotationEquals(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members, java.lang.Object other)ImplementsAnnotation.equals(java.lang.Object).private static intannotationHashCode(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members)ImplementsAnnotation.hashCode().private static java.lang.StringannotationToString(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members)ImplementsAnnotation.toString().static java.lang.annotation.AnnotationcanonicalizeIfNamed(java.lang.annotation.Annotation annotation)If the annotation is an instance ofjavax.inject.Named, canonicalizes to com.google.guice.name.Named.static java.lang.Class<? extends java.lang.annotation.Annotation>canonicalizeIfNamed(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)If the annotation is the classjavax.inject.Named, canonicalizes to com.google.guice.name.Named.static voidcheckForMisplacedScopeAnnotations(java.lang.Class<?> type, java.lang.Object source, Errors errors)Adds an error if there is a misplaced annotations ontype.(package private) static booleancontainsComponentAnnotation(java.lang.annotation.Annotation[] annotations)private static Annotations.AnnotationToStringConfigdetermineAnnotationToStringConfig()static java.lang.annotation.AnnotationfindBindingAnnotation(Errors errors, java.lang.reflect.Member member, java.lang.annotation.Annotation[] annotations)Returns the binding annotation onmember, or null if there isn't one.static java.lang.Class<? extends java.lang.annotation.Annotation>findScopeAnnotation(Errors errors, java.lang.annotation.Annotation[] annotations)Returns the scoping annotation, or null if there isn't one.static java.lang.Class<? extends java.lang.annotation.Annotation>findScopeAnnotation(Errors errors, java.lang.Class<?> implementation)Returns the scope annotation ontype, or null if none is specified.static <T extends java.lang.annotation.Annotation>
TgenerateAnnotation(java.lang.Class<T> annotationType)Generates an Annotation for the annotation class.private static <T extends java.lang.annotation.Annotation>
TgenerateAnnotationImpl(java.lang.Class<T> annotationType)static Key<?>getKey(TypeLiteral<?> type, java.lang.reflect.Member member, java.lang.annotation.Annotation[] annotations, Errors errors)Gets a key for the given type, member and annotations.static booleanisAllDefaultMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static booleanisBindingAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns true if annotations of the specified type are binding annotations.static booleanisMarker(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returnstrueif the given annotation type has no attributes.static booleanisRetainedAtRuntime(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns true if the given annotation is retained at runtime.static booleanisScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)static java.lang.StringmemberValueString(java.lang.String value)Returnsvalue, quoted if annotation implementations quote their member values.static java.lang.StringmemberValueString(java.lang.String memberName, java.lang.Object value)Returns string representation of the annotation memeber.static java.lang.StringnameOf(Key<?> key)Returns the name the binding should use.private static com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Object>resolveMembers(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
-
-
Field Detail
-
cache
private static final com.google.common.cache.LoadingCache<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.annotation.Annotation> cache
-
JOINER
private static final com.google.common.base.Joiner.MapJoiner JOINER
-
ANNOTATION_TO_STRING_CONFIG
private static final Annotations.AnnotationToStringConfig ANNOTATION_TO_STRING_CONFIG
-
scopeChecker
private static final Annotations.AnnotationChecker scopeChecker
-
bindingAnnotationChecker
private static final Annotations.AnnotationChecker bindingAnnotationChecker
-
-
Method Detail
-
isMarker
public static boolean isMarker(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returnstrueif the given annotation type has no attributes.
-
isAllDefaultMethods
public static boolean isAllDefaultMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
generateAnnotation
public static <T extends java.lang.annotation.Annotation> T generateAnnotation(java.lang.Class<T> annotationType)
Generates an Annotation for the annotation class. Requires that the annotation is all optionals.
-
generateAnnotationImpl
private static <T extends java.lang.annotation.Annotation> T generateAnnotationImpl(java.lang.Class<T> annotationType)
-
resolveMembers
private static com.google.common.collect.ImmutableMap<java.lang.String,java.lang.Object> resolveMembers(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
annotationEquals
private static boolean annotationEquals(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members, java.lang.Object other) throws java.lang.ExceptionImplementsAnnotation.equals(java.lang.Object).- Throws:
java.lang.Exception
-
annotationHashCode
private static int annotationHashCode(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members) throws java.lang.ExceptionImplementsAnnotation.hashCode().- Throws:
java.lang.Exception
-
annotationToString
private static java.lang.String annotationToString(java.lang.Class<? extends java.lang.annotation.Annotation> type, java.util.Map<java.lang.String,java.lang.Object> members) throws java.lang.ExceptionImplementsAnnotation.toString().- Throws:
java.lang.Exception
-
isRetainedAtRuntime
public static boolean isRetainedAtRuntime(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if the given annotation is retained at runtime.
-
findScopeAnnotation
public static java.lang.Class<? extends java.lang.annotation.Annotation> findScopeAnnotation(Errors errors, java.lang.Class<?> implementation)
Returns the scope annotation ontype, or null if none is specified.
-
findScopeAnnotation
public static java.lang.Class<? extends java.lang.annotation.Annotation> findScopeAnnotation(Errors errors, java.lang.annotation.Annotation[] annotations)
Returns the scoping annotation, or null if there isn't one.
-
containsComponentAnnotation
static boolean containsComponentAnnotation(java.lang.annotation.Annotation[] annotations)
-
memberValueString
public static java.lang.String memberValueString(java.lang.String value)
Returnsvalue, quoted if annotation implementations quote their member values. In Java 9, annotations quote their string members.
-
memberValueString
public static java.lang.String memberValueString(java.lang.String memberName, java.lang.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.
-
determineAnnotationToStringConfig
private static Annotations.AnnotationToStringConfig determineAnnotationToStringConfig()
-
isScopeAnnotation
public static boolean isScopeAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
-
checkForMisplacedScopeAnnotations
public static void checkForMisplacedScopeAnnotations(java.lang.Class<?> type, java.lang.Object source, Errors errors)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, java.lang.reflect.Member member, java.lang.annotation.Annotation[] annotations, Errors errors) throws ErrorsException
Gets a key for the given type, member and annotations.- Throws:
ErrorsException
-
findBindingAnnotation
public static java.lang.annotation.Annotation findBindingAnnotation(Errors errors, java.lang.reflect.Member member, java.lang.annotation.Annotation[] annotations)
Returns the binding annotation onmember, or null if there isn't one.
-
isBindingAnnotation
public static boolean isBindingAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true if annotations of the specified type are binding annotations.
-
canonicalizeIfNamed
public static java.lang.annotation.Annotation canonicalizeIfNamed(java.lang.annotation.Annotation annotation)
If the annotation is an instance ofjavax.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation otherwise.
-
canonicalizeIfNamed
public static java.lang.Class<? extends java.lang.annotation.Annotation> canonicalizeIfNamed(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
If the annotation is the classjavax.inject.Named, canonicalizes to com.google.guice.name.Named. Returns the given annotation class otherwise.
-
nameOf
public static java.lang.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.
-
-