|
16 | 16 |
|
17 | 17 | package dagger.internal.codegen.compileroption; |
18 | 18 |
|
| 19 | +import androidx.room3.compiler.processing.XProcessingEnv; |
19 | 20 | import androidx.room3.compiler.processing.XTypeElement; |
| 21 | +import com.google.common.base.Ascii; |
20 | 22 | import javax.tools.Diagnostic; |
21 | 23 |
|
22 | 24 | /** A collection of options that dictate how the compiler will run. */ |
@@ -168,4 +170,34 @@ public int keysPerComponentShard(XTypeElement component) { |
168 | 170 | * boundaries at compile time (for Maps) and runtime (for Sets). |
169 | 171 | */ |
170 | 172 | public abstract boolean mapMultibindingDuplicateDetectionFix(); |
| 173 | + |
| 174 | + /** |
| 175 | + * Returns {@code true} if Dagger should also look for nullable type annotations. |
| 176 | + * |
| 177 | + * Note that when disabled, Dagger doesn't disallow usage of nullable type annotations. Instead, |
| 178 | + * the behavior is simply that Dagger does not look for them, so types marked with nullable type |
| 179 | + * annotations may appear to be non-nullable. |
| 180 | + */ |
| 181 | + public abstract boolean nullableTypeAnnotations(); |
| 182 | + |
| 183 | + /** |
| 184 | + * Returns {@code true} if Dagger should also look for nullable type annotations. |
| 185 | + * |
| 186 | + * @deprecated use {@link CompilerOptions#nullableTypeAnnotations()}. This method should only be |
| 187 | + * used for legacy code which requires accessing this flag from static methods that don't |
| 188 | + * easily have access to an instance of {@link CompilerOptions}. |
| 189 | + */ |
| 190 | + @Deprecated |
| 191 | + public static boolean nullableTypeAnnotations(XProcessingEnv processingEnv) { |
| 192 | + String optionName = |
| 193 | + ProcessingEnvironmentCompilerOptions.Feature.NULLABLE_TYPE_ANNOTATIONS.toString(); |
| 194 | + String defaultValue = |
| 195 | + ProcessingEnvironmentCompilerOptions.Feature.NULLABLE_TYPE_ANNOTATIONS |
| 196 | + .defaultValue().name(); |
| 197 | + String optionValue = |
| 198 | + processingEnv.getOptions().containsKey(optionName) |
| 199 | + ? processingEnv.getOptions().get(optionName) |
| 200 | + : defaultValue; |
| 201 | + return Ascii.equalsIgnoreCase(optionValue, FeatureStatus.ENABLED.name()); |
| 202 | + } |
171 | 203 | } |
0 commit comments