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.bindinggraphvalidation;
18 
19 import com.google.common.collect.ImmutableSet;
20 import dagger.Module;
21 import dagger.Provides;
22 import dagger.internal.codegen.compileroption.CompilerOptions;
23 import dagger.internal.codegen.validation.CompositeBindingGraphPlugin;
24 import dagger.internal.codegen.validation.Validation;
25 import dagger.spi.BindingGraphPlugin;
26 
27 /** Binds the set of {@link BindingGraphPlugin}s used to implement Dagger validation. */
28 @Module
29 public interface BindingGraphValidationModule {
30 
31   @Provides
32   @Validation
providePlugins( CompositeBindingGraphPlugin.Factory factory, CompilerOptions compilerOptions, DependencyCycleValidator validation1, DependsOnProductionExecutorValidator validation2, DuplicateBindingsValidator validation3, IncompatiblyScopedBindingsValidator validation4, InjectBindingValidator validation5, MapMultibindingValidator validation6, MissingBindingValidator validation7, NullableBindingValidator validation8, ProvisionDependencyOnProducerBindingValidator validation9, SubcomponentFactoryMethodValidator validation10)33   static ImmutableSet<BindingGraphPlugin> providePlugins(
34       CompositeBindingGraphPlugin.Factory factory,
35       CompilerOptions compilerOptions,
36       DependencyCycleValidator validation1,
37       DependsOnProductionExecutorValidator validation2,
38       DuplicateBindingsValidator validation3,
39       IncompatiblyScopedBindingsValidator validation4,
40       InjectBindingValidator validation5,
41       MapMultibindingValidator validation6,
42       MissingBindingValidator validation7,
43       NullableBindingValidator validation8,
44       ProvisionDependencyOnProducerBindingValidator validation9,
45       SubcomponentFactoryMethodValidator validation10) {
46     ImmutableSet<BindingGraphPlugin> plugins = ImmutableSet.of(
47         validation1,
48         validation2,
49         validation3,
50         validation4,
51         validation5,
52         validation6,
53         validation7,
54         validation8,
55         validation9,
56         validation10);
57     if (compilerOptions.experimentalDaggerErrorMessages()) {
58       return ImmutableSet.of(factory.create(plugins, "Dagger/Validation"));
59     } else {
60       return plugins;
61     }
62   }
63 }
64