• 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 experimental Android mode is enabled.
28    *
29    * <p><b>Warning: Do Not use! This flag is for internal, experimental use only!</b>
30    *
31    * <p>Issues related to this flag will not be supported. This flag could break your build, cause
32    * memory leaks in your app, or cause other unknown issues at runtime.
33    */
experimentalMergedMode(XTypeElement element)34   public abstract boolean experimentalMergedMode(XTypeElement element);
35 
36   /**
37    * Returns true if the fast initialization flag, {@code fastInit}, is enabled.
38    *
39    * <p>If enabled, the generated code will attempt to optimize for fast component initialization.
40    * This is done by reducing the number of factory classes loaded during initialization and the
41    * number of eagerly initialized fields at the cost of potential memory leaks and higher
42    * per-provision instantiation time.
43    */
fastInit(XTypeElement element)44   public abstract boolean fastInit(XTypeElement element);
45 
formatGeneratedSource()46   public abstract boolean formatGeneratedSource();
47 
writeProducerNameInToken()48   public abstract boolean writeProducerNameInToken();
49 
nullableValidationKind()50   public abstract Diagnostic.Kind nullableValidationKind();
51 
doCheckForNulls()52   public final boolean doCheckForNulls() {
53     return nullableValidationKind().equals(Diagnostic.Kind.ERROR);
54   }
55 
privateMemberValidationKind()56   public abstract Diagnostic.Kind privateMemberValidationKind();
57 
staticMemberValidationKind()58   public abstract Diagnostic.Kind staticMemberValidationKind();
59 
60   /**
61    * Returns {@code true} if the stacktrace should be included in the deferred error message.
62    *
63    * <p>The default for this option is {@code false}. The stacktrace is mostly useful for special
64    * debugging purposes to gather more information about where the exception was thrown from within
65    * Dagger's own processors.
66    */
includeStacktraceWithDeferredErrorMessages()67   public abstract boolean includeStacktraceWithDeferredErrorMessages();
68 
69   /**
70    * If {@code true}, Dagger will generate factories and components even if some members-injected
71    * types have {@code private} or {@code static} {@code @Inject}-annotated members.
72    *
73    * <p>This should only ever be enabled by the TCK tests. Disabling this validation could lead to
74    * generating code that does not compile.
75    */
ignorePrivateAndStaticInjectionForComponent()76   public abstract boolean ignorePrivateAndStaticInjectionForComponent();
77 
scopeCycleValidationType()78   public abstract ValidationType scopeCycleValidationType();
79 
80   /**
81    * If {@code true}, Dagger will validate all transitive component dependencies of a component.
82    * Otherwise, Dagger will only validate the direct component dependencies.
83    *
84    * <p>Note: this is different from scopeCycleValidationType, which lets you silence errors of
85    * transitive component dependencies, but still requires the full transitive dependencies in the
86    * classpath.
87    *
88    * <p>The main motivation for this flag is to prevent requiring the transitive component
89    * dependencies in the classpath to speed up builds. See
90    * https://github.com/google/dagger/issues/970.
91    */
validateTransitiveComponentDependencies()92   public abstract boolean validateTransitiveComponentDependencies();
93 
warnIfInjectionFactoryNotGeneratedUpstream()94   public abstract boolean warnIfInjectionFactoryNotGeneratedUpstream();
95 
headerCompilation()96   public abstract boolean headerCompilation();
97 
fullBindingGraphValidationType()98   public abstract ValidationType fullBindingGraphValidationType();
99 
100   /**
101    * If {@code true}, each plugin will visit the full binding graph for the given element.
102    *
103    * @throws IllegalArgumentException if {@code element} is not a module or (sub)component
104    */
pluginsVisitFullBindingGraphs(XTypeElement element)105   public abstract boolean pluginsVisitFullBindingGraphs(XTypeElement element);
106 
moduleHasDifferentScopesDiagnosticKind()107   public abstract Diagnostic.Kind moduleHasDifferentScopesDiagnosticKind();
108 
explicitBindingConflictsWithInjectValidationType()109   public abstract ValidationType explicitBindingConflictsWithInjectValidationType();
110 
experimentalDaggerErrorMessages()111   public abstract boolean experimentalDaggerErrorMessages();
112 
113   /**
114    * Returns {@code true} if strict superficial validation is enabled.
115    *
116    * <p>This option is enabled by default and allows Dagger to detect and fail if an element that
117    * supports being annotated with a scope or qualifier annotation is annotated with any
118    * unresolvable annotation types. This option is considered "strict" because in most cases we must
119    * fail for any unresolvable annotation types, not just scopes and qualifiers. In particular, if
120    * an annotation type is not resolvable, we don't have enough information to tell if it's a scope
121    * or qualifier, so we must fail for all unresolvable annotations.
122    *
123    * <p>This option can be disabled to allow easier migration from the legacy behavior of Dagger
124    * (i.e. versions less than or equal to 2.40.5). However, we will remove this option in a future
125    * version of Dagger.
126    *
127    * <p>Warning:Disabling this option means that Dagger may miss a scope or qualifier on a binding,
128    * leading to a (wrong) unscoped binding or a (wrong) unqualified binding, respectively.
129    */
strictSuperficialValidation()130   public abstract boolean strictSuperficialValidation();
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