@Override
public HandledResult handle(ValidationContext ctx, ValidationError error) {
final String el = error.element().getLocalPart();
final Set<String> alts = error.alternatives();
final Location loc = error.location();
final Position pos = ctx.searchBackward(loc.getLineNumber() - 1, loc.getColumnNumber(),
Pattern.compile(String.format("<%s[ >/]", el)));
final HandledResult result = HandledResult.from(error)
.addPrimaryMessage(this.primaryMessageKey, el);
if (pos != null) {
result.line(pos.line).column(pos.col);
}
if (!alts.isEmpty()) {
final List<SchemaElement> path = ctx.mapDocLocationToSchemaPath(error.element(), error.position());
if (path.isEmpty()) {
result.possiblyMalformed(true);
}
Set<String> otherElements =
ctx.elementsForElement(path).stream()
.map(SchemaElement::name)
.collect(Collectors.toSet());
result.addPrimaryMessage(this.optionsMessageKey,
Util.asSortedList(alts).stream()
.map(String::toLowerCase)
.map(Util.possiblyUnderscoredName(otherElements))
.collect(Collectors.toList()));
}
return result;
}