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; 17 18 import com.google.android.enterprise.connectedapps.processor.annotationdiscovery.AnnotationNames; 19 20 /** Formats annotation validation messages with the provided names of the annotation set. */ 21 public final class ValidationMessageFormatter { 22 23 private final AnnotationNames annotationNames; 24 forAnnotations(AnnotationNames annotationNames)25 public static ValidationMessageFormatter forAnnotations(AnnotationNames annotationNames) { 26 return new ValidationMessageFormatter(annotationNames); 27 } 28 ValidationMessageFormatter(AnnotationNames annotationNames)29 private ValidationMessageFormatter(AnnotationNames annotationNames) { 30 this.annotationNames = annotationNames; 31 } 32 33 /** 34 * Supports the replacement strings CROSS_PROFILE_ANNOTATION, CROSS_PROFILE_CALLBACK_ANNOTATION, 35 * CROSS_PROFILE_CONFIGURATION_ANNOTATION, CROSS_PROFILE_CONFIGURATIONS_ANNOTATION, 36 * CROSS_PROFILE_PROVIDER_ANNOTATION, and CROSS_PROFILE_TEST_ANNOTATION. 37 */ format(String message)38 String format(String message) { 39 return message 40 .replace("CROSS_PROFILE_ANNOTATION", annotationNames.crossProfile()) 41 .replace("CROSS_PROFILE_CALLBACK_ANNOTATION", annotationNames.crossProfileCallback()) 42 .replace( 43 "CROSS_PROFILE_CONFIGURATION_ANNOTATION", annotationNames.crossProfileConfiguration()) 44 .replace( 45 "CROSS_PROFILE_CONFIGURATIONS_ANNOTATION", annotationNames.crossProfileConfigurations()) 46 .replace("CROSS_PROFILE_PROVIDER_ANNOTATION", annotationNames.crossProfileProvider()) 47 .replace("CROSS_PROFILE_TEST_ANNOTATION", annotationNames.crossProfileTest()); 48 } 49 } 50