Search in sources :

Example 1 with IJSONCleanupStrategy

use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.

the class JSONObjectFormatter 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_OBJECT_OPEN) {
            source.append(decoratedRegion(regions[0], 0, stgy));
        }
    }
    source.append(getLineDelimiter(node));
    source.append(getIndent(node));
    source.append(getIndentString());
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 2 with IJSONCleanupStrategy

use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.

the class UnknownRuleFormatter method formatPre.

@Override
protected void formatPre(IJSONNode node, IRegion region, StringBuilder source) {
    IJSONCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
    CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
    for (int i = 0; i < regions.length; i++) {
        if (i != 0 || needS(outside[0]))
            appendSpaceBefore(node, regions[i], source);
        source.append(decoratedPropValueRegion(regions[i], stgy));
    }
    if (needS(outside[1]) && !isIncludesPreEnd(node, region))
        appendSpaceBefore(node, outside[1], source);
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 3 with IJSONCleanupStrategy

use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.

the class UnknownRuleFormatter method formatPre.

@Override
protected void formatPre(IJSONNode node, StringBuilder source) {
    IJSONCleanupStrategy stgy = getCleanupStrategy(node);
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(decoratedPropValueRegion(regions[i], stgy));
        }
    }
// else { // generate source
// JSONUnknownRule rule = (JSONUnknownRule) node;
// source.append(rule.getCssText());
// }
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 4 with IJSONCleanupStrategy

use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.

the class AbstractJSONSourceFormatter method formatValue.

protected void formatValue(IJSONNode node, StringBuilder source, IJSONNode value) {
    IJSONCleanupStrategy stgy = getCleanupStrategy(node);
    IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
    int start = node.getStartOffset();
    int end = node.getEndOffset();
    CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
    if (regions.length > 2) {
        for (int i = 2; i < regions.length; i++) {
            source.append(decoratedRegion(regions[i], 0, stgy));
        }
    }
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 5 with IJSONCleanupStrategy

use of org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy in project webtools.sourceediting by eclipse.

the class AbstractJSONSourceFormatter method getCleanupStrategy.

/**
 * Insert the method's description here.
 *
 * @return org.eclipse.wst.css.core.internal.cleanup.JSONCleanupStrategy
 * @param node
 *            org.eclipse.wst.css.core.model.interfaces.IJSONNode
 */
protected IJSONCleanupStrategy getCleanupStrategy(IJSONNode node) {
    IJSONCleanupStrategy currentStrategy = JSONCleanupStrategyImpl.getInstance();
    IJSONDocument doc = node.getOwnerDocument();
    if (doc == null)
        return currentStrategy;
    IJSONModel model = doc.getModel();
    if (model == null)
        return currentStrategy;
    return currentStrategy;
}
Also used : IJSONCleanupStrategy(org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy) IJSONModel(org.eclipse.wst.json.core.document.IJSONModel) IJSONDocument(org.eclipse.wst.json.core.document.IJSONDocument)

Aggregations

IJSONCleanupStrategy (org.eclipse.wst.json.core.cleanup.IJSONCleanupStrategy)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)13 IJSONArray (org.eclipse.wst.json.core.document.IJSONArray)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2 IJSONDocument (org.eclipse.wst.json.core.document.IJSONDocument)1 IJSONModel (org.eclipse.wst.json.core.document.IJSONModel)1 IJSONNode (org.eclipse.wst.json.core.document.IJSONNode)1 IJSONObject (org.eclipse.wst.json.core.document.IJSONObject)1 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)1