private void renderClassLevelAnnotations(JDefinedClass classModel, List<FieldModel> fields) throws Exception {
JFieldRef constantsClass = classModel.staticRef(Util.CONSTANTS_CLASS_NAME);
JFieldRef elementsClass = classModel.staticRef(Util.ELEMENTS_CLASS_NAME);
JClass coreConstants = codeModel.ref(CoreConstants.class);
JFieldRef commonElementsRef = coreConstants.staticRef("CommonElements");
// XmlRootElement
JAnnotationUse rootElementAnnotation = classModel.annotate(XmlRootElement.class);
rootElementAnnotation.param("name", constantsClass.ref(Util.ROOT_ELEMENT_NAME_FIELD));
// XmlAccessorType
JAnnotationUse xmlAccessorTypeAnnotation = classModel.annotate(XmlAccessorType.class);
xmlAccessorTypeAnnotation.param("value", XmlAccessType.NONE);
// XmlType
JAnnotationUse xmlTypeAnnotation = classModel.annotate(XmlType.class);
xmlTypeAnnotation.param("name", constantsClass.ref(Util.TYPE_NAME_FIELD));
JAnnotationArrayMember propOrderMember = xmlTypeAnnotation.paramArray("propOrder");
for (FieldModel field : fields) {
if (Util.isCommonElement(field.fieldName)) {
propOrderMember.param(commonElementsRef.ref(Util.toConstantsVariable(field.fieldName)));
} else {
propOrderMember.param(elementsClass.ref(Util.toConstantsVariable(field.fieldName)));
}
}
propOrderMember.param(commonElementsRef.ref("FUTURE_ELEMENTS"));
}
ImmutableJaxbGenerator.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:kc-rice
作者:
评论列表
文章目录