• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.compileroption;
18 
19 import javax.lang.model.element.TypeElement;
20 import javax.tools.Diagnostic;
21 
22 /** A collection of options that dictate how the compiler will run. */
23 public abstract class CompilerOptions {
usesProducers()24   public abstract boolean usesProducers();
25 
26   /**
27    * Returns true if the fast initialization flag, {@code fastInit}, is enabled.
28    *
29    * <p>If enabled, the generated code will attempt to optimize for fast component initialization.
30    * This is done by reducing the number of factory classes loaded during initialization and the
31    * number of eagerly initialized fields at the cost of potential memory leaks and higher
32    * per-provision instantiation time.
33    */
fastInit(TypeElement element)34   public abstract boolean fastInit(TypeElement element);
35 
formatGeneratedSource()36   public abstract boolean formatGeneratedSource();
37 
writeProducerNameInToken()38   public abstract boolean writeProducerNameInToken();
39 
nullableValidationKind()40   public abstract Diagnostic.Kind nullableValidationKind();
41 
doCheckForNulls()42   public final boolean doCheckForNulls() {
43     return nullableValidationKind().equals(Diagnostic.Kind.ERROR);
44   }
45 
privateMemberValidationKind()46   public abstract Diagnostic.Kind privateMemberValidationKind();
47 
staticMemberValidationKind()48   public abstract Diagnostic.Kind staticMemberValidationKind();
49 
50   /**
51    * If {@code true}, Dagger will generate factories and components even if some members-injected
52    * types have {@code private} or {@code static} {@code @Inject}-annotated members.
53    *
54    * <p>This should only ever be enabled by the TCK tests. Disabling this validation could lead to
55    * generating code that does not compile.
56    */
ignorePrivateAndStaticInjectionForComponent()57   public abstract boolean ignorePrivateAndStaticInjectionForComponent();
58 
scopeCycleValidationType()59   public abstract ValidationType scopeCycleValidationType();
60 
61   /**
62    * If {@code true}, Dagger will validate all transitive component dependencies of a component.
63    * Otherwise, Dagger will only validate the direct component dependencies.
64    *
65    * <p>Note: this is different from scopeCycleValidationType, which lets you silence errors of
66    * transitive component dependencies, but still requires the full transitive dependencies in the
67    * classpath.
68    *
69    * <p>The main motivation for this flag is to prevent requiring the transitive component
70    * dependencies in the classpath to speed up builds. See
71    * https://github.com/google/dagger/issues/970.
72    */
validateTransitiveComponentDependencies()73   public abstract boolean validateTransitiveComponentDependencies();
74 
warnIfInjectionFactoryNotGeneratedUpstream()75   public abstract boolean warnIfInjectionFactoryNotGeneratedUpstream();
76 
headerCompilation()77   public abstract boolean headerCompilation();
78 
fullBindingGraphValidationType()79   public abstract ValidationType fullBindingGraphValidationType();
80 
81   /**
82    * If {@code true}, each plugin will visit the full binding graph for the given element.
83    *
84    * @throws IllegalArgumentException if {@code element} is not a module or (sub)component
85    */
pluginsVisitFullBindingGraphs(TypeElement element)86   public abstract boolean pluginsVisitFullBindingGraphs(TypeElement element);
87 
moduleHasDifferentScopesDiagnosticKind()88   public abstract Diagnostic.Kind moduleHasDifferentScopesDiagnosticKind();
89 
explicitBindingConflictsWithInjectValidationType()90   public abstract ValidationType explicitBindingConflictsWithInjectValidationType();
91 
experimentalDaggerErrorMessages()92   public abstract boolean experimentalDaggerErrorMessages();
93 
94   /** Returns the number of bindings allowed per shard. */
keysPerComponentShard(TypeElement component)95   public int keysPerComponentShard(TypeElement component) {
96     return 3500;
97   }
98 
99   /**
100    * This option enables a fix to an issue where Dagger previously would erroneously allow
101    * multibinding contributions in a component to have dependencies on child components. This will
102    * eventually become the default and enforced.
103    */
strictMultibindingValidation()104   public abstract boolean strictMultibindingValidation();
105 }
106