1 /* 2 * Copyright 2021 Google LLC 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 * https://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 package com.google.android.enterprise.connectedapps.processor.annotationdiscovery; 17 18 import com.google.auto.value.AutoValue; 19 import java.lang.annotation.Annotation; 20 21 /** Provides the raw string names for cross-profile annotations. */ 22 @AutoValue 23 public abstract class AnnotationStrings 24 implements AnnotationNames, AnnotationPrinter, AnnotationClasses { 25 26 @Override crossProfile()27 public String crossProfile() { 28 return crossProfileAnnotationClass().getSimpleName(); 29 } 30 31 @Override crossProfileAsAnnotation()32 public String crossProfileAsAnnotation() { 33 return asAnnotation(crossProfile()); 34 } 35 36 @Override crossProfileAsAnnotation(String content)37 public String crossProfileAsAnnotation(String content) { 38 return asAnnotationWithContent(crossProfile(), content); 39 } 40 41 @Override crossProfileQualifiedName()42 public String crossProfileQualifiedName() { 43 return crossProfileAnnotationClass().getCanonicalName(); 44 } 45 46 @Override crossProfileCallback()47 public String crossProfileCallback() { 48 return crossProfileCallbackAnnotationClass().getSimpleName(); 49 } 50 51 @Override crossProfileCallbackAsAnnotation()52 public String crossProfileCallbackAsAnnotation() { 53 return asAnnotation(crossProfileCallback()); 54 } 55 56 @Override crossProfileCallbackAsAnnotation(String content)57 public String crossProfileCallbackAsAnnotation(String content) { 58 return crossProfileCallbackAsAnnotation() + "(" + content + ")"; 59 } 60 61 @Override crossProfileCallbackQualifiedName()62 public String crossProfileCallbackQualifiedName() { 63 return crossProfileCallbackAnnotationClass().getCanonicalName(); 64 } 65 66 @Override crossProfileConfiguration()67 public String crossProfileConfiguration() { 68 return crossProfileConfigurationAnnotationClass().getSimpleName(); 69 } 70 71 @Override crossProfileConfigurationAsAnnotation()72 public String crossProfileConfigurationAsAnnotation() { 73 return asAnnotation(crossProfileConfiguration()); 74 } 75 76 @Override crossProfileConfigurationAsAnnotation(String content)77 public String crossProfileConfigurationAsAnnotation(String content) { 78 return asAnnotationWithContent(crossProfileConfiguration(), content); 79 } 80 81 @Override crossProfileConfigurationQualifiedName()82 public String crossProfileConfigurationQualifiedName() { 83 return crossProfileConfigurationAnnotationClass().getCanonicalName(); 84 } 85 86 @Override crossProfileConfigurations()87 public String crossProfileConfigurations() { 88 return crossProfileConfigurationsAnnotationClass().getSimpleName(); 89 } 90 91 @Override crossProfileConfigurationsAsAnnotation(String content)92 public String crossProfileConfigurationsAsAnnotation(String content) { 93 return asAnnotationWithContent(crossProfileProvider(), content); 94 } 95 96 @Override crossProfileConfigurationsQualifiedName()97 public String crossProfileConfigurationsQualifiedName() { 98 return crossProfileConfigurationsAnnotationClass().getCanonicalName(); 99 } 100 101 @Override crossProfileProvider()102 public String crossProfileProvider() { 103 return crossProfileProviderAnnotationClass().getSimpleName(); 104 } 105 106 @Override crossProfileProviderAsAnnotation()107 public String crossProfileProviderAsAnnotation() { 108 return asAnnotation(crossProfileProvider()); 109 } 110 111 @Override crossProfileProviderAsAnnotation(String content)112 public String crossProfileProviderAsAnnotation(String content) { 113 return asAnnotationWithContent(crossProfileProvider(), content); 114 } 115 116 @Override crossProfileProviderQualifiedName()117 public String crossProfileProviderQualifiedName() { 118 return crossProfileProviderAnnotationClass().getCanonicalName(); 119 } 120 121 @Override crossProfileTest()122 public String crossProfileTest() { 123 return crossProfileTestAnnotationClass().getSimpleName(); 124 } 125 126 @Override crossProfileTestAsAnnotation(String content)127 public String crossProfileTestAsAnnotation(String content) { 128 return asAnnotationWithContent(crossProfileTest(), content); 129 } 130 131 @Override crossProfileTestQualifiedName()132 public String crossProfileTestQualifiedName() { 133 return crossProfileTestAnnotationClass().getCanonicalName(); 134 } 135 136 @Override toString()137 public final String toString() { 138 return crossProfile() + " AnnotationStrings"; 139 } 140 asAnnotation(String annotationName)141 private static String asAnnotation(String annotationName) { 142 return "@" + annotationName; 143 } 144 asAnnotationWithContent(String annotationName, String content)145 private static String asAnnotationWithContent(String annotationName, String content) { 146 return "@" + annotationName + "(" + content + ")"; 147 } 148 149 @Override crossProfileAnnotationClass()150 public abstract Class<? extends Annotation> crossProfileAnnotationClass(); 151 152 @Override crossProfileCallbackAnnotationClass()153 public abstract Class<? extends Annotation> crossProfileCallbackAnnotationClass(); 154 155 @Override crossProfileConfigurationAnnotationClass()156 public abstract Class<? extends Annotation> crossProfileConfigurationAnnotationClass(); 157 158 @Override crossProfileConfigurationsAnnotationClass()159 public abstract Class<? extends Annotation> crossProfileConfigurationsAnnotationClass(); 160 161 @Override crossProfileProviderAnnotationClass()162 public abstract Class<? extends Annotation> crossProfileProviderAnnotationClass(); 163 164 @Override crossProfileTestAnnotationClass()165 public abstract Class<? extends Annotation> crossProfileTestAnnotationClass(); 166 builder()167 static Builder builder() { 168 return new AutoValue_AnnotationStrings.Builder(); 169 } 170 171 @AutoValue.Builder 172 abstract static class Builder { setCrossProfileAnnotationClass(Class<? extends Annotation> value)173 abstract Builder setCrossProfileAnnotationClass(Class<? extends Annotation> value); 174 setCrossProfileCallbackAnnotationClass(Class<? extends Annotation> value)175 abstract Builder setCrossProfileCallbackAnnotationClass(Class<? extends Annotation> value); 176 setCrossProfileConfigurationAnnotationClass(Class<? extends Annotation> value)177 abstract Builder setCrossProfileConfigurationAnnotationClass(Class<? extends Annotation> value); 178 setCrossProfileConfigurationsAnnotationClass( Class<? extends Annotation> value)179 abstract Builder setCrossProfileConfigurationsAnnotationClass( 180 Class<? extends Annotation> value); 181 setCrossProfileProviderAnnotationClass(Class<? extends Annotation> value)182 abstract Builder setCrossProfileProviderAnnotationClass(Class<? extends Annotation> value); 183 setCrossProfileTestAnnotationClass(Class<? extends Annotation> value)184 abstract Builder setCrossProfileTestAnnotationClass(Class<? extends Annotation> value); 185 build()186 abstract AnnotationStrings build(); 187 } 188 } 189