* we mustn't interfere with it. Two annotations of the same kind on a Java field
* do not compile.
* Stores the applied annotations and their origin into the map arg.
*/
private void applyAnnotations(XSSimpleType simpleType, JFieldVar fieldVar, Map<JAnnotationUse, FacetType> a) {
XSFacet facet; // Auxiliary field.
JType fieldType = fieldVar.type();
if (notAnnotated(fieldVar, sizeAnn) && isSizeAnnotationApplicable(fieldType)) {
if ((facet = simpleType.getFacet(FACET_LENGTH)) != null) {
int length = Integer.valueOf(facet.getValue().value);
a.put(fieldVar.annotate(sizeAnn).param("min", length).param("max", length), FacetType.length);
} else {
Integer minLength = (facet = simpleType.getFacet(FACET_MINLENGTH)) != null ? Integer.valueOf(facet.getValue().value) : null;
Integer maxLength = (facet = simpleType.getFacet(FACET_MAXLENGTH)) != null ? Integer.valueOf(facet.getValue().value) : null;
if (minLength != null && maxLength != null) // Note: If using both minLength + maxLength, the minLength's customizations are considered.
a.put(fieldVar.annotate(sizeAnn).param("min", minLength).param("max", maxLength), FacetType.minLength);
else if (minLength != null) a.put(fieldVar.annotate(sizeAnn).param("min", minLength), FacetType.minLength);
else if (maxLength != null) a.put(fieldVar.annotate(sizeAnn).param("max", maxLength), FacetType.maxLength);
}
}
if ((facet = simpleType.getFacet(FACET_MAXINCLUSIVE)) != null && isNumberOrCharSequence(fieldType, false)) {
String maxIncValue = facet.getValue().value;
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMaxAnn, maxIncValue)) {
a.put(fieldVar.annotate(decimalMaxAnn).param("value", maxIncValue), FacetType.maxInclusive);
convertToElement(fieldVar);
}
}
if ((facet = simpleType.getFacet(FACET_MININCLUSIVE)) != null && isNumberOrCharSequence(fieldType, false)) {
String minIncValue = facet.getValue().value;
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMinAnn, minIncValue)) {
a.put(fieldVar.annotate(decimalMinAnn).param("value", minIncValue), FacetType.minInclusive);
convertToElement(fieldVar);
}
}
if ((facet = simpleType.getFacet(FACET_MAXEXCLUSIVE)) != null && isNumberOrCharSequence(fieldType, false)) {
String maxExcValue = facet.getValue().value;
if (!jsr303) { // ~ if jsr349
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMaxAnn, maxExcValue)) {
a.put(fieldVar.annotate(decimalMaxAnn).param("value", maxExcValue).param("inclusive", false), FacetType.maxExclusive);
convertToElement(fieldVar);
}
} else {
Integer intMaxExc = Integer.valueOf(maxExcValue) - 1;
maxExcValue = intMaxExc.toString();
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMaxAnn, maxExcValue)) {
a.put(fieldVar.annotate(decimalMaxAnn).param("value", maxExcValue), FacetType.maxExclusive);
convertToElement(fieldVar);
}
}
}
if ((facet = simpleType.getFacet(FACET_MINEXCLUSIVE)) != null && isNumberOrCharSequence(fieldType, false)) {
String minExcValue = facet.getValue().value;
if (!jsr303) // ~ if jsr349
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMinAnn, minExcValue)) {
a.put(fieldVar.annotate(decimalMinAnn).param("value", minExcValue).param("inclusive", false), FacetType.minExclusive);
convertToElement(fieldVar);
}
else {
Integer intMinExc = Integer.valueOf(minExcValue) + 1;
minExcValue = intMinExc.toString();
if (notAnnotatedAndNotDefaultBoundary(fieldVar, decimalMinAnn, minExcValue)) {
a.put(fieldVar.annotate(decimalMinAnn).param("value", minExcValue), FacetType.minExclusive);
convertToElement(fieldVar);
}
}
}
if ((facet = simpleType.getFacet(FACET_TOTALDIGITS)) != null && isNumberOrCharSequence(fieldType, true)) {
Integer digits = Integer.valueOf(facet.getValue().value);
if (digits != null) {
XSFacet fractionDigits = simpleType.getFacet(FACET_FRACTIONDIGITS);
int fractionDigs = fractionDigits == null ? 0 : Integer.valueOf(fractionDigits.getValue().value);
if (notAnnotated(fieldVar, digitsAnn))
a.put(fieldVar.annotate(digitsAnn).param("integer", (digits - fractionDigs)).param("fraction", fractionDigs), FacetType.totalDigits);
}
}