mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#2155 - QueryBeans: Change to use own @Generated with retention RUNTIME
This commit is contained in:
1 parent
74d907bbce
commit
2672dff512
9 files changed
+35
-85
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
package io.ebean.typequery;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks generated query bean source code.
|
||||||
|
* <p>
|
||||||
|
* This is code generated by the query bean generator (annotation processor).
|
||||||
|
*/
|
||||||
|
@Target({ ElementType.TYPE })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Generated {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the generator used to generate this source.
|
||||||
|
*/
|
||||||
|
String value();
|
||||||
|
|
||||||
|
}
|
||||||
+1
-4
@@ -3,11 +3,8 @@ package io.ebean.querybean.generator;
|
|||||||
interface Constants {
|
interface Constants {
|
||||||
|
|
||||||
String AT_GENERATED = "@Generated(\"io.ebean.querybean.kotlin-generator\")";
|
String AT_GENERATED = "@Generated(\"io.ebean.querybean.kotlin-generator\")";
|
||||||
|
|
||||||
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
||||||
|
String GENERATED = "io.ebean.typequery.Generated";
|
||||||
String GENERATED_9 = "javax.annotation.processing.Generated";
|
|
||||||
String GENERATED_8 = "javax.annotation.Generated";
|
|
||||||
|
|
||||||
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
||||||
String INHERITANCE = "javax.persistence.Inheritance";
|
String INHERITANCE = "javax.persistence.Inheritance";
|
||||||
|
|||||||
-19
@@ -50,7 +50,6 @@ class ProcessingContext implements Constants {
|
|||||||
private final Filer filer;
|
private final Filer filer;
|
||||||
private final Messager messager;
|
private final Messager messager;
|
||||||
private final Elements elementUtils;
|
private final Elements elementUtils;
|
||||||
private final String generatedAnnotation;
|
|
||||||
|
|
||||||
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
||||||
|
|
||||||
@@ -99,9 +98,6 @@ class ProcessingContext implements Constants {
|
|||||||
this.filer = processingEnv.getFiler();
|
this.filer = processingEnv.getFiler();
|
||||||
this.messager = processingEnv.getMessager();
|
this.messager = processingEnv.getMessager();
|
||||||
this.elementUtils = processingEnv.getElementUtils();
|
this.elementUtils = processingEnv.getElementUtils();
|
||||||
|
|
||||||
boolean jdk8 = processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
|
|
||||||
this.generatedAnnotation = generatedAnnotation(jdk8);
|
|
||||||
this.generatedSources = initGeneratedSources(processingEnv);
|
this.generatedSources = initGeneratedSources(processingEnv);
|
||||||
this.readModuleInfo = new ReadModuleInfo(this);
|
this.readModuleInfo = new ReadModuleInfo(this);
|
||||||
}
|
}
|
||||||
@@ -122,13 +118,6 @@ class ProcessingContext implements Constants {
|
|||||||
return elementUtils.getTypeElement(EBEAN_COMPONENT);
|
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) {
|
private String initGeneratedSources(ProcessingEnvironment processingEnv) {
|
||||||
String generatedDir = processingEnv.getOptions().get("kapt.kotlin.generated");
|
String generatedDir = processingEnv.getOptions().get("kapt.kotlin.generated");
|
||||||
return (generatedDir != null) ? generatedDir : "target/generated-sources/kapt/compile";
|
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));
|
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isGeneratedAvailable() {
|
|
||||||
return generatedAnnotation != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGeneratedAnnotation() {
|
|
||||||
return generatedAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void readModuleInfo() {
|
void readModuleInfo() {
|
||||||
String factory = loadMetaInfServices();
|
String factory = loadMetaInfServices();
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
|
|||||||
+2
-7
@@ -90,10 +90,7 @@ class SimpleModuleInfoWriter {
|
|||||||
writer.append("import java.util.ArrayList;").eol();
|
writer.append("import java.util.ArrayList;").eol();
|
||||||
writer.append("import java.util.Collections;").eol();
|
writer.append("import java.util.Collections;").eol();
|
||||||
writer.append("import java.util.List;").eol();
|
writer.append("import java.util.List;").eol();
|
||||||
final String generated = processingContext.getGeneratedAnnotation();
|
writer.append("import %s;", Constants.GENERATED).eol();
|
||||||
if (generated != null) {
|
|
||||||
writer.append("import %s;", generated).eol();
|
|
||||||
}
|
|
||||||
writer.eol();
|
writer.eol();
|
||||||
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
||||||
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
||||||
@@ -102,9 +99,7 @@ class SimpleModuleInfoWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buildAtContextModule(Append writer) {
|
void buildAtContextModule(Append writer) {
|
||||||
if (processingContext.isGeneratedAvailable()) {
|
writer.append(Constants.AT_GENERATED).eol();
|
||||||
writer.append(Constants.AT_GENERATED).eol();
|
|
||||||
}
|
|
||||||
writer.append("@ModuleInfo(");
|
writer.append("@ModuleInfo(");
|
||||||
if (processingContext.hasOtherClasses()) {
|
if (processingContext.hasOtherClasses()) {
|
||||||
writer.append("other={%s}, ", otherClasses());
|
writer.append("other={%s}, ", otherClasses());
|
||||||
|
|||||||
+3
-11
@@ -88,11 +88,7 @@ class SimpleQueryBeanWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void gatherPropertyDetails() {
|
private void gatherPropertyDetails() {
|
||||||
|
importTypes.add(Constants.GENERATED);
|
||||||
final String generated = processingContext.getGeneratedAnnotation();
|
|
||||||
if (generated != null) {
|
|
||||||
importTypes.add(generated);
|
|
||||||
}
|
|
||||||
importTypes.add(beanFullName);
|
importTypes.add(beanFullName);
|
||||||
importTypes.add(Constants.TQROOTBEAN);
|
importTypes.add(Constants.TQROOTBEAN);
|
||||||
importTypes.add(Constants.TYPEQUERYBEAN);
|
importTypes.add(Constants.TYPEQUERYBEAN);
|
||||||
@@ -282,9 +278,7 @@ class SimpleQueryBeanWriter {
|
|||||||
writer.append(" * ").eol();
|
writer.append(" * ").eol();
|
||||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||||
writer.append(" */").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();
|
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||||
lang().beginAssocClass(writer, shortName, origShortName);
|
lang().beginAssocClass(writer, shortName, origShortName);
|
||||||
|
|
||||||
@@ -294,9 +288,7 @@ class SimpleQueryBeanWriter {
|
|||||||
writer.append(" * ").eol();
|
writer.append(" * ").eol();
|
||||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||||
writer.append(" */").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();
|
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||||
lang().beginClass(writer, shortName);
|
lang().beginClass(writer, shortName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ interface Constants {
|
|||||||
String AT_GENERATED = "@Generated(\"io.ebean.querybean.generator\")";
|
String AT_GENERATED = "@Generated(\"io.ebean.querybean.generator\")";
|
||||||
|
|
||||||
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
String AT_TYPEQUERYBEAN = "@TypeQueryBean(\"v1\")";
|
||||||
|
String GENERATED = "io.ebean.typequery.Generated";
|
||||||
String GENERATED_9 = "javax.annotation.processing.Generated";
|
|
||||||
String GENERATED_8 = "javax.annotation.Generated";
|
|
||||||
|
|
||||||
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
String MAPPED_SUPERCLASS = "javax.persistence.MappedSuperclass";
|
||||||
String INHERITANCE = "javax.persistence.Inheritance";
|
String INHERITANCE = "javax.persistence.Inheritance";
|
||||||
@@ -35,4 +33,4 @@ interface Constants {
|
|||||||
String METAINF_MANIFEST = "META-INF/ebean-generated-info.mf";
|
String METAINF_MANIFEST = "META-INF/ebean-generated-info.mf";
|
||||||
String METAINF_SERVICES_MODULELOADER = "META-INF/services/io.ebean.config.ModuleInfoLoader";
|
String METAINF_SERVICES_MODULELOADER = "META-INF/services/io.ebean.config.ModuleInfoLoader";
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,6 @@ class ProcessingContext implements Constants {
|
|||||||
private final Filer filer;
|
private final Filer filer;
|
||||||
private final Messager messager;
|
private final Messager messager;
|
||||||
private final Elements elementUtils;
|
private final Elements elementUtils;
|
||||||
private final String generatedAnnotation;
|
|
||||||
|
|
||||||
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
private final PropertyTypeMap propertyTypeMap = new PropertyTypeMap();
|
||||||
|
|
||||||
@@ -95,9 +94,6 @@ class ProcessingContext implements Constants {
|
|||||||
this.filer = processingEnv.getFiler();
|
this.filer = processingEnv.getFiler();
|
||||||
this.messager = processingEnv.getMessager();
|
this.messager = processingEnv.getMessager();
|
||||||
this.elementUtils = processingEnv.getElementUtils();
|
this.elementUtils = processingEnv.getElementUtils();
|
||||||
|
|
||||||
boolean jdk8 = processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
|
|
||||||
this.generatedAnnotation = generatedAnnotation(jdk8);
|
|
||||||
this.readModuleInfo = new ReadModuleInfo(this);
|
this.readModuleInfo = new ReadModuleInfo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,17 +113,6 @@ class ProcessingContext implements Constants {
|
|||||||
return elementUtils.getTypeElement(EBEAN_COMPONENT);
|
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 boolean isTypeAvailable(String canonicalName) {
|
|
||||||
return null != elementUtils.getTypeElement(canonicalName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather all the fields (properties) for the given bean element.
|
* Gather all the fields (properties) for the given bean element.
|
||||||
*/
|
*/
|
||||||
@@ -413,14 +398,6 @@ class ProcessingContext implements Constants {
|
|||||||
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
|
messager.printMessage(Diagnostic.Kind.NOTE, String.format(msg, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isGeneratedAvailable() {
|
|
||||||
return generatedAnnotation != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGeneratedAnnotation() {
|
|
||||||
return generatedAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
void readModuleInfo() {
|
void readModuleInfo() {
|
||||||
String factory = loadMetaInfServices();
|
String factory = loadMetaInfServices();
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
|
|||||||
+2
-7
@@ -89,10 +89,7 @@ class SimpleModuleInfoWriter {
|
|||||||
writer.append("import java.util.ArrayList;").eol();
|
writer.append("import java.util.ArrayList;").eol();
|
||||||
writer.append("import java.util.Collections;").eol();
|
writer.append("import java.util.Collections;").eol();
|
||||||
writer.append("import java.util.List;").eol();
|
writer.append("import java.util.List;").eol();
|
||||||
final String generated = processingContext.getGeneratedAnnotation();
|
writer.append("import %s;", Constants.GENERATED).eol();
|
||||||
if (generated != null) {
|
|
||||||
writer.append("import %s;", generated).eol();
|
|
||||||
}
|
|
||||||
writer.eol();
|
writer.eol();
|
||||||
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
writer.append("import io.ebean.config.ModuleInfo;").eol();
|
||||||
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
writer.append("import io.ebean.config.ModuleInfoLoader;").eol();
|
||||||
@@ -100,9 +97,7 @@ class SimpleModuleInfoWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void buildAtContextModule(Append writer) {
|
void buildAtContextModule(Append writer) {
|
||||||
if (processingContext.isGeneratedAvailable()) {
|
writer.append(Constants.AT_GENERATED).eol();
|
||||||
writer.append(Constants.AT_GENERATED).eol();
|
|
||||||
}
|
|
||||||
writer.append("@ModuleInfo(");
|
writer.append("@ModuleInfo(");
|
||||||
if (processingContext.hasOtherClasses()) {
|
if (processingContext.hasOtherClasses()) {
|
||||||
writer.append("other={%s}, ", otherClasses());
|
writer.append("other={%s}, ", otherClasses());
|
||||||
|
|||||||
+3
-10
@@ -62,10 +62,7 @@ class SimpleQueryBeanWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void gatherPropertyDetails() {
|
private void gatherPropertyDetails() {
|
||||||
final String generated = processingContext.getGeneratedAnnotation();
|
importTypes.add(Constants.GENERATED);
|
||||||
if (generated != null) {
|
|
||||||
importTypes.add(generated);
|
|
||||||
}
|
|
||||||
importTypes.add(beanFullName);
|
importTypes.add(beanFullName);
|
||||||
importTypes.add(Constants.TQROOTBEAN);
|
importTypes.add(Constants.TQROOTBEAN);
|
||||||
importTypes.add(Constants.TYPEQUERYBEAN);
|
importTypes.add(Constants.TYPEQUERYBEAN);
|
||||||
@@ -301,9 +298,7 @@ class SimpleQueryBeanWriter {
|
|||||||
writer.append(" * ").eol();
|
writer.append(" * ").eol();
|
||||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||||
writer.append(" */").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();
|
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||||
writer.append("public class Q%s<R> extends TQAssocBean<%s,R> {", shortName, origShortName).eol();
|
writer.append("public class Q%s<R> extends TQAssocBean<%s,R> {", shortName, origShortName).eol();
|
||||||
|
|
||||||
@@ -313,9 +308,7 @@ class SimpleQueryBeanWriter {
|
|||||||
writer.append(" * ").eol();
|
writer.append(" * ").eol();
|
||||||
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
|
||||||
writer.append(" */").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();
|
writer.append(Constants.AT_TYPEQUERYBEAN).eol();
|
||||||
writer.append("public class Q%s extends TQRootBean<%1$s,Q%1$s> {", shortName).eol();
|
writer.append("public class Q%s extends TQRootBean<%1$s,Q%1$s> {", shortName).eol();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user