private boolean formatWithinTag(TextEdit textEdit, XMLFormattingConstraints constraints, IStructuredDocumentRegion currentDocumentRegion, IStructuredDocumentRegion previousDocumentRegion) {
int availableLineWidth = constraints.getAvailableLineWidth();
String indentStrategy = constraints.getIndentStrategy();
String whitespaceStrategy = constraints.getWhitespaceStrategy();
int indentLevel = constraints.getIndentLevel();
ITextRegionList textRegions = currentDocumentRegion.getRegions();
int currentTextRegionIndex = 1;
ITextRegion currentTextRegion = textRegions.get(currentTextRegionIndex);
String currentType = currentTextRegion.getType();
// tag name should always be the first text region
if (DOMRegionContext.XML_TAG_NAME.equals(currentType)) {
ITextRegion nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
String nextType = (nextTextRegion != null) ? nextTextRegion.getType() : null;
if (DOMRegionContext.XML_TAG_CLOSE.equals(nextType)) {
// already at tag close
formatStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
return false;
}
else if (DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(nextType)) {
// already at empty tag close
formatEmptyStartTagWithNoAttr(textEdit, constraints, currentDocumentRegion, previousDocumentRegion, availableLineWidth, indentStrategy, whitespaceStrategy, currentTextRegion);
return true;
}
else {
availableLineWidth -= (currentTextRegion.getTextLength() + 2);
boolean alignFinalBracket = getFormattingPreferences().getAlignFinalBracket();
boolean oneSpaceInTagName = getFormattingPreferences().getSpaceBeforeEmptyCloseTag();
boolean indentMultipleAttribute = getFormattingPreferences().getIndentMultipleAttributes();
// indicates if tag spanned more than one line
boolean spanMoreThan1Line = false;
// indicates if all attributes should be indented
boolean indentAllAttributes = false;
if (indentMultipleAttribute) {
int attributesCount = 0;
int i = 2;
final int size = textRegions.size();
while (i < size && attributesCount < 2) {
if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(textRegions.get(i).getType())) {
++attributesCount;
}
i++;
}
indentAllAttributes = (attributesCount > 1);
}
while ((currentTextRegionIndex + 1) < textRegions.size()) {
nextTextRegion = textRegions.get(currentTextRegionIndex + 1);
nextType = nextTextRegion.getType();
if (DOMRegionContext.XML_TAG_ATTRIBUTE_NAME.equals(nextType)) {
boolean indentAttribute = indentAllAttributes;
if (!indentAttribute)
indentAttribute = shouldIndentBeforeAttribute(constraints, textRegions, availableLineWidth, currentTextRegionIndex, currentTextRegion, nextTextRegion);