xref: /aosp_15_r20/external/auto/value/src/test/java/com/google/auto/value/processor/GeneratedImport.java (revision 1c2bbba85eccddce6de79cbbf1645fda32e723f0)
1 /*
2  * Copyright 2017 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  * 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 package com.google.auto.value.processor;
17 
18 import javax.lang.model.SourceVersion;
19 
20 /**
21  * Utility methods for compile-testing tests to know which {@code @Generated} annotation is
22  * available.
23  */
24 final class GeneratedImport {
25 
26   /**
27    * Returns the qualified name of the {@code @Generated} annotation available during a compilation
28    * task.
29    */
generatedAnnotationType()30   static String generatedAnnotationType() {
31     return SourceVersion.latestSupported().compareTo(SourceVersion.RELEASE_8) > 0
32         ? "javax.annotation.processing.Generated"
33         : "javax.annotation.Generated";
34   }
35 
36   /**
37    * Returns an {@code import} statement that imports the {@code @Generated} annotation {@linkplain
38    * #generatedAnnotationType() available during a compilation task}.
39    */
importGeneratedAnnotationType()40   static String importGeneratedAnnotationType() {
41     return "import " + generatedAnnotationType() + ";";
42   }
43 }
44