aboutsummaryrefslogtreecommitdiff
path: root/java/dagger/hilt/processor/internal/HiltCompilerOptions.java
diff options
context:
space:
mode:
authorNicklas Ansman Giertz <nicklas@ansman.se>2021-03-03 22:17:07 -0800
committerDagger Team <dagger-dev+copybara@google.com>2021-03-03 22:18:29 -0800
commitc70cf2d38a5528c05fa1eb1426b3c78167062e33 (patch)
tree24ef38966280a842586511119891483d193c4b67 /java/dagger/hilt/processor/internal/HiltCompilerOptions.java
parent39894d289d27ed97b8e72a308bfa281e555ab5cc (diff)
downloaddagger2-c70cf2d38a5528c05fa1eb1426b3c78167062e33.tar.gz
Prevent KAPT from logging errors when compiling modules without entry points.
When Hilt Android is run on a module that contains no entry points, KAPT will log an error about `disableAndroidSuperclassValidation` not being a support option. This is because the Hilt Gradle plugin will add this option when applied but if no entry points exists, no processor actually accepts that option. With this fix, all Hilt processors accept these options (though they are unused). This will prevent KAPT from logging these warnings in most cases. It is still possible for warnings to be logged, for example if the Hilt plugin is applied, but Hilt isn't used but for those cases the user can simply skip applying the plugin. Fixes #2040 Closes #2372 RELNOTES="Reduce the possibility of KAPT logging warnings due to no processor supporting `disableAndroidSuperclassValidation` when no Android entry points are in the source module." PiperOrigin-RevId: 360836064
Diffstat (limited to 'java/dagger/hilt/processor/internal/HiltCompilerOptions.java')
-rw-r--r--java/dagger/hilt/processor/internal/HiltCompilerOptions.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/java/dagger/hilt/processor/internal/HiltCompilerOptions.java b/java/dagger/hilt/processor/internal/HiltCompilerOptions.java
new file mode 100644
index 000000000..1ba73ec59
--- /dev/null
+++ b/java/dagger/hilt/processor/internal/HiltCompilerOptions.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2020 The Dagger Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dagger.hilt.processor.internal;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.annotation.processing.ProcessingEnvironment;
+
+/** Hilt annotation processor options. */
+// TODO(danysantiago): Consider consolidating with Dagger compiler options logic.
+public final class HiltCompilerOptions {
+
+ /** Processor options which can have true or false values. */
+ public enum BooleanOption {
+ /**
+ * Flag that disables validating the superclass of @AndroidEntryPoint are Hilt_ generated,
+ * classes. This flag is to be used internally by the Gradle plugin, enabling the bytecode
+ * transformation to change the superclass.
+ */
+ DISABLE_ANDROID_SUPERCLASS_VALIDATION(
+ "android.internal.disableAndroidSuperclassValidation", false),
+
+ /** Flag that disables check on modules to be annotated with @InstallIn. */
+ DISABLE_MODULES_HAVE_INSTALL_IN_CHECK("disableModulesHaveInstallInCheck", false);
+
+ private final String name;
+ private final boolean defaultValue;
+
+ BooleanOption(String name, boolean defaultValue) {
+ this.name = name;
+ this.defaultValue = defaultValue;
+ }
+
+ public boolean get(ProcessingEnvironment env) {
+ String value = env.getOptions().get(getQualifiedName());
+ if (value == null) {
+ return defaultValue;
+ }
+ // TODO(danysantiago): Strictly verify input, either 'true' or 'false' and nothing else.
+ return Boolean.parseBoolean(value);
+ }
+
+ public String getQualifiedName() {
+ return "dagger.hilt." + name;
+ }
+ }
+
+ public static Set<String> getProcessorOptions() {
+ return Arrays.stream(BooleanOption.values())
+ .map(BooleanOption::getQualifiedName)
+ .collect(Collectors.toSet());
+ }
+
+ private HiltCompilerOptions() {}
+}