#2155 - QueryBeans: Change to use own @Generated with retention RUNTIME

This commit is contained in:
Robin Bygrave committed 2021-02-10 15:28:55 +13:00
1 parent 74d907bbce
commit 2672dff512
9 files changed
+35 -85

No files matched your search

@@ -3,11 +3,8 @@ package io.ebean.querybean.generator;
interface Constants {
String AT_GENERATED = "@Generated(\"io.ebean.querybean.kotlin-generator\")";
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
String GENERATED_9 = "javax.annotation.processing.Generated";
String GENERATED_8 = "javax.annotation.Generated";
String GENERATED = "io.ebean.typequery.Generated";
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
String INHERITANCE = "javax.persistence.Inheritance";
@@ -50,7 +50,6 @@ class ProcessingContext implements Constants {
private final Filer filer;
private final Messager messager;
private final Elements elementUtils;
private final String generatedAnnotation;
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
@@ -99,9 +98,6 @@ class ProcessingContext implements Constants {
this.filer = processingEnv.getFiler();
this.messager = processingEnv.getMessager();
this.elementUtils = processingEnv.getElementUtils();
boolean jdk8 = processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
this.generatedAnnotation = generatedAnnotation(jdk8);
this.generatedSources = initGeneratedSources(processingEnv);
this.readModuleInfo = new ReadModuleInfo(this);
}
@@ -122,13 +118,6 @@ class ProcessingContext implements Constants {
return elementUtils.getTypeElement(EBEAN_COMPONENT);
}
private String generatedAnnotation(boolean jdk8) {
if (jdk8) {
return isTypeAvailable(GENERATED_8) ? GENERATED_8 : null;
}
return isTypeAvailable(GENERATED_9) ? GENERATED_9 : null;
}
private String initGeneratedSources(ProcessingEnvironment processingEnv) {
String generatedDir = processingEnv.getOptions().get("kapt.kotlin.generated");
return (generatedDir != null) ? generatedDir : "target/generated-sources/kapt/compile";
@@ -430,14 +419,6 @@ class ProcessingContext implements Constants {
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
}
boolean isGeneratedAvailable() {
return generatedAnnotation != null;
}
String getGeneratedAnnotation() {
return generatedAnnotation;
}
void readModuleInfo() {
String factory = loadMetaInfServices();
if (factory != null) {
@@ -90,10 +90,7 @@ class SimpleModuleInfoWriter {
writer.append("import java.util.ArrayList;").eol();
writer.append("import java.util.Collections;").eol();
writer.append("import java.util.List;").eol();
final String generated = processingContext.getGeneratedAnnotation();
if (generated != null) {
writer.append("import %s;", generated).eol();
}
writer.append("import %s;", Constants.GENERATED).eol();
writer.eol();
writer.append("import io.ebean.config.ModuleInfo;").eol();
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
@@ -102,9 +99,7 @@ class SimpleModuleInfoWriter {
}
void buildAtContextModule(Append writer) {
if (processingContext.isGeneratedAvailable()) {
writer.append(Constants.AT_GENERATED).eol();
}
writer.append(Constants.AT_GENERATED).eol();
writer.append("@ModuleInfo(");
if (processingContext.hasOtherClasses()) {
writer.append("other={%s}, ", otherClasses());
@@ -88,11 +88,7 @@ class SimpleQueryBeanWriter {
}
private void gatherPropertyDetails() {
final String generated = processingContext.getGeneratedAnnotation();
if (generated != null) {
importTypes.add(generated);
}
importTypes.add(Constants.GENERATED);
importTypes.add(beanFullName);
importTypes.add(Constants.TQROOTBEAN);
importTypes.add(Constants.TYPEQUERYBEAN);
@@ -282,9 +278,7 @@ class SimpleQueryBeanWriter {
writer.append(" * ").eol();
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
writer.append(" */").eol();
if (processingContext.isGeneratedAvailable()) {
writer.append(Constants.AT_GENERATED).eol();
}
writer.append(Constants.AT_GENERATED).eol();
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
lang().beginAssocClass(writer, shortName, origShortName);
@@ -294,9 +288,7 @@ class SimpleQueryBeanWriter {
writer.append(" * ").eol();
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
writer.append(" */").eol();
if (processingContext.isGeneratedAvailable()) {
writer.append(Constants.AT_GENERATED).eol();
}
writer.append(Constants.AT_GENERATED).eol();
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
lang().beginClass(writer, shortName);
}