Search in sources :

Example 6 with IJSONArray

use of org.eclipse.wst.json.core.document.IJSONArray in project webtools.sourceediting by eclipse.

the class JSONArrayFormatter method formatPre.

@Override
protected void formatPre(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[0] != null && regions[0].getType() == JSONRegionContexts.JSON_ARRAY_OPEN) {
            source.append(decoratedRegion(regions[0], 0, stgy));
        }
    }
    if (node instanceof IJSONArray && node.hasChildNodes()) {
        source.append(getLineDelimiter(node));
        source.append(getIndent(node));
        source.append(getIndentString());
    }
}
Also used : IJSONArray(org.eclipse.wst.json.core.document.IJSONArray) IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 7 with IJSONArray

use of org.eclipse.wst.json.core.document.IJSONArray 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());
            }
        }
    }
}
Also used : IJSONArray(org.eclipse.wst.json.core.document.IJSONArray) IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IJSONObject(org.eclipse.wst.json.core.document.IJSONObject) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Aggregations

IJSONArray (org.eclipse.wst.json.core.document.IJSONArray)7 IJSONNode (org.eclipse.wst.json.core.document.IJSONNode)4 IJSONObject (org.eclipse.wst.json.core.document.IJSONObject)3 IJSONPair (org.eclipse.wst.json.core.document.IJSONPair)3 IJSONValue (org.eclipse.wst.json.core.document.IJSONValue)3 IJSONCleanupStrategy (org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 HashSet (java.util.HashSet)1 JsonValue (org.eclipse.json.provisonnal.com.eclipsesource.json.JsonValue)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1