use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
CSSCleanupStrategy 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(decoratedPropNameRegion(regions[i], stgy));
}
if (needS(outside[1])) {
if (isIncludesPreEnd(node, region) && (!isCleanup() || getCleanupStrategy(node).isFormatSource())) {
appendAfterColonSpace(node, source);
} else
appendSpaceBefore(node, outside[1], source);
}
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class FunctionFormatter method formatBefore.
/**
*/
protected void formatBefore(ICSSNode node, ICSSNode child, IRegion region, String toAppend, StringBuffer source) {
CSSCleanupStrategy 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(decoratedRegion(regions[i], 2, stgy));
}
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatBefore.
/**
*/
protected void formatBefore(ICSSNode node, ICSSNode child, String toAppend, StringBuffer source, IRegion exceptFor) {
ICSSNode prev = (child != null) ? child.getPreviousSibling() : node.getLastChild();
int start = (prev != null) ? ((IndexedRegion) prev).getEndOffset() : 0;
int end = (child != null) ? ((IndexedRegion) child).getStartOffset() : 0;
if (start > 0 && start < end) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
// get meaning regions
CompoundRegion[] regions = null;
if (exceptFor == null)
regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
else {
regions = getRegions(structuredDocument, new FormatRegion(start, end - start), exceptFor, null);
}
// generate source
for (int i = 0; i < regions.length; i++) {
appendSpaceBefore(node, regions[i], source);
// must
source.append(decoratedRegion(regions[i], 2, stgy));
// be
// comments
}
}
if (child != null) {
boolean append = true;
if (child instanceof ICSSPrimitiveValue) {
if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_COMMA)
// $NON-NLS-1$
toAppend = ",";
else if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
// $NON-NLS-1$
toAppend = "/";
ICSSNode prevSibling = child.getPreviousSibling();
if (prevSibling instanceof ICSSPrimitiveValue) {
if (((ICSSPrimitiveValue) prevSibling).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
append = false;
if (prevSibling instanceof CSSRegionContainer) {
// If the previous region was unknown, don't append whitespace
final ITextRegion region = ((CSSRegionContainer) prevSibling).getFirstRegion();
if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
append = false;
}
}
}
if (child instanceof CSSRegionContainer) {
final ITextRegion region = ((CSSRegionContainer) child).getFirstRegion();
// If the current region is unknown, don't append whitespace
if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
append = false;
}
if (toAppend != null && !toAppend.equals(",") && !toAppend.equals("/") && !toAppend.equals(")") && append) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
appendSpaceBefore(node, toAppend, source);
}
}
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class StyleRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
int start = ((IndexedRegion) node).getStartOffset();
int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
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)
appendSpaceBetween(node, regions[i - 1], regions[i], source);
source.append(decoratedSelectorRegion(regions[i], (i != 0) ? regions[i - 1] : null, stgy));
}
} else {
// generate source
String str = ((ICSSStyleRule) node).getSelectorText();
// appendSpaceBefore(node,str,source);
source.append(str);
// $NON-NLS-1$
appendSpaceBefore(node, "{", source);
// $NON-NLS-1$
source.append("{");
}
appendDelimBefore(node, null, source);
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class StyleRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
CSSCleanupStrategy 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]))
appendSpaceBetween(node, (i == 0) ? outside[0] : regions[i - 1], regions[i], source);
source.append(decoratedSelectorRegion(regions[i], (i != 0) ? regions[i - 1] : null, stgy));
}
if (needS(outside[1])) {
if (isIncludesPreEnd(node, region))
appendDelimBefore(node, null, source);
else
appendSpaceBetween(node, regions[regions.length - 1], outside[1], source);
}
}
Aggregations