OptionalBinderBinding<Optional<T>> optionalBinder = null;
OptionalBinderBinding<?> javaOptionalBinder = null;
Key<?> defaultKey = null;
Key<?> actualKey = null;
Binding optionalBinding = indexed.get(optionalKey);
optionalBinder =
(OptionalBinderBinding<Optional<T>>) optionalBinding.acceptTargetVisitor(visitor);
if (HAS_JAVA_OPTIONAL) {
Binding javaOptionalBinding = indexed.get(javaOptionalKey);
javaOptionalBinder = (OptionalBinderBinding) javaOptionalBinding.acceptTargetVisitor(visitor);
}
// Locate the defaultKey & actualKey
for (Element element : elements) {
if (optionalBinder.containsElement(element) && element instanceof Binding) {
Binding binding = (Binding) element;
if (isSourceEntry(binding, Source.DEFAULT)) {
defaultKey = binding.getKey();
} else if (isSourceEntry(binding, Source.ACTUAL)) {
actualKey = binding.getKey();
}
}
}
assertNotNull(optionalBinder);
if (HAS_JAVA_OPTIONAL) {
assertNotNull(javaOptionalBinder);
}
assertEquals(expectedDefault == null, defaultKey == null);
assertEquals(expectedActual == null, actualKey == null);
Key<Optional<javax.inject.Provider<T>>> optionalJavaxProviderKey =
keyType.ofType(optionalOfJavaxProvider(keyType.getTypeLiteral()));
Key<?> javaOptionalJavaxProviderKey = HAS_JAVA_OPTIONAL ?
keyType.ofType(javaOptionalOfJavaxProvider(keyType.getTypeLiteral())) : null;
Key<Optional<Provider<T>>> optionalProviderKey =
keyType.ofType(optionalOfProvider(keyType.getTypeLiteral()));
Key<?> javaOptionalProviderKey = HAS_JAVA_OPTIONAL ?
keyType.ofType(javaOptionalOfProvider(keyType.getTypeLiteral())) : null;
boolean keyMatch = false;
boolean optionalKeyMatch = false;
boolean javaOptionalKeyMatch = false;
boolean optionalJavaxProviderKeyMatch = false;
boolean javaOptionalJavaxProviderKeyMatch = false;
boolean optionalProviderKeyMatch = false;
boolean javaOptionalProviderKeyMatch = false;
boolean defaultMatch = false;
boolean actualMatch = false;
List<Object> otherOptionalElements = Lists.newArrayList();
List<Element> otherContains = Lists.newArrayList();
List<Element> nonContainedElements = Lists.newArrayList();
for (Element element : elements) {
boolean contains = optionalBinder.containsElement(element);
if (HAS_JAVA_OPTIONAL) {
assertEquals(contains, javaOptionalBinder.containsElement(element));
}
if (!contains) {
nonContainedElements.add(element);
}
Key key = null;
Binding b = null;
if (element instanceof Binding) {
b = (Binding) element;
key = b.getKey();
Object visited = b.acceptTargetVisitor(visitor);
if (visited instanceof OptionalBinderBinding) {
if (visited.equals(optionalBinder)) {
assertTrue(contains);
} else if (HAS_JAVA_OPTIONAL && visited.equals(javaOptionalBinder)) {
assertTrue(contains);