1 /* 2 * Copyright (C) 2020 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.hilt.android.processor.internal.androidentrypoint; 18 19 import java.util.Arrays; 20 import java.util.Set; 21 import java.util.stream.Collectors; 22 import javax.annotation.processing.ProcessingEnvironment; 23 24 /** Hilt annotation processor options. */ 25 // TODO(danysantiago): Consider consolidating with Dagger compiler options logic. 26 // TODO(user): Move this class to dagger/hilt/processor/internal 27 public final class HiltCompilerOptions { 28 29 /** Processor options which can have true or false values. */ 30 public enum BooleanOption { 31 /** 32 * Flag that disables validating the superclass of @AndroidEntryPoint are Hilt_ generated, 33 * classes. This flag is to be used internally by the Gradle plugin, enabling the bytecode 34 * transformation to change the superclass. 35 */ 36 DISABLE_ANDROID_SUPERCLASS_VALIDATION( 37 "android.internal.disableAndroidSuperclassValidation", false), 38 39 /** Flag that disables check on modules to be annotated with @InstallIn. */ 40 DISABLE_MODULES_HAVE_INSTALL_IN_CHECK("disableModulesHaveInstallInCheck", false); 41 42 private final String name; 43 private final boolean defaultValue; 44 BooleanOption(String name, boolean defaultValue)45 BooleanOption(String name, boolean defaultValue) { 46 this.name = name; 47 this.defaultValue = defaultValue; 48 } 49 get(ProcessingEnvironment env)50 public boolean get(ProcessingEnvironment env) { 51 String value = env.getOptions().get(getQualifiedName()); 52 if (value == null) { 53 return defaultValue; 54 } 55 // TODO(danysantiago): Strictly verify input, either 'true' or 'false' and nothing else. 56 return Boolean.parseBoolean(value); 57 } 58 getQualifiedName()59 public String getQualifiedName() { 60 return "dagger.hilt." + name; 61 } 62 } 63 getProcessorOptions()64 public static Set<String> getProcessorOptions() { 65 return Arrays.stream(BooleanOption.values()) 66 .map(BooleanOption::getQualifiedName) 67 .collect(Collectors.toSet()); 68 } 69 HiltCompilerOptions()70 private HiltCompilerOptions() {} 71 } 72