• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.internal.codegen;
18 
19 import static java.lang.annotation.ElementType.FIELD;
20 import static java.lang.annotation.ElementType.METHOD;
21 import static java.lang.annotation.ElementType.PARAMETER;
22 import static java.lang.annotation.RetentionPolicy.RUNTIME;
23 
24 import com.google.common.collect.ImmutableSet;
25 import dagger.Module;
26 import dagger.Provides;
27 import dagger.internal.codegen.validation.BindingGraphValidator;
28 import dagger.spi.BindingGraphPlugin;
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.Target;
31 import java.util.Optional;
32 import java.util.ServiceLoader;
33 import javax.inject.Qualifier;
34 import javax.inject.Singleton;
35 
36 /** Contains the bindings for {@link BindingGraphValidator} from external SPI providers. */
37 @Module
38 abstract class SpiModule {
SpiModule()39   private SpiModule() {}
40 
41   @Provides
42   @Singleton
externalPlugins( @estingPlugins Optional<ImmutableSet<BindingGraphPlugin>> testingPlugins, @ProcessorClassLoader ClassLoader processorClassLoader)43   static ImmutableSet<BindingGraphPlugin> externalPlugins(
44       @TestingPlugins Optional<ImmutableSet<BindingGraphPlugin>> testingPlugins,
45       @ProcessorClassLoader ClassLoader processorClassLoader) {
46     return testingPlugins.orElseGet(
47         () ->
48             ImmutableSet.copyOf(
49                 ServiceLoader.load(BindingGraphPlugin.class, processorClassLoader)));
50   }
51 
52   @Qualifier
53   @Retention(RUNTIME)
54   @Target({FIELD, PARAMETER, METHOD})
55   @interface TestingPlugins {}
56 
57   @Qualifier
58   @Retention(RUNTIME)
59   @Target({PARAMETER, METHOD})
60   @interface ProcessorClassLoader {}
61 }
62