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.
/*
* Copyright (C) 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.inject.daggeradapter;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getFirst;
import static com.google.inject.daggeradapter.SupportedAnnotations.isAnnotationSupported;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimaps;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.internal.ProviderMethodsModule;
import com.google.inject.spi.ModuleAnnotatedMethodScanner;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.Set;
/**
* Adapts classes annotated with {@link @dagger.Module} such that their {@link @dagger.Provides}
* methods can be properly invoked by Guice to perform their provision operations.
*
*
Simple example:
*
*
{@code
* Guice.createInjector(
* DaggerAdapter.from(SomeDaggerModule.class, new AnotherModuleWithConstructor());
* }
*
*
For modules with no instance binding methods, prefer using a class literal. If there are
* instance binding methods, an instance of the module must be passed.
*
*
Any class literals specified by {@code dagger.Module(includes = ...)} transitively will be
* included. Modules are de-duplicated, though multiple module instances of the same type is an
* error. Specifying a module instance and a class literal is also an error.
*
*
Some notes on usage and compatibility.
*
*
*
Dagger provider methods have a "SET_VALUES" provision mode not supported by Guice.
*
Be careful about stateful modules. In contrast to Dagger (where components are expected to
* be recreated on-demand with new Module instances), Guice typically has a single injector
* with a long lifetime, so your module instance will be used throughout the lifetime of the
* entire app.
*
Dagger 1.x uses {@link @Singleton} for all scopes, including shorter-lived scopes like
* per-request or per-activity. Using modules written with Dagger 1.x usage in mind may result
* in mis-scoped objects.
*
Dagger 2.x supports custom scope annotations, but for use in Guice, a custom scope
* implementation must be registered in order to support the custom lifetime of that
* annotation.
*
*
*
If methods need to be ignored based on a condtion, a {@code Predicate} can be used
* passed to {@link DaggerAdapter.Builder#filter}, as in {@code
* DaggerAdapter.builder().addModules(...).filter(predicate).build()}. Only the methods which
* satisfy the predicate will be processed.
*/
public final class DaggerAdapter {
/** Creates a new {@link DaggerAdapter} from {@code daggerModuleObjects}. */
public static Module from(Object... daggerModuleObjects) {
return builder().addModules(ImmutableList.copyOf(daggerModuleObjects)).build();
}
public static Builder builder() {
return new Builder();
}
/**
* Builder for setting configuration options on DaggerAdapter.
*
* @since 5.0
*/
public static class Builder {
private final ImmutableList.Builder