/** Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get( TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType) { return new Key<T>(typeLiteral, strategyFor(annotationType)); }
/** Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType) { return new Key<T>(type, strategyFor(annotationType)); }
/** Gets a key for an injection type and an annotation. */ public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Annotation annotation) { return new Key<T>(typeLiteral, strategyFor(annotation)); }
/** Gets a key for an injection type and an annotation. */ public static <T> Key<T> get(Class<T> type, Annotation annotation) { return new Key<T>(type, strategyFor(annotation)); }
/** Gets a key for an injection type and an annotation type. */ public static Key<?> get(Type type, Class<? extends Annotation> annotationType) { return new Key<Object>(type, strategyFor(annotationType)); }
/** Gets a key for an injection type and an annotation. */ public static Key<?> get(Type type, Annotation annotation) { return new Key<Object>(type, strategyFor(annotation)); }
/** * Constructs a new key. Derives the type from this class's type parameter. * * <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the * anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure. * * <p>Example usage for a binding of type {@code Foo} annotated with {@code @Bar}: * * <p>{@code new Key<Foo>(Bar.class) {}}. */ @SuppressWarnings("unchecked") protected Key(Class<? extends Annotation> annotationType) { this.annotationStrategy = strategyFor(annotationType); this.typeLiteral = MoreTypes.canonicalizeForKey( (TypeLiteral<T>) TypeLiteral.fromSuperclassTypeParameter(getClass())); this.hashCode = computeHashCode(); }
/** * Constructs a new key. Derives the type from this class's type parameter. * * <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the * anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure. * * <p>Example usage for a binding of type {@code Foo} annotated with {@code @Bar}: * * <p>{@code new Key<Foo>(new Bar()) {}}. */ @SuppressWarnings("unchecked") protected Key(Annotation annotation) { // no usages, not test-covered this.annotationStrategy = strategyFor(annotation); this.typeLiteral = MoreTypes.canonicalizeForKey( (TypeLiteral<T>) TypeLiteral.fromSuperclassTypeParameter(getClass())); this.hashCode = computeHashCode(); }
/** Gets the strategy for an annotation type. */ static AnnotationStrategy strategyFor(Class<? extends Annotation> annotationType) { annotationType = Annotations.canonicalizeIfNamed(annotationType); if (isAllDefaultMethods(annotationType)) { return strategyFor(generateAnnotation(annotationType)); } checkNotNull(annotationType, "annotation type"); ensureRetainedAtRuntime(annotationType); ensureIsBindingAnnotation(annotationType); return new AnnotationTypeStrategy(annotationType, null); }
/** * Gets a key for an injection type and an annotation. */ public static <T> Key<T> get(Class<T> type, Annotation annotation) { return new SimpleKey<T>(type, strategyFor(annotation)); }
/** * Gets a key for an injection type and an annotation type. */ public static Key<?> get(Type type, Class<? extends Annotation> annotationType) { return new SimpleKey<Object>(type, strategyFor(annotationType)); }
/** * Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType) { return new Key<T>(type, strategyFor(annotationType)); }
/** * Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType) { return new Key<T>(typeLiteral, strategyFor(annotationType)); }
/** * Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType) { return new Key<T>(type, strategyFor(annotationType)); }
/** * Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(Class<T> type, Class<? extends Annotation> annotationType) { return new SimpleKey<T>(type, strategyFor(annotationType)); }
/** * Gets a key for an injection type and an annotation. */ public static Key<?> get(Type type, Annotation annotation) { return new Key<Object>(type, strategyFor(annotation)); }
/** * Gets a key for an injection type and an annotation type. */ public static <T> Key<T> get(TypeLiteral<T> typeLiteral, Class<? extends Annotation> annotationType) { return new Key<T>(typeLiteral, strategyFor(annotationType)); }
public ConstantBindingBuilder annotatedWith(Annotation annotation) { Objects.nonNull(annotation, "annotation"); validateAnnotation(annotation.annotationType()); annotationStrategy = Key.strategyFor(annotation); return this; }
/** Gets the strategy for an annotation type. */ static AnnotationStrategy strategyFor(Class<? extends Annotation> annotationType) { annotationType = Annotations.canonicalizeIfNamed(annotationType); if (isAllDefaultMethods(annotationType)) { return strategyFor(generateAnnotation(annotationType)); } checkNotNull(annotationType, "annotation type"); ensureRetainedAtRuntime(annotationType); ensureIsBindingAnnotation(annotationType); return new AnnotationTypeStrategy(annotationType, null); }
/** Gets the strategy for an annotation type. */ static AnnotationStrategy strategyFor(Class<? extends Annotation> annotationType) { annotationType = Annotations.canonicalizeIfNamed(annotationType); if (isAllDefaultMethods(annotationType)) { return strategyFor(generateAnnotation(annotationType)); } checkNotNull(annotationType, "annotation type"); ensureRetainedAtRuntime(annotationType); ensureIsBindingAnnotation(annotationType); return new AnnotationTypeStrategy(annotationType, null); }