}
// check there are extra space before the last attribute
IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
if (flatNode == null)
return; // must never happen
ITextRegionList regions = flatNode.getRegions();
if (regions == null)
return; // must never happen
ITextRegion prevRegion = null;
ITextRegion nextRegion = null;
for (int i = 0; i < regions.size(); i++) {
ITextRegion region = regions.get(i);
if (region == nameRegion) {
if (i > 0) {
prevRegion = regions.get(i - 1);
}
}
if (region == lastRegion) {
if (i + 1 < regions.size()) {
nextRegion = regions.get(i + 1);
}
break;
}
}
boolean isLastAttr = false;
if (nextRegion != null) {
String regionType = nextRegion.getType();
if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType)) {
isLastAttr = true;
}
}
if (isLastAttr && prevRegion != null) {
start += prevRegion.getTextEnd();
}
else {
start += nameRegion.getStart();
}
// impl.resetRegions(ownerElement);
impl.resetRegions(element);
}
else { // append attribute
IStructuredDocumentRegion flatNode = element.getStartStructuredDocumentRegion();
if (flatNode == null)
return; // must never happen
attrValueClose = getAttrValueClose(element);
if (attrValueClose != null && attrValueClose.length() > 0) {
insertSpace = true;
start = flatNode.getEndOffset();
end = start;
}
else {
ITextRegionList regions = flatNode.getRegions();
if (regions == null)
return; // must never happen
int attrStart = 0;
for (int i = regions.size() - 1; i >= 0; i--) {
ITextRegion region = regions.get(i);
String regionType = region.getType();
if (regionType == DOMRegionContext.XML_TAG_CLOSE || regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE || isNestedTagClose(regionType))
continue;
int regionEnd = region.getEnd();
if (regionEnd == region.getTextEnd())