use of org.jooq.meta.jaxb.GeneratedAnnotationType in project jOOQ by jOOQ.
the class JavaGenerator method printClassAnnotations.
protected void printClassAnnotations(JavaWriter out, Definition definition, Mode mode) {
if (generateGeneratedAnnotation()) {
SchemaDefinition schema = definition.getSchema();
CatalogDefinition catalog = definition.getCatalog();
// [#7581] The concrete annotation type depends on the JDK, with
// javax.annotation.Generated being deprecated in JDK 9
GeneratedAnnotationType type = generateGeneratedAnnotationType();
if (type == null)
type = GeneratedAnnotationType.DETECT_FROM_JDK;
String generated;
switch(type) {
case DETECT_FROM_JDK:
try {
// Seems more reliable than tampering with java.version
Reflect.onClass("java.util.Optional").call("of", new Object()).call("stream");
generated = "javax.annotation.processing.Generated";
} catch (ReflectException e) {
generated = "javax.annotation.Generated";
}
break;
case JAVAX_ANNOTATION_GENERATED:
generated = "javax.annotation.Generated";
break;
case JAVAX_ANNOTATION_PROCESSING_GENERATED:
generated = "javax.annotation.processing.Generated";
break;
default:
throw new IllegalStateException("Unsupported type: " + type);
}
out.println("@%s(", out.ref(generated));
if (useSchemaVersionProvider() || useCatalogVersionProvider()) {
boolean hasCatalogVersion = !StringUtils.isBlank(catalogVersions.get(catalog));
boolean hasSchemaVersion = !StringUtils.isBlank(schemaVersions.get(schema));
if (scala)
out.println("value = %s(", out.ref("scala.Array"));
else if (kotlin)
out.println("value = [");
else
out.println("value = {");
out.println("\"https://www.jooq.org\",");
out.println("\"jOOQ version:%s\"%s", Constants.VERSION, (hasCatalogVersion || hasSchemaVersion ? "," : ""));
if (hasCatalogVersion)
out.println("\"catalog version:%s\"%s", escapeString(catalogVersions.get(catalog)), (hasSchemaVersion ? "," : ""));
if (hasSchemaVersion)
out.println("\"schema version:%s\"", escapeString(schemaVersions.get(schema)));
if (scala)
out.println("),");
else if (kotlin)
out.println("],");
else
out.println("},");
if (generateGeneratedAnnotationDate())
out.println("date = \"" + isoDate + "\",");
out.println("comments = \"This class is generated by jOOQ\"");
} else {
if (scala)
out.println("value = %s(", out.ref("scala.Array"));
else if (kotlin)
out.println("value = [");
else
out.println("value = {");
out.println("\"https://www.jooq.org\",");
out.println("\"jOOQ version:%s\"", Constants.VERSION);
if (scala)
out.println("),");
else if (kotlin)
out.println("],");
else
out.println("},");
out.println("comments = \"This class is generated by jOOQ\"");
}
out.println(")");
}
if (scala) {
} else if (kotlin)
out.println("@Suppress(\"UNCHECKED_CAST\")");
else
out.println("@%s({ \"all\", \"unchecked\", \"rawtypes\" })", out.ref("java.lang.SuppressWarnings"));
}
Aggregations