From 9ed13bea8f0ba4051e45a3ff698d955ad95d6763 Mon Sep 17 00:00:00 2001 From: waiet Date: Fri, 31 May 2019 13:29:22 +0200 Subject: [PATCH 1/3] Optimization logging of removing annotate for class, that not include this annotate. --- .../plugin/removeannotation/RemoveAnnotationPlugin.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java index 600cee6..bb28140 100644 --- a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java +++ b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java @@ -364,6 +364,9 @@ private void removeAnnotation(final JCodeModel codeModel, } } else { + if (annotatable.annotations() == null || annotatable.annotations().isEmpty()) { + return; + } JClass annotationClass = codeModel.ref(aClass); JAnnotationUse annotationUse = null; From 633b1a049d71ee49fd0768bee136a7cce592f67b Mon Sep 17 00:00:00 2001 From: waiet Date: Tue, 11 Jun 2019 15:45:41 +0200 Subject: [PATCH 2/3] Remove annotations for impl classes --- .../RemoveAnnotationPlugin.java | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java index bb28140..fe871ae 100644 --- a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java +++ b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java @@ -33,11 +33,19 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; import javax.xml.namespace.QName; +import com.sun.codemodel.JAnnotatable; +import com.sun.codemodel.JAnnotationUse; +import com.sun.codemodel.JClass; +import com.sun.codemodel.JCodeModel; +import com.sun.codemodel.JFieldVar; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.tools.ant.util.CollectionUtils; import org.jvnet.annox.Constants; import org.jvnet.jaxb2_commons.plugin.AbstractParameterizablePlugin; import org.jvnet.jaxb2_commons.plugin.AnnotationTarget; @@ -47,10 +55,6 @@ import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import com.sun.codemodel.JAnnotatable; -import com.sun.codemodel.JAnnotationUse; -import com.sun.codemodel.JClass; -import com.sun.codemodel.JCodeModel; import com.sun.tools.xjc.Options; import com.sun.tools.xjc.model.CCustomizations; import com.sun.tools.xjc.model.CElementInfo; @@ -194,6 +198,14 @@ protected void processClassOutline(ClassOutline classOutline, for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) { processFieldOutline(classOutline, fieldOutline, options, errorHandler); + + } + + if (classOutline.getImplClass() != null) { + for (final Map.Entry entry : classOutline.getImplClass().fields().entrySet()) { + processFieldImplOutline(classOutline, entry.getValue(), options, + errorHandler); + } } } @@ -207,6 +219,18 @@ protected void processFieldOutline(ClassOutline classOutline, customizations, errorHandler); } + protected void processFieldImplOutline(ClassOutline classOutline, + JFieldVar fieldOutlineImpl, Options options, + ErrorHandler errorHandler) { + + if(ArrayUtils.isNotEmpty(classOutline.getDeclaredFields())){ + final CCustomizations customizations = CustomizationUtils + .getCustomizations(classOutline.getDeclaredFields()[0]); + removeAnnotationFromFieldImplOutline(classOutline.ref.owner(), fieldOutlineImpl, + customizations, errorHandler); + } + } + protected void processEnumConstantOutline(EnumOutline enumOutline, EnumConstantOutline enumConstantOutline, Options options, ErrorHandler errorHandler) { @@ -311,6 +335,10 @@ protected void removeAnnotationFromClassOutline(final JCodeModel codeModel, .getAnnotatable(classOutline.parent(), classOutline); removeAnnotation(codeModel, errorHandler, customization, element, annotatable); + if (classOutline.getImplClass() != null) { + removeAnnotation(codeModel, errorHandler, customization, element, + classOutline.getImplClass()); + } } catch (IllegalArgumentException iaex) { logger.error("Error applying the annotation.", iaex); } @@ -345,7 +373,30 @@ protected void removeAnnotationFromFieldOutline(final JCodeModel codeModel, } } } + protected void removeAnnotationFromFieldImplOutline(final JCodeModel codeModel, + final JFieldVar fieldOutline, + final CCustomizations customizations, ErrorHandler errorHandler) { + for (final CPluginCustomization customization : customizations) { + final Element element = customization.element; + final QName name = new QName(element.getNamespaceURI(), + element.getLocalName()); + if (isCustomizationElementName(name)) { + customization.markAsAcknowledged(); + + final AnnotationTarget annotationTarget = AnnotationTarget + .getAnnotationTarget(element, AnnotationTarget + .getAnnotationTarget(getDefaultFieldTarget())); + try { + removeAnnotation(codeModel, errorHandler, customization, element, + fieldOutline); + } catch (IllegalArgumentException iaex) { + logger.error("Error removing the annotation.", iaex); + } + + } + } + } private void removeAnnotation(final JCodeModel codeModel, ErrorHandler errorHandler, final CPluginCustomization customization, From 3e21a15a11a4ba5d7c6bc28e9bb433e474f0d54e Mon Sep 17 00:00:00 2001 From: waiet <00wlado@azet.sk> Date: Tue, 11 Jun 2019 15:47:42 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"Optimization=20logging=20of=20rem?= =?UTF-8?q?oving=20annotate=20for=20class,=20that=20not=20include=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/removeannotation/RemoveAnnotationPlugin.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java index bb28140..600cee6 100644 --- a/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java +++ b/plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/removeannotation/RemoveAnnotationPlugin.java @@ -364,9 +364,6 @@ private void removeAnnotation(final JCodeModel codeModel, } } else { - if (annotatable.annotations() == null || annotatable.annotations().isEmpty()) { - return; - } JClass annotationClass = codeModel.ref(aClass); JAnnotationUse annotationUse = null;