private static boolean typeIsOneOf(Set<Class<?>> classes, TypeMirror type) { for (Class<?> clazz : classes) { if (MoreTypes.isTypeOf(clazz, type)) { return true; } } return false; }
/** * {@code true} if {@code type} is a {@link Set} type. */ static boolean isSet(TypeMirror type) { return MoreTypes.isType(type) && MoreTypes.isTypeOf(Set.class, type); }
/** * {@code true} if {@code type} is a {@link Map} type. */ static boolean isMap(TypeMirror type) { return MoreTypes.isType(type) && MoreTypes.isTypeOf(Map.class, type); }
static boolean isFutureType(TypeMirror type) { return FUTURE_TYPES.stream().anyMatch(t -> MoreTypes.isTypeOf(t, type)); }
private static Optional<TypeMirror> unwrapListenableFuture( ValidationReport.Builder<ExecutableElement> reportBuilder, TypeMirror type) { if (MoreTypes.isType(type) && MoreTypes.isTypeOf(ListenableFuture.class, type)) { DeclaredType declaredType = MoreTypes.asDeclared(type); if (declaredType.getTypeArguments().isEmpty()) { reportBuilder.addError("@Produces methods cannot return a raw ListenableFuture"); return Optional.empty(); } else { return Optional.of((TypeMirror) getOnlyElement(declaredType.getTypeArguments())); } } return Optional.of(type); } }
/** * Returns {@code true} if {@code type} is a parameterized type of {@code kind}'s {@link * #frameworkClass(RequestKind) framework class}. */ private static boolean matchesKind(RequestKind kind, TypeMirror type) { return isType(type) && isTypeOf(frameworkClass(kind), type) && !asDeclared(type).getTypeArguments().isEmpty(); }
private boolean isDispatchingAndroidInjector(Binding binding) { Key key = binding.key(); return MoreTypes.isTypeOf(DispatchingAndroidInjector.class, key.type()) && !key.qualifier().isPresent(); }
/** * {@code true} if {@link #elementType()} is a {@code clazz}. */ boolean elementsAreTypeOf(Class<?> clazz) { return MoreTypes.isType(elementType()) && MoreTypes.isTypeOf(clazz, elementType()); }
/** * {@code true} if {@link #valueType()} is a {@code clazz}. * * @throws IllegalStateException if {@link #isRawType()} is true. */ boolean valuesAreTypeOf(Class<?> clazz) { return MoreTypes.isType(valueType()) && MoreTypes.isTypeOf(clazz, valueType()); }
/** * Returns a stream of the dependencies of {@code binding} that have a key type of {@code Map<K, * Provider<AndroidInjector.Factory<?>>}. */ private Stream<Binding> injectorMapDependencies(Binding binding, BindingGraph graph) { return graph.requestedBindings(binding).stream() .filter(requestedBinding -> requestedBinding.kind().equals(BindingKind.MULTIBOUND_MAP)) .filter( requestedBinding -> { TypeMirror valueType = MoreTypes.asDeclared(requestedBinding.key().type()).getTypeArguments().get(1); if (!MoreTypes.isTypeOf(Provider.class, valueType) || !valueType.getKind().equals(TypeKind.DECLARED)) { return false; } TypeMirror providedType = MoreTypes.asDeclared(valueType).getTypeArguments().get(0); return MoreTypes.isTypeOf(AndroidInjector.Factory.class, providedType); }); }
/** * Unwraps the framework class(es) of {@code requestKind} from {@code type}. If {@code * requestKind} is {@link RequestKind#INSTANCE}, this acts as an identity function. * * @throws TypeNotPresentException if {@code type} is an {@link javax.lang.model.type.ErrorType}, * which may mean that the type will be generated in a later round of processing * @throws IllegalArgumentException if {@code type} is not wrapped with {@code requestKind}'s * framework class(es). */ static TypeMirror extractKeyType(RequestKind requestKind, TypeMirror type) { checkTypePresent(type); switch (requestKind) { case INSTANCE: return type; case PROVIDER_OF_LAZY: return extractKeyType(LAZY, extractKeyType(PROVIDER, type)); default: checkArgument(isType(type) && isTypeOf(frameworkClass(requestKind), type)); return getOnlyElement(MoreTypes.asDeclared(type).getTypeArguments()); } }
DependencyRequest forComponentProductionMethod( ExecutableElement productionMethod, ExecutableType productionMethodType) { checkNotNull(productionMethod); checkNotNull(productionMethodType); checkArgument( productionMethod.getParameters().isEmpty(), "Component production methods must be empty: %s", productionMethod); TypeMirror type = productionMethodType.getReturnType(); Optional<AnnotationMirror> qualifier = InjectionAnnotations.getQualifier(productionMethod); // Only a component production method can be a request for a ListenableFuture, so we // special-case it here. if (isTypeOf(ListenableFuture.class, type)) { return DependencyRequest.builder() .kind(FUTURE) .key(keyFactory.forQualifiedType(qualifier, types.unwrapType(type))) .requestElement(productionMethod) .build(); } else { return newDependencyRequest(productionMethod, type, qualifier); } }
requestElement); if (MoreTypes.isType(keyType) && MoreTypes.isTypeOf(MembersInjector.class, keyType)) { DeclaredType membersInjectorType = MoreTypes.asDeclared(keyType); if (membersInjectorType.getTypeArguments().isEmpty()) {
}); if (isType(requestKey.type()) && isTypeOf(MembersInjector.class, requestKey.type())) { injectBindingRegistry .getOrFindMembersInjectorProvisionBinding(requestKey)