/** * Returns a {@link SetType} for {@code key}'s {@link Key#type() type}. * * @throws IllegalArgumentException if {@code key.type()} is not a {@link Set} type */ static SetType from(Key key) { return from (key.type()); } }
/** * {@code true} if {@code key.type()} is a {@link Set} type. */ static boolean isSet(Key key) { return isSet(key.type()); }
@Override protected TypeMirror contributedType() { return request.key().type(); } }
/** * Returns a {@link OptionalType} for {@code key}'s {@link Key#type() type}. * * @throws IllegalArgumentException if {@code key.type()} is not an {@code Optional} type */ static OptionalType from(Key key) { return from(key.type()); } }
/** * {@code true} if {@code key.type()} is a {@link Map} type. */ static boolean isMap(Key key) { return isMap(key.type()); }
/** Returns {@code true} if {@code key.type()} is an {@code Optional} type. */ static boolean isOptional(Key key) { return isOptional(key.type()); }
static ComponentRequirement forBoundInstance(Key key, boolean nullable, String variableName) { return new AutoValue_ComponentRequirement( Kind.BOUND_INSTANCE, MoreTypes.equivalence().wrap(key.type()), nullable ? Optional.of(NullPolicy.ALLOW) : Optional.empty(), Optional.of(key), variableName); }
static boolean isValidMembersInjectionKey(Key key) { return !key.qualifier().isPresent() && !key.multibindingContributionIdentifier().isPresent() && key.type().getKind().equals(TypeKind.DECLARED); }
private static TypeName asyncDependencyType(DependencyRequest dependency) { TypeName keyName = TypeName.get(dependency.key().type()); switch (dependency.kind()) { case INSTANCE: return keyName; case PRODUCED: return producedOf(keyName); default: throw new AssertionError(); } }
@Override Expression getDependencyExpression(ClassName requestingClass) { return Expression.create(binding.key().type(), "new $LBuilder()", subcomponentBuilderName); } }
/** * Returns {@code true} if this is valid as an implicit key (that is, if it's valid for a * just-in-time binding by discovering an {@code @Inject} constructor). */ static boolean isValidImplicitProvisionKey(Key key, DaggerTypes types) { return isValidImplicitProvisionKey(key.qualifier(), key.type(), types); }
/** * When a binding is resolved for a {@link SubcomponentDeclaration}, adds corresponding {@link * ComponentDescriptor subcomponent} to a queue in the owning component's resolver. The queue * will be used to detect which subcomponents need to be resolved. */ private void addSubcomponentToOwningResolver(ProvisionBinding subcomponentCreatorBinding) { checkArgument(subcomponentCreatorBinding.kind().equals(SUBCOMPONENT_BUILDER)); Resolver owningResolver = getOwningResolver(subcomponentCreatorBinding).get(); TypeElement builderType = MoreTypes.asTypeElement(subcomponentCreatorBinding.key().type()); owningResolver.subcomponentsToResolve.add( owningResolver.componentDescriptor.getChildComponentWithBuilderType(builderType)); }
@Override Expression getDependencyExpression(ClassName requestingClass) { CodeBlock invocation = CodeBlock.of( "$L.$L()", componentRequirementExpressions.getExpression(componentRequirement(), requestingClass), binding.bindingElement().get().getSimpleName()); return Expression.create( binding.contributedPrimitiveType().orElse(binding.key().type()), maybeCheckForNull(binding, compilerOptions, invocation)); }
@Override Expression getDependencyExpression(ClassName requestingClass) { return Expression.create( types.wrapType(key.type(), ListenableFuture.class), CodeBlock.of("$T.immediateFuture($L)", Futures.class, instanceExpression(requestingClass))); }
private static TypeMirror fieldValueType(ResolvedBindings resolvedBindings) { return resolvedBindings.isMultibindingContribution() ? resolvedBindings.contributionBinding().contributedType() : resolvedBindings.key().type(); }
@Override public String visitVariable(VariableElement variable, DependencyRequest request) { TypeMirror requestedType = requestType(request.kind(), request.key().type(), types); return INDENT + formatQualifier(request.key().qualifier()) + requestedType + " is injected at\n" + DOUBLE_INDENT + elementToString(variable); }
private Expression collectionsStaticFactoryInvocation( ClassName requestingClass, CodeBlock methodInvocation) { return Expression.create( binding.key().type(), CodeBlock.builder() .add("$T.", Collections.class) .add(maybeTypeParameter(requestingClass)) .add(methodInvocation) .build()); }
private Expression collectionsStaticFactoryInvocation( ClassName requestingClass, CodeBlock methodInvocation) { return Expression.create( binding.key().type(), CodeBlock.builder() .add("$T.", Collections.class) .add(maybeTypeParameters(requestingClass)) .add(methodInvocation) .build()); }
private CodeBlock maybeTypeParameters(ClassName requestingClass) { TypeMirror bindingKeyType = binding.key().type(); MapType mapType = MapType.from(binding.key()); return isTypeAccessibleFrom(bindingKeyType, requestingClass.packageName()) ? CodeBlock.of("<$T, $T>", mapType.keyType(), mapType.valueType()) : CodeBlock.of(""); }
/** Returns a {@link dagger.model.BindingKind#MEMBERS_INJECTOR} binding. */ ProvisionBinding membersInjectorBinding( Key key, MembersInjectionBinding membersInjectionBinding) { return ProvisionBinding.builder() .key(key) .contributionType(ContributionType.UNIQUE) .kind(MEMBERS_INJECTOR) .bindingElement(MoreTypes.asTypeElement(membersInjectionBinding.key().type())) .provisionDependencies(membersInjectionBinding.dependencies()) .injectionSites(membersInjectionBinding.injectionSites()) .build(); }