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

pack-priv Class Indexer

extends DefaultBindingTargetVisitor<Object, Indexer.IndexedBinding>
implements BindingScopingVisitor<Object>
Class Inheritance
All Implemented Interfaces
com.google.inject.spi.BindingScopingVisitor
Imports
com.google.common.base.Objects, com.google.inject.Binding, .Injector, .Scope, .Scopes, .TypeLiteral, com.google.inject.spi.BindingScopingVisitor, .ConstructorBinding, .ConvertedConstantBinding, .DefaultBindingTargetVisitor, .ExposedBinding, .InstanceBinding, .LinkedKeyBinding, .ProviderBinding, .ProviderInstanceBinding, .ProviderKeyBinding, .UntargettedBinding, java.lang.annotation.Annotation

Visits bindings to return a IndexedBinding that can be used to emulate the binding deduplication that Guice internally performs.

Note

simply using equals/hashCode on the BindingImpls doesn't work because they all have unique annotations. This works around that by reimplementing equality semantics that ignores Element#uniqueId(). A better solution might be to introduce the idea of an 'anonymous' binding to guice, that might support this usecase directly.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final Object
pack-priv final Injector

Constructor Summary

AccessConstructor and Description
pack-priv
Indexer(Injector injector)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
isIndexable(Binding<?> binding)

private Object
scope(Binding<?> binding)

