Skip to content

Commit feac076

Browse files
digitalfoghighsource
authored andcommitted
Prepared fix for #11.
1 parent ef51e96 commit feac076

File tree

20 files changed

+469
-12
lines changed

20 files changed

+469
-12
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ You can put your annotations directly in schema:
6161
</xsd:sequence>
6262
</xsd:complexType>
6363

64+
<xs:simpleType name="FooEnum">
65+
<xs:annotation>
66+
<xs:appinfo>
67+
<annox:annotateEnumValueMethod>@java.lang.Deprecated</annox:annotateEnumValueMethod>
68+
</xs:appinfo>
69+
</xs:annotation>
70+
71+
<xs:restriction base="xs:string">
72+
<xs:enumeration value="BAR"/>
73+
<xs:enumeration value="BAZ"/>
74+
</xs:restriction>
75+
</xs:simpleType>
76+
6477
</xsd:schema>
6578
````
6679

@@ -97,12 +110,16 @@ You can use the following customization elements in the `http://annox.dev.java.n
97110
* `setter`
98111
* `setter-parameter`
99112
* `field`
113+
* `enum-value-method`
114+
* `enum-fromValue-method`
100115
* `annotateProperty`
101116
* `annotatePackage`
102117
* `annotateClass`
103118
* `annotateElement`
104119
* `annotateEnum`
105120
* `annotateEnumConstant`
121+
* `annotateEnumValueMethod` - place annotation above `value()` method
122+
* `annotateEnumFromValueMethod` - place annotation above `fromValue(String)` method
106123

107124
The `http://annox.dev.java.net` namespace must be declared in the `jaxb:extensionBindingPrefixes` attribute via prefix, ex.:
108125

plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</dependency>
6060
<dependency>
6161
<groupId>com.sun.xml.bind</groupId>
62-
<artifactId>jaxb-impl</artifactId>
62+
<artifactId>jaxb-core</artifactId>
6363
<scope>provided</scope>
6464
</dependency>
6565
<dependency>

plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/annotate/AnnotatePlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public class AnnotatePlugin extends AbstractParameterizablePlugin {
8181
Constants.NAMESPACE_URI, "annotateEnum");
8282
public static final QName ANNOTATE_ENUM_CONSTANT_QNAME = new QName(
8383
Constants.NAMESPACE_URI, "annotateEnumConstant");
84+
public static final QName ANNOTATE_ENUM_VALUE_METHOD_QNAME = new QName(
85+
Constants.NAMESPACE_URI, "annotateEnumValueMethod");
86+
public static final QName ANNOTATE_ENUM_FROM_VALUE_METHOD_QNAME = new QName(
87+
Constants.NAMESPACE_URI, "annotateEnumFromValueMethod");
8488
public static final QName ANNOTATE_QNAME = new QName(
8589
Constants.NAMESPACE_URI, "annotate");
8690

@@ -394,7 +398,8 @@ public Collection<QName> getCustomizationElementNames() {
394398
ANNOTATE_PROPERTY_QNAME, ANNOTATE_PROPERTY_FIELD_QNAME,
395399
ANNOTATE_PROPERTY_GETTER_QNAME, ANNOTATE_PROPERTY_SETTER_QNAME,
396400
ANNOTATE_PROPERTY_SETTER_PARAMETER_QNAME, ANNOTATE_ENUM_QNAME,
397-
ANNOTATE_ENUM_CONSTANT_QNAME);
401+
ANNOTATE_ENUM_CONSTANT_QNAME, ANNOTATE_ENUM_VALUE_METHOD_QNAME,
402+
ANNOTATE_ENUM_FROM_VALUE_METHOD_QNAME);
398403
}
399404

400405
}

plugin/src/main/java/org/jvnet/jaxb2_commons/plugin/annotate/AnnotationTarget.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
import org.w3c.dom.Element;
3939

