branch feature/308-generated-annotation-configuration created (now 658ab7d2)
This is an automated email from the git hooks/post-receive script. New change to branch feature/308-generated-annotation-configuration in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git at 658ab7d2 refs #308: Add configuration for @Generated annotation This branch includes the following new commits: new 658ab7d2 refs #308: Add configuration for @Generated annotation The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 658ab7d2fb02b1052468d92ca1513b571069568b Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Dec 10 09:57:12 2019 +0100 refs #308: Add configuration for @Generated annotation -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/308-generated-annotation-configuration in repository eugene. See https://gitlab.nuiton.org/nuiton/eugene.git commit 658ab7d2fb02b1052468d92ca1513b571069568b Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Dec 10 09:57:12 2019 +0100 refs #308: Add configuration for @Generated annotation --- .../org/nuiton/eugene/EugeneCoreTagValues.java | 25 +++++++++++++++++++++- .../eugene/java/ObjectModelTransformerToJava.java | 23 +++++++++++--------- .../main/resources/i18n/eugene_en_GB.properties | 1 + .../main/resources/i18n/eugene_fr_FR.properties | 1 + 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/eugene/src/main/java/org/nuiton/eugene/EugeneCoreTagValues.java b/eugene/src/main/java/org/nuiton/eugene/EugeneCoreTagValues.java index f91e40ef..c53a7ddf 100644 --- a/eugene/src/main/java/org/nuiton/eugene/EugeneCoreTagValues.java +++ b/eugene/src/main/java/org/nuiton/eugene/EugeneCoreTagValues.java @@ -92,7 +92,7 @@ public class EugeneCoreTagValues extends DefaultTagValueMetadatasProvider { constantPrefix(n("eugene.core.tagValues.constantPrefix"), String.class, "PROPERTY_", ObjectModel.class, ObjectModelPackage.class, ObjectModelClassifier.class), /** - * Tag value to specify the i18n prefix to use whene generating i18n keys. + * Tag value to specify the i18n prefix to use where generating i18n keys. * * You can globaly use it on the complete model or to a specific classifier. * @@ -100,6 +100,15 @@ public class EugeneCoreTagValues extends DefaultTagValueMetadatasProvider { */ i18n(n("eugene.core.tagValues.i18n"), String.class, null, ObjectModel.class, ObjectModelPackage.class, ObjectModelClassifier.class), + /** + * Tag value to specify the @Generated annotation class name. + * + * You can globaly use it on the complete model or to a specific classifier. + * + * @since 3.0 + */ + generatedAnnotation(n("eugene.core.tagValues.generatedAnnotation"), String.class, null, ObjectModel.class, ObjectModelPackage.class, ObjectModelClassifier.class), + /** * Tag value to generate also {@code getXXX} methods for a boolean property. * @@ -240,6 +249,20 @@ public class EugeneCoreTagValues extends DefaultTagValueMetadatasProvider { return TagValueUtil.findTagValue(Store.i18n, element, aPackage, model); } + /** + * Cherche et renvoie le préfixe i18n à utiliser sur cet element, sinon sur + * le model. + * + * @param element element to seek + * @param aPackage package to seek + * @param model model to seek + * @return le préfixe i18n ou <code>null</code> si non spécifié + * @since 2.3 + */ + public String getGeneratedAnnotationTagValue(ObjectModelElement element, ObjectModelPackage aPackage, ObjectModel model) { + return TagValueUtil.findTagValue(Store.generatedAnnotation, element, aPackage, model); + } + /** * Obtain the value of the {@link Store#generateBooleanGetMethods} * tag value on the given model, package or classifier. diff --git a/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java b/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java index dd127c27..9566f505 100644 --- a/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java +++ b/eugene/src/main/java/org/nuiton/eugene/java/ObjectModelTransformerToJava.java @@ -47,7 +47,6 @@ import org.nuiton.eugene.models.object.ObjectModelTransformer; import org.nuiton.eugene.models.object.ObjectModelType; import org.nuiton.i18n.I18n; -import javax.annotation.Generated; import java.beans.Introspector; import java.net.URL; import java.util.Collection; @@ -121,19 +120,21 @@ public abstract class ObjectModelTransformerToJava extends ObjectModelTransforme } /** - * Add the {@link Generated} annotation to the given {@link ObjectModelClassifier} + * Add the {@code Generated} annotation to the given {@link ObjectModelClassifier} * * @param element the element to be generated on which the annotation will be added * @since 2.7 */ - // TODO AThimel 06/07/13 Maybe be skipped by configuration ? protected void addGeneratedAnnotation(ObjectModelClassifier element) { - - String generatorName = getClass().getName(); - Date now = new Date(); - ObjectModelAnnotation annotation = addAnnotation(element, element, Generated.class); - addAnnotationParameter(element, annotation, "value", generatorName); - addAnnotationParameter(element, annotation, "date", now.toString()); + ObjectModelPackage aPackage = getPackage(element); + String generatedAnnotation = eugeneTagValues.getGeneratedAnnotationTagValue(element, aPackage, model); + if (generatedAnnotation != null) { + String generatorName = getClass().getName(); + Date now = new Date(); + ObjectModelAnnotation annotation = addAnnotation(element, element, generatedAnnotation); + addAnnotationParameter(element, annotation, "value", generatorName); + addAnnotationParameter(element, annotation, "date", now.toString()); + } } protected ObjectModelClass createClass(String name, String packageName) { @@ -444,7 +445,9 @@ public abstract class ObjectModelTransformerToJava extends ObjectModelTransforme public ObjectModelAnnotation addAnnotation(ObjectModelClassifier classifier, ObjectModelElement element, String annotationType) { - return builder.addAnnotation(classifier, element, annotationType); + addImport(classifier, annotationType); + String simpleClassName = GeneratorUtil.getClassNameFromQualifiedName(annotationType); + return builder.addAnnotation(classifier, element, simpleClassName); } /** diff --git a/eugene/src/main/resources/i18n/eugene_en_GB.properties b/eugene/src/main/resources/i18n/eugene_en_GB.properties index 9360a93c..2048ca46 100644 --- a/eugene/src/main/resources/i18n/eugene_en_GB.properties +++ b/eugene/src/main/resources/i18n/eugene_en_GB.properties @@ -2,6 +2,7 @@ eugene.core.tagValues.attributeGeneric=Generic type of attribute eugene.core.tagValues.constantPrefix=Constant field prefix eugene.core.tagValues.documentation=Documentation eugene.core.tagValues.generateBooleanGetMethods=Generate getter on Boolean +eugene.core.tagValues.generatedAnnotation=@Generated annotation class name eugene.core.tagValues.i18n=I18n prefix eugene.core.tagValues.ordered=Is attribute ordererd ? eugene.core.tagValues.skip=Skip generation diff --git a/eugene/src/main/resources/i18n/eugene_fr_FR.properties b/eugene/src/main/resources/i18n/eugene_fr_FR.properties index d1594f2b..8fe8d868 100644 --- a/eugene/src/main/resources/i18n/eugene_fr_FR.properties +++ b/eugene/src/main/resources/i18n/eugene_fr_FR.properties @@ -2,6 +2,7 @@ eugene.core.tagValues.attributeGeneric=Type générique de l'attribut eugene.core.tagValues.constantPrefix=Préfixe des constantes eugene.core.tagValues.documentation=Documentation eugene.core.tagValues.generateBooleanGetMethods=Génerer les getters sur le type Boolean +eugene.core.tagValues.generatedAnnotation=@Generated annotation class name eugene.core.tagValues.i18n=Préfix i18n eugene.core.tagValues.ordered=L'attribut est-il ordonné ? eugene.core.tagValues.skip=Ne pas générer -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm