Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.google.inject.internal;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.spi.InjectionPoint;
import com.google.inject.spi.Message;
import com.google.inject.spi.ModuleAnnotatedMethodScanner;
import com.google.inject.util.Modules;
import java.lang.annotation.Annotation;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
/**
* Creates bindings to methods annotated with {@literal @}{@link Provides}. Use the scope and
* binding annotations on the provider method to configure the binding.
*
*/
public final class ProviderMethodsModule implements Module {
private final Object delegate;
private final TypeLiteral> typeLiteral;
private final boolean skipFastClassGeneration;
private final ModuleAnnotatedMethodScanner scanner;
private ProviderMethodsModule(Object delegate, boolean skipFastClassGeneration,
ModuleAnnotatedMethodScanner scanner) {
this.delegate = checkNotNull(delegate, "delegate");
this.typeLiteral = TypeLiteral.get(this.delegate.getClass());
this.skipFastClassGeneration = skipFastClassGeneration;
this.scanner = scanner;
}
/**
* Returns a module which creates bindings for provider methods from the given module.
*/
public static Module forModule(Module module) {
return forObject(module, false, ProvidesMethodScanner.INSTANCE);
}
/**
* Returns a module which creates bindings methods in the module that match the scanner.
*/
public static Module forModule(Object module, ModuleAnnotatedMethodScanner scanner) {
return forObject(module, false, scanner);
}
/**
* Returns a module which creates bindings for provider methods from the given object.
* This is useful notably for GIN
*
*
This will skip bytecode generation for provider methods, since it is assumed that callers
* are only interested in Module metadata.
*/
public static Module forObject(Object object) {
return forObject(object, true, ProvidesMethodScanner.INSTANCE);
}
private static Module forObject(Object object, boolean skipFastClassGeneration,
ModuleAnnotatedMethodScanner scanner) {
// avoid infinite recursion, since installing a module always installs itself
if (object instanceof ProviderMethodsModule) {
return Modules.EMPTY_MODULE;
}
return new ProviderMethodsModule(object, skipFastClassGeneration, scanner);
}
public Class> getDelegateModuleClass() {
return isStaticModule() ? (Class>) delegate : delegate.getClass();
}
@Override
public void configure(Binder binder) {
for (ProviderMethod> providerMethod : getProviderMethods(binder)) {
providerMethod.configure(binder);
}
}
private boolean isStaticModule() {
return delegate instanceof Class;
}
public Object getDelegateModule() {
return delegate;
}
public List> getProviderMethods(Binder binder) {
List> result = null;
List methodsAndAnnotations = null;
// The highest class in the type hierarchy that contained a provider method definition.
Class> superMostClass = getDelegateModuleClass();
for (Class> c = superMostClass; c != Object.class && c != null; c = c.getSuperclass()) {
for (Method method : DeclaredMembers.getDeclaredMethods(c)) {
Annotation annotation = getAnnotation(binder, method);
if (annotation != null) {
if (isStaticModule()
&& !Modifier.isStatic(method.getModifiers())
&& !Modifier.isAbstract(method.getModifiers())) {
binder
.skipSources(ProviderMethodsModule.class)
.addError(
"%s is an instance method, but a class literal was passed. Make this method"
+ " static or pass an instance of the module instead.",
method);
continue;
}
if (result == null) {
result = new ArrayList<>();
methodsAndAnnotations = new ArrayList<>();
}
ProviderMethod