use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class CounterFormatter method formatAttrChanged.
/**
*/
public StringBuffer formatAttrChanged(ICSSNode node, ICSSAttr attr, boolean insert, AttrChangeContext context) {
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
StringBuffer source = new StringBuffer();
if (node == null || attr == null)
return source;
if (!ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName()) && !ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName()) && !ICounter.SEPARATOR.equalsIgnoreCase(attr.getName()))
return source;
// get region to replace
IndexedRegion iNode = (IndexedRegion) node;
context.start = iNode.getStartOffset();
context.end = iNode.getEndOffset();
ICounter counter = (ICounter) node;
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
String sep = counter.getSeparator();
String ident = counter.getIdentifier();
String style = counter.getListStyle();
if (ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName())) {
if (insert)
ident = attr.getValue();
else
// $NON-NLS-1$
ident = "";
} else if (ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName())) {
if (insert)
style = attr.getValue();
else
style = null;
} else if (ICounter.SEPARATOR.equalsIgnoreCase(attr.getName())) {
if (insert)
sep = attr.getValue();
else
sep = null;
}
quote = CSSUtil.detectQuote(sep, quote);
sep = (sep == null || sep.length() == 0) ? null : (quote + sep + quote);
// $NON-NLS-2$//$NON-NLS-1$
String func = (sep == null || sep.length() == 0) ? "counter(" : "counters(";
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(")");
/*
* IStructuredDocument structuredDocument =
* node.getOwnerDocument().getModel().getStructuredDocument();
* ITextRegion[] regions =
* getRegionsWithoutWhiteSpaces(structuredDocument, new
* FormatRegion(context.start, context.end - context.start + 1)); int
* commas[2]; int numComma = 0; for(int j = 0; j <regions.length; j++) {
* if (regions[j].getType() == CSSRegionContexts.COMMA) {
* commas[numComma++] = j; if (numComma > 1) break; } }
*
* if (ICounter.IDENTIFIER.equalsIgnoreCase(attr.getName())) { } else
* if (ICounter.LISTSTYLE.equalsIgnoreCase(attr.getName())) { } else
* if (ICounter.SEPARATOR.equalsIgnoreCase(attr.getName())) { boolean
* skipSpace = false; String func = insert ? "counters(" : "counter(";
* if (mgr.isPropValueUpperCase()) func = func.toUpperCase();
*
* for(int i=0; i <regions.length; i++) { if (regions[i].getType() ==
* CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
* source.append(func); else { if (numComma == 2 && commas[1] < i) {
* } else if (numComma == 1 && commas[0] < i && insert) {
* } else if (numComma == 1 && commas[0] < i && ! insert) { } else if
* (numComma == 0 && insert && regions[i].getType ==
* CSSRegionContexts.PARENTHESIS_CLOSE) { source.append(",");
* appendSpaceBefore(node,attr.getValue(),source);
* source.append(attr.getValue()); }
*
* if (i != 0 && !skipSpace)
* appendSpaceBefore(node,regions[i],source);
* source.append(decoratedPropValueRegion(regions[i])); } skipSpace =
* false;
*
* if (regions[i].getType() ==
* CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) skipSpace = true; } }
*/
return source;
}
use of org.eclipse.core.runtime.Preferences 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.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class ImportRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
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
CSSCleanupStrategy 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++) {
String str = regions[i].getText();
if (regions[i].getType() == CSSRegionContexts.CSS_IMPORT)
str = decoratedIdentRegion(regions[i], stgy);
else
str = decoratedPropValueRegion(regions[i], stgy);
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(str);
}
} else {
// generate source
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String str = IMPORT;
if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
str = IMPORT.toUpperCase();
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
source.append(str);
// $NON-NLS-1$
str = "url(";
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
str = str.toUpperCase();
String href = ((ICSSImportRule) node).getHref();
quote = CSSUtil.detectQuote(href, quote);
// $NON-NLS-1$
str = str + quote + href + quote + ")";
appendSpaceBefore(node, str, source);
source.append(str);
}
ICSSNode child = node.getFirstChild();
if (child != null && (child instanceof org.w3c.dom.stylesheets.MediaList) && ((org.w3c.dom.stylesheets.MediaList) child).getLength() > 0) {
// $NON-NLS-1$
appendSpaceBefore(node, "", source);
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class TestCleanupProcessorCSS method tearDown.
protected void tearDown() throws Exception {
// restore old preferences
Preferences prefs = CSSCorePlugin.getDefault().getPluginPreferences();
prefs.setValue(CSSCorePreferenceNames.CLEAR_ALL_BLANK_LINES, fOldClearBlankLinesPref);
prefs.setValue(CSSCorePreferenceNames.LINE_WIDTH, fOldMaxLineWidthPref);
prefs.setValue(CSSCorePreferenceNames.INDENTATION_CHAR, fOldIndentationCharPref);
prefs.setValue(CSSCorePreferenceNames.INDENTATION_SIZE, fOldIndentationSizePref);
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractJSONSourceFormatter method decoratedPropNameRegion.
protected String decoratedPropNameRegion(CompoundRegion region, IJSONCleanupStrategy stgy) {
if (isFormat())
return region.getText();
String text = null;
if (!stgy.isFormatSource())
text = region.getFullText();
else
text = region.getText();
// return decoratedRegion(region, 1, stgy);
if (isCleanup()) {
/*if (stgy.getPropNameCase() == JSONCleanupStrategy.ASIS
|| region.getType() != JSONRegionContexts.JSON_DECLARATION_PROPERTY)
return text;
else*/
if (stgy.getPropNameCase() == IJSONCleanupStrategy.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
Preferences preferences = JSONCorePlugin.getDefault().getPluginPreferences();
// else
if (preferences.getInt(JSONCorePreferenceNames.CASE_PROPERTY_NAME) == JSONCorePreferenceNames.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
Aggregations