use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getCleanupStrategy.
/**
* Insert the method's description here.
*
* @return org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy
* @param node
* org.eclipse.wst.css.core.model.interfaces.ICSSNode
*/
protected CSSCleanupStrategy getCleanupStrategy(ICSSNode node) {
CSSCleanupStrategy currentStrategy = CSSCleanupStrategyImpl.getInstance();
ICSSDocument doc = node.getOwnerDocument();
if (doc == null)
return currentStrategy;
ICSSModel model = doc.getModel();
if (model == null)
return currentStrategy;
if (model.getStyleSheetType() != ICSSModel.EXTERNAL) {
// TODO - TRANSITION Nakamori-san, or Kit, how can we move to
// "HTML" plugin?
// can we subclass?
// currentStrategy = CSSInHTMLCleanupStrategyImpl.getInstance();
}
return currentStrategy;
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class CharsetRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CSSCleanupStrategy stgy = getCleanupStrategy(node);
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])) && !regions[i].getType().equals(CSSRegionContexts.CSS_DELIMITER))
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
if (needS(outside[1]) && !isIncludesPreEnd(node, region))
appendSpaceBefore(node, outside[1], source);
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class CounterFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = ((IndexedRegion) node).getEndOffset();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
CSSCleanupStrategy stgy = getCleanupStrategy(node);
if (end > 0) {
// format source
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
boolean skipSpace = false;
for (int i = 0; i < regions.length; i++) {
if (i != 0 && !skipSpace)
appendSpaceBefore(node, regions[i], source);
skipSpace = false;
source.append(decoratedPropValueRegion(regions[i], stgy));
if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
skipSpace = true;
}
} else {
// generate source
ICounter counter = (ICounter) node;
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
String separator = counter.getSeparator();
quote = CSSUtil.detectQuote(separator, quote);
String sep = (separator == null || separator.length() == 0) ? null : (quote + separator + quote);
String ident = counter.getIdentifier();
String style = counter.getListStyle();
// $NON-NLS-2$//$NON-NLS-1$
String func = (sep == null || sep.length() == 0) ? "counter(" : "counters(";
// normalize
if (ident == null)
// $NON-NLS-1$
ident = "";
if (style == null)
// $NON-NLS-1$
style = "";
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
ident = ident.toUpperCase();
style = style.toUpperCase();
func = func.toUpperCase();
} else {
ident = ident.toLowerCase();
style = style.toLowerCase();
}
if (sep == null || sep.length() == 0) {
source.append(func);
appendSpaceBefore(node, ident, source);
source.append(ident);
} else {
source.append(func);
appendSpaceBefore(node, ident, source);
source.append(ident);
// $NON-NLS-1$
source.append(",");
appendSpaceBefore(node, sep, source);
source.append(sep);
}
if (style != null && style.length() != 0) {
// $NON-NLS-1$
source.append(",");
appendSpaceBefore(node, style, source);
}
// $NON-NLS-1$
source.append(")");
}
}
use of org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class CounterFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, IRegion region, StringBuffer source) {
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CSSCleanupStrategy stgy = getCleanupStrategy(node);
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.css.core.internal.cleanup.CSSCleanupStrategy in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatPost.
/**
*/
protected void formatPost(ICSSNode node, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
int end = ((IndexedRegion) node).getEndOffset();
int start = (node.getLastChild() != null && ((IndexedRegion) node.getLastChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getLastChild()).getEndOffset() : getChildInsertPos(node);
if (end > 0 && start < end) {
// 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++) {
appendSpaceBefore(node, regions[i], source);
String decorateIndetRegion = decoratedIdentRegion(regions[i], stgy);
if (decorateIndetRegion.trim().length() == 0)
// $NON-NLS-1$
decorateIndetRegion = " ";
if (!source.toString().endsWith(decorateIndetRegion))
source.append(decorateIndetRegion);
}
} else {
// generate source
// append "!important"
String priority = ((ICSSStyleDeclItem) node).getPriority();
if (priority != null && priority.length() > 0) {
appendSpaceBefore(node, priority, source);
source.append(priority);
}
}
}
Aggregations