use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BIEnumMember in project jaxb-ri by eclipse-ee4j.
the class SimpleTypeBuilder method buildCEnumConstants.
/**
* @param errorRef
* if constant names couldn't be generated, return a reference to that enum facet.
* @return
* null if unable to generate names for some of the constants.
*/
private List<CEnumConstant> buildCEnumConstants(XSRestrictionSimpleType type, boolean needsToGenerateMemberName, Map<String, BIEnumMember> members, XSFacet[] errorRef) {
List<CEnumConstant> memberList = new ArrayList<>();
int idx = 1;
// to avoid duplicates. See issue #366
Set<String> enums = new HashSet<>();
for (XSFacet facet : type.getDeclaredFacets(XSFacet.FACET_ENUMERATION)) {
String name = null;
String mdoc = builder.getBindInfo(facet).getDocumentation();
if (!enums.add(facet.getValue().value))
// ignore the 2nd occasion
continue;
if (needsToGenerateMemberName) {
// generate names for all member names.
// this will even override names specified by the user. that's crazy.
name = "VALUE_" + (idx++);
} else {
String facetValue = facet.getValue().value;
BIEnumMember mem = members.get(facetValue);
if (mem == null)
// look at the one attached to the facet object
mem = builder.getBindInfo(facet).get(BIEnumMember.class);
if (mem != null) {
name = mem.name;
if (mdoc == null) {
mdoc = mem.javadoc;
}
}
if (name == null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < facetValue.length(); i++) {
char ch = facetValue.charAt(i);
if (Character.isJavaIdentifierPart(ch))
sb.append(ch);
else
sb.append('_');
}
name = model.getNameConverter().toConstantName(sb.toString());
}
}
if (!JJavaName.isJavaIdentifier(name)) {
if (errorRef != null)
errorRef[0] = facet;
// unable to generate a name
return null;
}
memberList.add(new CEnumConstant(name, mdoc, facet.getValue().value, facet, builder.getBindInfo(facet).toCustomizationList(), facet.getLocator()));
}
return memberList;
}
Aggregations