Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.google.inject;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.inject.internal.Annotations;
import com.google.inject.internal.MoreTypes;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.inject.internal.Annotations.generateAnnotation;
import static com.google.inject.internal.Annotations.isAllDefaultMethods;
/**
* Binding key consisting of an injection type and an optional annotation.
* Matches the type and annotation at a point of injection.
*
*
For example, {@code Key.get(Service.class, Transactional.class)} will
* match:
*
*
* {@literal @}Inject
* public void setService({@literal @}Transactional Service service) {
* ...
* }
*
*
*
{@code Key} supports generic types via subclassing just like {@link
* TypeLiteral}.
*
*
Keys do not differentiate between primitive types (int, char, etc.) and
* their corresponding wrapper types (Integer, Character, etc.). Primitive
* types will be replaced with their wrapper types when keys are created.
*/
public class Key {
private final AnnotationStrategy annotationStrategy;
private final TypeLiteral typeLiteral;
private final int hashCode;
// This field is updated using the 'Data-Race-Ful' lazy intialization pattern
// See http://jeremymanson.blogspot.com/2008/12/benign-data-races-in-java.html for a detailed
// explanation.
private String toString;
/**
* Constructs a new key. Derives the type from this class's type parameter.
*
*
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.
*
*
Example usage for a binding of type {@code Foo} annotated with
* {@code @Bar}:
*
*
{@code new Key(Bar.class) {}}.
*/
@SuppressWarnings("unchecked")
protected Key(Class extends Annotation> annotationType) {
this.annotationStrategy = strategyFor(annotationType);
this.typeLiteral = MoreTypes.canonicalizeForKey(
(TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()));
this.hashCode = computeHashCode();
}
/**
* Constructs a new key. Derives the type from this class's type parameter.
*
*
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.
*
*
Example usage for a binding of type {@code Foo} annotated with
* {@code @Bar}:
*
*
{@code new Key(new Bar()) {}}.
*/
@SuppressWarnings("unchecked")
protected Key(Annotation annotation) {
// no usages, not test-covered
this.annotationStrategy = strategyFor(annotation);
this.typeLiteral = MoreTypes.canonicalizeForKey(
(TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()));
this.hashCode = computeHashCode();
}
/**
* Constructs a new key. Derives the type from this class's type parameter.
*
*
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.
*
*
Example usage for a binding of type {@code Foo}:
*
*
{@code new Key() {}}.
*/
@SuppressWarnings("unchecked")
protected Key() {
this.annotationStrategy = NullAnnotationStrategy.INSTANCE;
this.typeLiteral = MoreTypes.canonicalizeForKey(
(TypeLiteral) TypeLiteral.fromSuperclassTypeParameter(getClass()));
this.hashCode = computeHashCode();
}
/**
* Unsafe. Constructs a key from a manually specified type.
*/
@SuppressWarnings("unchecked")
private Key(Type type, AnnotationStrategy annotationStrategy) {
this.annotationStrategy = annotationStrategy;
this.typeLiteral = MoreTypes.canonicalizeForKey((TypeLiteral) TypeLiteral.get(type));
this.hashCode = computeHashCode();
}
/**
* Constructs a key from a manually specified type.
*/
private Key(TypeLiteral typeLiteral, AnnotationStrategy annotationStrategy) {
this.annotationStrategy = annotationStrategy;
this.typeLiteral = MoreTypes.canonicalizeForKey(typeLiteral);
this.hashCode = computeHashCode();
}
/**
* Gets a key for an injection type and an annotation strategy.
*/
static Key get(Class type, AnnotationStrategy annotationStrategy) {
return new Key(type, annotationStrategy);
}
/**
* Gets a key for an injection type.
*/
public static Key get(Class type) {
return new Key(type, NullAnnotationStrategy.INSTANCE);
}
/**
* Gets a key for an injection type and an annotation type.
*/
public static Key get(Class type, Class extends Annotation> annotationType) {
return new Key(type, strategyFor(annotationType));
}
/**
* Gets a key for an injection type and an annotation.
*/
public static Key get(Class type, Annotation annotation) {
return new Key(type, strategyFor(annotation));
}
/**
* Gets a key for an injection type.
*/
public static Key> get(Type type) {
return new Key