use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.
the class JSONArrayFormatter method formatChildren.
@Override
protected void formatChildren(IJSONNode node, StringBuilder source) {
if (node instanceof IJSONArray) {
IJSONArray array = (IJSONArray) node;
IJSONNode child = array.getFirstChild();
while (child != null) {
if (child instanceof IJSONObject || child instanceof IJSONArray) {
formatObject(node, source, child);
if (child.getNextSibling() != null) {
int start = child.getEndOffset();
int end = child.getNextSibling().getStartOffset();
if (end > start) {
IJSONCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
source.append(decoratedRegion(regions[i], 0, stgy));
}
}
}
String delim = getLineDelimiter(node);
source.append(delim);
source.append(getIndent(node));
} else {
formatValue(node, source, child);
}
child = child.getNextSibling();
if (child != null) {
source.append(getIndentString());
}
}
}
}
use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.
the class JSONPairFormatter method formatPost.
@Override
protected void formatPost(IJSONNode node, IRegion region, StringBuilder source) {
if (node.getNextSibling() != null) {
int start = node.getEndOffset();
int end = node.getNextSibling().getStartOffset();
IJSONCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
source.append(decoratedRegion(regions[i], 0, stgy));
}
String delim = getLineDelimiter(node);
source.append(delim);
if (node.getNextSibling() != null) {
source.append(getIndent(node));
} else {
source.append(getIndent(node.getParentNode()));
}
}
}
use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.
the class JSONObjectFormatter method formatPost.
@Override
protected void formatPost(IJSONNode node, IRegion region, StringBuilder source) {
IJSONCleanupStrategy stgy = getCleanupStrategy(node);
if (region.getOffset() >= 0 && region.getLength() >= 0) {
IStructuredDocument document = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(document, region, stgy);
if (regions.length > 0 && regions[regions.length - 1] != null) {
CompoundRegion r = regions[regions.length - 1];
if (r != null && r.getType() == JSONRegionContexts.JSON_OBJECT_CLOSE) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(decoratedRegion(r, 0, stgy));
}
}
}
}
use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.
the class AbstractJSONSourceFormatter method formatObject.
protected void formatObject(IJSONNode node, StringBuilder source, IJSONNode jsonObject) {
IJSONCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
IStructuredDocumentRegion[] structuredRegions = structuredDocument.getStructuredDocumentRegions(node.getStartOffset(), node.getEndOffset());
if (structuredRegions.length >= 2) {
int start = structuredRegions[1].getStartOffset();
int end = node.getEndOffset();
IJSONSourceFormatter formatter = (IJSONSourceFormatter) ((INodeNotifier) jsonObject).getAdapterFor(IJSONSourceFormatter.class);
if (formatter == null) {
formatter = JSONSourceFormatterFactory.getInstance().getSourceFormatter(jsonObject);
}
StringBuilder objectSource = formatter.format(jsonObject, new FormatRegion(start, end - start));
if (objectSource != null) {
source.append(objectSource);
}
}
}
Aggregations