public Indexer.IndexedBinding
public Indexer.IndexedBinding
visit(ConvertedConstantBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding created from converting a bound instance to a new type.
public Indexer.IndexedBinding
visit(ExposedBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding to a key exposed from an enclosed private environment.
public Indexer.IndexedBinding
public Indexer.IndexedBinding
public Indexer.IndexedBinding
visit(ProviderBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding to a com.google.inject.Provider that delegates to the binding for the provided type.
public Indexer.IndexedBinding
public Indexer.IndexedBinding
public Indexer.IndexedBinding
public Object
visitEagerSingleton()

Implements com.google.inject.spi.BindingScopingVisitor.visitEagerSingleton.

Visit an eager singleton or single instance.
public Object
visitNoScoping()

Implements com.google.inject.spi.BindingScopingVisitor.visitNoScoping.

Visit an unspecified or unscoped strategy.
public Object
public Object
visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation)

Implements com.google.inject.spi.BindingScopingVisitor.visitScopeAnnotation.

Visit a scope annotation.
Inherited from com.google.inject.spi.DefaultBindingTargetVisitor:
visitOther

Field Detail

EAGER_SINGLETONback to summary
private static final Object EAGER_SINGLETON
injectorback to summary
pack-priv final Injector injector

Constructor Detail

Indexerback to summary
pack-priv Indexer(Injector injector)

Method Detail

isIndexableback to summary
pack-priv boolean isIndexable(Binding<?> binding)
scopeback to summary
private Object scope(Binding<?> binding)
visitback to summary
public Indexer.IndexedBinding visit(ConstructorBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a constructor binding. To resolve injections, an instance is instantiated by invoking constructor. This target is found only on injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(ConvertedConstantBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding created from converting a bound instance to a new type. The source binding has the same binding annotation but a different type. This target is found only on injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(ExposedBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding to a key exposed from an enclosed private environment. This target is only found in injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(InstanceBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a instance binding. The same instance is returned for every injection. This target is found in both module and injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(LinkedKeyBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a linked key binding. The other key's binding is used to resolve injections. This target is found in both module and injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(ProviderBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a binding to a com.google.inject.Provider that delegates to the binding for the provided type. This target is found only on injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(ProviderInstanceBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a provider instance binding. The provider's get method is invoked to resolve injections. This target is found in both module and injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(ProviderKeyBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit a provider key binding. To resolve injections, the provider key is first resolved, then that provider's get method is invoked. This target is found in both module and injector bindings.

Annotations
@Override
visitback to summary
public Indexer.IndexedBinding visit(UntargettedBinding<? extends Object> binding)

Overrides com.google.inject.spi.DefaultBindingTargetVisitor.visit.

Implements com.google.inject.spi.BindingTargetVisitor.visit.

Doc from com.google.inject.spi.BindingTargetVisitor.visit.

Visit an untargetted binding. This target is found only on module bindings. It indicates that the injector should use its implicit binding strategies to resolve injections.

Annotations
@Override
visitEagerSingletonback to summary
public Object visitEagerSingleton()

Implements com.google.inject.spi.BindingScopingVisitor.visitEagerSingleton.

Doc from com.google.inject.spi.BindingScopingVisitor.visitEagerSingleton.

Visit an eager singleton or single instance. This scope strategy is found on both module and injector bindings.

Annotations
@Override
visitNoScopingback to summary
public Object visitNoScoping()

Implements com.google.inject.spi.BindingScopingVisitor.visitNoScoping.

Doc from com.google.inject.spi.BindingScopingVisitor.visitNoScoping.

Visit an unspecified or unscoped strategy. On a module, this strategy indicates that the injector should use scoping annotations to find a scope. On an injector, it indicates that no scope is applied to the binding. An unscoped binding will behave like a scoped one when it is linked to a scoped binding.

Annotations
@Override
visitScopeback to summary
public Object visitScope(Scope scope)

Implements com.google.inject.spi.BindingScopingVisitor.visitScope.

Doc from com.google.inject.spi.BindingScopingVisitor.visitScope.

Visit a scope instance. This scope strategy is found on both module and injector bindings.

Annotations
@Override
visitScopeAnnotationback to summary
public Object visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation)

Implements com.google.inject.spi.BindingScopingVisitor.visitScopeAnnotation.

Doc from com.google.inject.spi.BindingScopingVisitor.visitScopeAnnotation.

Visit a scope annotation. This scope strategy is found only on module bindings. The instance that implements this scope is registered by Binder.bindScope().

Annotations
@Override
com.google.inject.internal back to summary

pack-priv final Enum Indexer.BindingType

extends Enum<Indexer.BindingType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType
public static final Indexer.BindingType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Indexer.BindingType
public static Indexer.BindingType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CONSTANTback to summary
public static final Indexer.BindingType CONSTANT
CONSTRUCTORback to summary
public static final Indexer.BindingType CONSTRUCTOR
EXPOSEDback to summary
public static final Indexer.BindingType EXPOSED
INSTANCEback to summary
public static final Indexer.BindingType INSTANCE
LINKED_KEYback to summary
public static final Indexer.BindingType LINKED_KEY
PROVIDED_BYback to summary
public static final Indexer.BindingType PROVIDED_BY
PROVIDER_INSTANCEback to summary
public static final Indexer.BindingType PROVIDER_INSTANCE
PROVIDER_KEYback to summary
public static final Indexer.BindingType PROVIDER_KEY
UNTARGETTEDback to summary
public static final Indexer.BindingType UNTARGETTED

Constructor Detail

BindingTypeback to summary
private BindingType()

Method Detail

valueOfback to summary
public static Indexer.BindingType valueOf(String name)
valuesback to summary
public static Indexer.BindingType[] values()
com.google.inject.internal back to summary

pack-priv Class Indexer.IndexedBinding

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final String
pack-priv final Element.Type
pack-priv final Object
pack-priv final Object
pack-priv final Indexer.BindingType
pack-priv final TypeLiteral<?>

Constructor Summary

AccessConstructor and Description
pack-priv
IndexedBinding(Binding<?> binding, Indexer.BindingType type, Object scope, Object extraEquality)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationNameback to summary
pack-priv final String annotationName
annotationTypeback to summary
pack-priv final Element.Type annotationType
extraEqualityback to summary
pack-priv final Object extraEquality
scopeback to summary
pack-priv final Object scope
typeback to summary
pack-priv final Indexer.BindingType type
typeLiteralback to summary
pack-priv final TypeLiteral<?> typeLiteral

Constructor Detail

IndexedBindingback to summary
pack-priv IndexedBinding(Binding<?> binding, Indexer.BindingType type, Object scope, Object extraEquality)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override