/* * 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 static androidx.room.compiler.processing.compat.XConverters.getProcessingEnv; import static com.google.common.base.Ascii.toUpperCase; import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.XTypeElement; import androidx.room.compiler.processing.compat.XConverters; import com.google.common.collect.ImmutableSet; import dagger.hilt.processor.internal.optionvalues.BooleanValue; import dagger.hilt.processor.internal.optionvalues.GradleProjectType; import dagger.internal.codegen.extension.DaggerStreams; import java.util.Arrays; import java.util.HashSet; import java.util.Locale; import java.util.Set; import javax.tools.Diagnostic.Kind; /** Hilt annotation processor options. */ // TODO(danysantiago): Consider consolidating with Dagger compiler options logic. public final class HiltCompilerOptions { /** * Returns {@code true} if the superclass validation is disabled for {@link * dagger.hilt.android.AndroidEntryPoint}-annotated classes. * *
This flag is for internal use only! The superclass validation checks that the super class is
* a generated {@code Hilt_} class. This flag is disabled by the Hilt Gradle plugin to enable
* bytecode transformation to change the superclass.
*/
public static boolean isAndroidSuperClassValidationDisabled(XTypeElement element) {
EnumOption This flag should rarely be needed, but may be used for legacy/migration purposes if tests
* require the use of {@link dagger.hilt.android.HiltAndroidApp} rather than {@link
* dagger.hilt.android.testing.HiltAndroidTest}.
*
* Note that Hilt still does validation within a single compilation unit. In particular, a
* compilation unit that contains a {@code HiltAndroidApp} usage cannot have other {@code
* HiltAndroidApp} or {@code HiltAndroidTest} usages in the same compilation unit.
*/
public static boolean isCrossCompilationRootValidationDisabled(
ImmutableSet Tests that provide their own test bindings (e.g. using {@link
* dagger.hilt.android.testing.BindValue} or a test {@link dagger.Module}) cannot use the shared
* component. In these cases, a component will be generated for the test.
*/
public static boolean isSharedTestComponentsEnabled(XProcessingEnv env) {
return SHARE_TEST_COMPONENTS.get(env) == BooleanValue.TRUE;
}
/**
* Returns {@code true} if the aggregating processor is enabled (default is {@code true}).
*
* Note:This is for internal use only!
*/
public static boolean useAggregatingRootProcessor(XProcessingEnv env) {
return USE_AGGREGATING_ROOT_PROCESSOR.get(env) == BooleanValue.TRUE;
}
/**
* Returns project type or null if Hilt Gradle Plugin is not applied.
*
* Note:This is for internal use only!
*/
public static GradleProjectType getGradleProjectType(XProcessingEnv env) {
return GRADLE_PROJECT_TYPE.get(env);
}
public static boolean isAssistedInjectViewModelsEnabled(XTypeElement viewModelElement) {
boolean enabled =
ENABLE_ASSISTED_INJECT_VIEWMODELS.get(XConverters.getProcessingEnv(viewModelElement))
== BooleanValue.TRUE;
return enabled;
}
/** Do not use! This is for internal use only. */
private static final EnumOption