4040
import com.sun.codemodel.JAnnotatable;
41+
import com.sun.codemodel.JCodeModel;
4142
import com.sun.codemodel.JFieldVar;
4243
import com.sun.codemodel.JMethod;
44+
import com.sun.codemodel.JType;
4345
import com.sun.codemodel.JVar;
44-
import com.sun.tools.xjc.model.CElementInfo;
4546
import com.sun.tools.xjc.model.CEnumLeafInfo;
4647
import com.sun.tools.xjc.outline.ClassOutline;
4748
import com.sun.tools.xjc.outline.ElementOutline;
@@ -212,6 +213,38 @@ public JAnnotatable getAnnotatable(Outline outline,
212213
}
213214
},
214215
//
216+
ENUM_VALUE_METHOD("enum-value-method", AnnotatePlugin.ANNOTATE_ENUM_VALUE_METHOD_QNAME) {
217+
@Override
218+
public JAnnotatable getAnnotatable(Outline outline,
219+
EnumOutline enumOutline)
220+
throws IllegalArgumentException, UnsupportedOperationException {
221+
final JMethod valueMethod = enumOutline.clazz.getMethod("value", new JType[0]);
222+
if (null == valueMethod) {
223+
throw new UnsupportedOperationException(MessageFormat.format(
224+
"Method value() not found in enum [{0}]",
225+
enumOutline.clazz.name()));
226+
}
227+
return valueMethod;
228+
}
229+
},
230+
//
231+
ENUM_FROM_VALUE_METHOD("enum-fromValue-method", AnnotatePlugin.ANNOTATE_ENUM_FROM_VALUE_METHOD_QNAME) {
232+
@Override
233+
public JAnnotatable getAnnotatable(Outline outline,
234+
EnumOutline enumOutline)
235+
throws IllegalArgumentException, UnsupportedOperationException {
236+
final JCodeModel codeModel = enumOutline.clazz.owner();
237+
final JType jTypeString = codeModel._ref(String.class);
238+
final JMethod fromValueMethod = enumOutline.clazz.getMethod("fromValue", new JType[]{jTypeString});
239+
if (null == fromValueMethod) {
240+
throw new UnsupportedOperationException(MessageFormat.format(
241+
"Method fromValue(String) not found in enum [{0}]",
242+
enumOutline.clazz.name()));
243+
}
244+
return fromValueMethod;
245+
}
246+
},
247+
//
215248
ELEMENT("element", AnnotatePlugin.ANNOTATE_ELEMENT_QNAME) {
216249
@Override
217250
public JAnnotatable getAnnotatable(Outline outline,

pom.xml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@
9090
<module>plugin</module>
9191
</modules>
9292
<profiles>
93+
<profile>
94+
<!-- Disable syntax validation for javadoc in Java8 -->
95+
<id>disable-java8-doclint</id>
96+
<activation>
97+
<jdk>[1.8,)</jdk>
98+
</activation>
99+
<properties>
100+
<additionalparam>-Xdoclint:none</additionalparam>
101+
</properties>
102+
</profile>
93103
<profile>
94104
<id>all</id>
95105
<activation>
@@ -139,6 +149,11 @@
139149
<artifactId>junit</artifactId>
140150
<scope>test</scope>
141151
</dependency>
152+
<dependency>
153+
<groupId>org.hamcrest</groupId>
154+
<artifactId>hamcrest-all</artifactId>
155+
<scope>test</scope>
156+
</dependency>
142157
</dependencies>
143158
<dependencyManagement>
144159
<dependencies>
@@ -197,7 +212,7 @@
197212
</dependency>
198213
<dependency>
199214
<groupId>com.sun.xml.bind</groupId>
200-
<artifactId>jaxb-impl</artifactId>
215+
<artifactId>jaxb-core</artifactId>
201216
<version>${jaxb.version}</version>
202217
</dependency>
203218
<dependency>
@@ -216,6 +231,11 @@
216231
<artifactId>junit</artifactId>
217232
<version>4.11</version>
218233
</dependency>
234+
<dependency>
235+
<groupId>org.hamcrest</groupId>
236+
<artifactId>hamcrest-all</artifactId>
237+
<version>1.3</version>
238+
</dependency>
219239
<!-- Commons -->
220240
<dependency>
221241
<groupId>org.apache.commons</groupId>
@@ -261,6 +281,11 @@
261281
<artifactId>log4j</artifactId>
262282
<version>1.2.13</version>
263283
</dependency>
284+
<dependency>
285+
<groupId>org.apache.logging.log4j</groupId>
286+
<artifactId>log4j-jcl</artifactId>
287+
<version>2.5</version>
288+
</dependency>
264289
<!-- Spring -->
265290
<dependency>
266291
<groupId>org.springframework</groupId>
@@ -304,8 +329,8 @@
304329
<inherited>true</inherited>
305330
<artifactId>maven-compiler-plugin</artifactId>
306331
<configuration>
307-
<source>1.6</source>
308-
<target>1.6</target>
332+
<source>1.8</source>
333+
<target>1.8</target>
309334
</configuration>
310335
</plugin>
311336
<plugin>

samples/annotate/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@
6161
</dependency>
6262
<dependency>
6363
<groupId>com.sun.xml.bind</groupId>
64-
<artifactId>jaxb-impl</artifactId>
64+
<artifactId>jaxb-core</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.apache.logging.log4j</groupId>
68+
<artifactId>log4j-jcl</artifactId>
6569
</dependency>
6670
<dependency>
6771
<groupId>org.hibernate</groupId>

samples/annotate/project-build.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<fileset dir="${basedir}/lib">
4242
<include name="activation-*.jar"/>
4343
<include name="jaxb-api-*.jar"/>
44-
<include name="jaxb-impl-*.jar"/>
44+
<include name="jaxb-core-*.jar"/>
4545
<include name="stax-api-*.jar"/>
4646
<include name="jsr173_api-*.jar"/>
4747

@@ -55,7 +55,7 @@
5555
<fileset dir="${basedir}/lib">
5656
<include name="activation-*.jar"/>
5757
<include name="jaxb-api-*.jar"/>
58-
<include name="jaxb-impl-*.jar"/>
58+
<include name="jaxb-core-*.jar"/>
5959
<include name="stax-api-*.jar"/>
6060
<include name="jsr173_api-*.jar"/>
6161

@@ -76,7 +76,7 @@
7676
<fileset dir="${basedir}/lib">
7777
<include name="activation-*.jar"/>
7878
<include name="jaxb-api-*.jar"/>
79-
<include name="jaxb-impl-*.jar"/>
79+
<include name="jaxb-core-*.jar"/>
8080
<include name="jsr173_api-*.jar"/>
8181
<include name="stax-api-*.jar"/>
8282

samples/annotate/project-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<dependencies>
4141
<dependency>
4242
<groupId>com.sun.xml.bind</groupId>
43-
<artifactId>jaxb-impl</artifactId>
43+
<artifactId>jaxb-core</artifactId>
4444
<version>${jaxb.version}</version>
4545
<scope>provided</scope>
4646
</dependency>

samples/annotate/src/main/java/.placeholder

Whitespace-only changes.

0 commit comments

Comments
 (0)