Key forProductionComponentMonitor() { return Key.builder(elements.getTypeElement(ProductionComponentMonitor.class).asType()).build(); }
wrappingElement, mapType.unwrappedValueType(currentWrappingClass)); return Optional.of( possibleMapKey.toBuilder().type(mapOf(mapType.keyType(), wrappedValueType)).build());
.map(key -> key.toBuilder().multibindingContributionIdentifier(Optional.empty()).build()) .forEach(requestResolver::resolve);
.multibindingContributionIdentifier( new MultibindingContributionIdentifier(method, contributingModule)) .build();
/** * If {@code key}'s type is {@code Map<K, Provider<V>>}, {@code Map<K, Producer<V>>}, or {@code * Map<K, Produced<V>>}, returns a key with the same qualifier and {@link * Key#multibindingContributionIdentifier()} whose type is simply {@code Map<K, V>}. * * <p>Otherwise, returns {@code key}. */ Key unwrapMapValueType(Key key) { if (MapType.isMap(key)) { MapType mapType = MapType.from(key); if (!mapType.isRawType()) { for (Class<?> frameworkClass : asList(Provider.class, Producer.class, Produced.class)) { if (mapType.valuesAreTypeOf(frameworkClass)) { return key.toBuilder() .type(mapOf(mapType.keyType(), mapType.unwrappedValueType(frameworkClass))) .build(); } } } } return key; }
/** * If {@code key}'s type is {@code Map<K, Foo>} and {@code Foo} is not {@code WrappingClass * <Bar>}, returns a key with type {@code Map<K, WrappingClass<Foo>>} with the same qualifier. * Otherwise returns {@link Optional#empty()}. * * <p>Returns {@link Optional#empty()} if {@code WrappingClass} is not in the classpath. */ private Optional<Key> wrapMapKey(Key possibleMapKey, Class<?> wrappingClass) { if (MapType.isMap(possibleMapKey)) { MapType mapType = MapType.from(possibleMapKey); if (!mapType.isRawType() && !mapType.valuesAreTypeOf(wrappingClass)) { TypeElement wrappingElement = elements.getTypeElement(wrappingClass); if (wrappingElement == null) { // This target might not be compiled with Producers, so wrappingClass might not have an // associated element. return Optional.empty(); } DeclaredType wrappedValueType = types.getDeclaredType(wrappingElement, mapType.valueType()); return Optional.of( possibleMapKey.toBuilder().type(mapOf(mapType.keyType(), wrappedValueType)).build()); } } return Optional.empty(); }
/** * A multimap of those {@code declarations} that are multibinding contribution declarations, * indexed by the key of the set or map to which they contribute. */ static <T extends BindingDeclaration> ImmutableSetMultimap<Key, T> multibindingContributionsByMultibindingKey( Iterable<T> declarations) { ImmutableSetMultimap.Builder<Key, T> builder = ImmutableSetMultimap.builder(); for (T declaration : declarations) { if (declaration.key().multibindingContributionIdentifier().isPresent()) { builder.put( declaration .key() .toBuilder() .multibindingContributionIdentifier(Optional.empty()) .build(), declaration); } } return builder.build(); } }
/** * If {@code key}'s type is {@code Optional<T>} for some {@code T}, returns a key with the same * qualifier whose type is {@linkplain RequestKinds#extractKeyType(RequestKind, TypeMirror)} * extracted} from {@code T}. */ Optional<Key> unwrapOptional(Key key) { if (!OptionalType.isOptional(key)) { return Optional.empty(); } TypeMirror optionalValueType = OptionalType.from(key).valueType(); return Optional.of( key.toBuilder() .type(extractKeyType(getRequestKind(optionalValueType), optionalValueType)) .build()); } }
/** * If {@code key}'s type is {@code Set<WrappingClass<Bar>>}, returns a key with type {@code Set * <Bar>} with the same qualifier. Otherwise returns {@link Optional#empty()}. */ Optional<Key> unwrapSetKey(Key key, Class<?> wrappingClass) { if (SetType.isSet(key)) { SetType setType = SetType.from(key); if (!setType.isRawType() && setType.elementsAreTypeOf(wrappingClass)) { return Optional.of( key.toBuilder().type(setOf(setType.unwrappedElementType(wrappingClass))).build()); } } return Optional.empty(); }
Key forInjectConstructorWithResolvedType(TypeMirror type) { return Key.builder(type).build(); }
Key forMembersInjectedType(TypeMirror type) { return Key.builder(type).build(); }
Key forType(TypeMirror type) { return Key.builder(type).build(); }
Key forQualifiedType(Optional<AnnotationMirror> qualifier, TypeMirror type) { return Key.builder(boxPrimitives(type)).qualifier(qualifier).build(); }
Key forSubcomponentCreator(TypeMirror creatorType) { return Key.builder(creatorType).build(); }
Key forProductionExecutor() { return Key.builder(elements.getTypeElement(Executor.class).asType()) .qualifier(SimpleAnnotationMirror.of(elements.getTypeElement(Production.class))) .build(); }
Key forSubcomponentCreatorMethod( ExecutableElement subcomponentCreatorMethod, DeclaredType declaredContainer) { checkArgument(subcomponentCreatorMethod.getKind().equals(METHOD)); ExecutableType resolvedMethod = asExecutable(types.asMemberOf(declaredContainer, subcomponentCreatorMethod)); return Key.builder(resolvedMethod.getReturnType()).build(); }
Key forProductionImplementationExecutor() { return Key.builder(elements.getTypeElement(Executor.class).asType()) .qualifier(SimpleAnnotationMirror.of(elements.getTypeElement(ProductionImplementation.class))) .build(); }