|
21 | 21 | import java.io.IOException; |
22 | 22 | import java.util.Formatter; |
23 | 23 |
|
24 | | -import javax.annotation.Generated; |
25 | 24 | import javax.annotation.processing.Filer; |
26 | 25 | import javax.annotation.processing.ProcessingEnvironment; |
27 | 26 | import javax.lang.model.element.TypeElement; |
| 27 | +import javax.lang.model.type.TypeMirror; |
| 28 | +import javax.lang.model.util.Elements; |
28 | 29 | import javax.tools.JavaFileObject; |
29 | 30 |
|
30 | 31 | import org.seasar.doma.internal.Artifact; |
@@ -111,9 +112,15 @@ protected String getQualifiedNamePrefix(ProcessingEnvironment env, |
111 | 112 | } |
112 | 113 |
|
113 | 114 | protected void printGenerated() { |
114 | | - iprint("@%s(value = { \"%s\", \"%s\" }, date = \"%tFT%<tT.%<tL%<tz\")%n", |
115 | | - Generated.class.getName(), Artifact.getName(), |
116 | | - Options.getVersion(env), Options.getDate(env)); |
| 115 | + String annotationElements = String.format( |
| 116 | + "value = { \"%s\", \"%s\" }, date = \"%tFT%<tT.%<tL%<tz\"", |
| 117 | + Artifact.getName(), Options.getVersion(env), |
| 118 | + Options.getDate(env)); |
| 119 | + TypeMirror generatedTypeMirror = getGeneratedTypeMirror(); |
| 120 | + if (generatedTypeMirror == null) { |
| 121 | + iprint("// %s%n", annotationElements); |
| 122 | + } |
| 123 | + iprint("@%s(%s)%n", generatedTypeMirror, annotationElements); |
117 | 124 | } |
118 | 125 |
|
119 | 126 | protected void printValidateVersionStaticInitializer() { |
@@ -165,4 +172,19 @@ public void close() { |
165 | 172 | } |
166 | 173 | } |
167 | 174 |
|
| 175 | + private TypeMirror getGeneratedTypeMirror() { |
| 176 | + Elements elements = env.getElementUtils(); |
| 177 | + TypeElement java8 = elements |
| 178 | + .getTypeElement("javax.annotation.Generated"); |
| 179 | + if (java8 != null) { |
| 180 | + return java8.asType(); |
| 181 | + } |
| 182 | + TypeElement java9 = elements |
| 183 | + .getTypeElement("javax.annotation.processing.Generated"); |
| 184 | + if (java9 != null) { |
| 185 | + return java9.asType(); |
| 186 | + } |
| 187 | + return null; |
| 188 | + } |
| 189 | + |
168 | 190 | } |
0 commit comments