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());
}
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);
}
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());
// }
}
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));
}
}
}
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;
}
Aggregations