• 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 androidx.room.compiler.processing.XTypeElement;
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(XTypeElement element)34   public abstract boolean fastInit(XTypeElement 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    * Returns {@code true} if the stacktrace should be included in the deferred error message.
52    *
53    * <p>The default for this option is {@code false}. The stacktrace is mostly useful for special
54    * debugging purposes to gather more information about where the exception was thrown from within
55    * Dagger's own processors.
56    */
includeStacktraceWithDeferredErrorMessages()57   public abstract boolean includeStacktraceWithDeferredErrorMessages();
58 
59   /**
60    * If {@code true}, Dagger will generate factories and components even if some members-injected
61    * types have {@code private} or {@code static} {@code @Inject}-annotated members.
62    *
63    * <p>This should only ever be enabled by the TCK tests. Disabling this validation could lead to
64    * generating code that does not compile.
65    */
ignorePrivateAndStaticInjectionForComponent()66   public abstract boolean ignorePrivateAndStaticInjectionForComponent();
67 
scopeCycleValidationType()68   public abstract ValidationType scopeCycleValidationType();
69 
70   /**
71    * If {@code true}, Dagger will validate all transitive component dependencies of a component.
72    * Otherwise, Dagger will only validate the direct component dependencies.
73    *
74    * <p>Note: this is different from scopeCycleValidationType, which lets you silence errors of
75    * transitive component dependencies, but still requires the full transitive dependencies in the
76    * classpath.
77    *
78    * <p>The main motivation for this flag is to prevent requiring the transitive component
79    * dependencies in the classpath to speed up builds. See
80    * https://github.com/google/dagger/issues/970.
81    */
validateTransitiveComponentDependencies()82   public abstract boolean validateTransitiveComponentDependencies();
83 
warnIfInjectionFactoryNotGeneratedUpstream()84   public abstract boolean warnIfInjectionFactoryNotGeneratedUpstream();
85 
headerCompilation()86   public abstract boolean headerCompilation();
87 
fullBindingGraphValidationType()88   public abstract ValidationType fullBindingGraphValidationType();
89 
90   /**
91    * If {@code true}, each plugin will visit the full binding graph for the given element.
92    *
93    * @throws IllegalArgumentException if {@code element} is not a module or (sub)component
94    */
pluginsVisitFullBindingGraphs(XTypeElement element)95   public abstract boolean pluginsVisitFullBindingGraphs(XTypeElement element);
96 
moduleHasDifferentScopesDiagnosticKind()97   public abstract Diagnostic.Kind moduleHasDifferentScopesDiagnosticKind();
98 
explicitBindingConflictsWithInjectValidationType()99   public abstract ValidationType explicitBindingConflictsWithInjectValidationType();
100 
experimentalDaggerErrorMessages()101   public abstract boolean experimentalDaggerErrorMessages();
102 
103   /**
104    * Returns {@code true} if strict superficial validation is enabled.
105    *
106    * <p>This option is enabled by default and allows Dagger to detect and fail if an element that
107    * supports being annotated with a scope or qualifier annotation is annotated with any
108    * unresolvable annotation types. This option is considered "strict" because in most cases we must
109    * fail for any unresolvable annotation types, not just scopes and qualifiers. In particular, if
110    * an annotation type is not resolvable, we don't have enough information to tell if it's a scope
111    * or qualifier, so we must fail for all unresolvable annotations.
112    *
113    * <p>This option can be disabled to allow easier migration from the legacy behavior of Dagger
114    * (i.e. versions less than or equal to 2.40.5). However, we will remove this option in a future
115    * version of Dagger.
116    *
117    * <p>Warning:Disabling this option means that Dagger may miss a scope or qualifier on a binding,
118    * leading to a (wrong) unscoped binding or a (wrong) unqualified binding, respectively.
119    */
strictSuperficialValidation()120   public abstract boolean strictSuperficialValidation();
121 
122   /**
123    * Returns {@code true} if the Dagger generated class should extend the {@code @Component}
124    * annotated interface/class.
125    *
126    * <p>The default value is {@code false}. This flag was introduced in Dagger 2.42 to allow users
127    * to switch back to the previous behavior ({@code true}) so that they can migrate incrementally.
128    * This flag will be removed in a future release.
129    */
generatedClassExtendsComponent()130   public abstract boolean generatedClassExtendsComponent();
131 
132   /** Returns the number of bindings allowed per shard. */
keysPerComponentShard(XTypeElement component)133   public int keysPerComponentShard(XTypeElement component) {
134     return 3500;
135   }
136 
137   /**
138    * This option enables a fix to an issue where Dagger previously would erroneously allow
139    * multibinding contributions in a component to have dependencies on child components. This will
140    * eventually become the default and enforced.
141    */
strictMultibindingValidation()142   public abstract boolean strictMultibindingValidation();
143 
144   /**
145    * Returns {@code true} if we should ignore the variance in provision key types.
146    *
147    * <p>By enabling this flag, Dagger will no longer allow provisioning multiple keys that only
148    * differ by the key type's variance (a.k.a. wildcards). As an example, the provisioning a binding
149    * for {@code Foo<? extends Bar>} and {@code Foo<Bar>} would result in a duplicate binding error.
150    */
ignoreProvisionKeyWildcards()151   public abstract boolean ignoreProvisionKeyWildcards();
152 }
153