use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class FormatProcessorXML method getFormatPreferences.
public IStructuredFormatPreferences getFormatPreferences() {
if (fFormatPreferences == null) {
fFormatPreferences = new StructuredFormatPreferencesXML();
Preferences preferences = getModelPreferences();
if (preferences != null) {
fFormatPreferences.setLineWidth(preferences.getInt(XMLCorePreferenceNames.LINE_WIDTH));
((StructuredFormatPreferencesXML) fFormatPreferences).setSplitMultiAttrs(preferences.getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS));
((StructuredFormatPreferencesXML) fFormatPreferences).setAlignEndBracket(preferences.getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET));
((StructuredFormatPreferencesXML) fFormatPreferences).setPreservePCDATAContent(preferences.getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT));
fFormatPreferences.setClearAllBlankLines(preferences.getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES));
char indentChar = ' ';
String indentCharPref = preferences.getString(XMLCorePreferenceNames.INDENTATION_CHAR);
if (XMLCorePreferenceNames.TAB.equals(indentCharPref)) {
indentChar = '\t';
}
int indentationWidth = preferences.getInt(XMLCorePreferenceNames.INDENTATION_SIZE);
StringBuffer indent = new StringBuffer();
for (int i = 0; i < indentationWidth; i++) {
indent.append(indentChar);
}
fFormatPreferences.setIndent(indent.toString());
}
}
return fFormatPreferences;
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method decoratedRegion.
/**
*/
protected String decoratedRegion(CompoundRegion region, int type, CSSCleanupStrategy stgy) {
if (isFormat())
return region.getText();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String text = null;
if (!stgy.isFormatSource())
text = region.getFullText();
else
text = region.getText();
String regionType = region.getType();
if (regionType == CSSRegionContexts.CSS_URI || regionType == CSSRegionContexts.CSS_DECLARATION_VALUE_URI) {
String uri = CSSLinkConverter.stripFunc(text);
boolean prefIsUpper = preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER;
boolean upper = (type == 0) ? prefIsUpper : ((type == 1) ? preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER : preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER);
String func = text.substring(0, 4);
if (isCleanup()) {
upper = ((type == 0) ? stgy.getIdentCase() : ((type == 1) ? stgy.getPropNameCase() : stgy.getPropValueCase())) == CSSCleanupStrategy.UPPER;
// $NON-NLS-2$//$NON-NLS-1$
func = ((type == 0) ? stgy.getIdentCase() : ((type == 1) ? stgy.getPropNameCase() : stgy.getPropValueCase())) == CSSCleanupStrategy.ASIS ? text.substring(0, 4) : (upper ? "URL(" : "url(");
}
if ((!isCleanup() && preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI)) || (isCleanup() && stgy.isQuoteValues())) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
quote = CSSUtil.detectQuote(uri, quote);
// $NON-NLS-1$
text = func + quote + uri + quote + ")";
} else if (isCleanup() && !stgy.isQuoteValues()) {
// $NON-NLS-1$
text = func + CSSLinkConverter.removeFunc(text) + ")";
} else {
// $NON-NLS-1$
text = func + uri + ")";
}
} else if (region.getType() == CSSRegionContexts.CSS_STRING && (!isCleanup() || stgy.isQuoteValues())) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
// begginning
if (!text.startsWith(quote)) {
if (// $NON-NLS-1$ //$NON-NLS-2$
text.startsWith("\"") || text.startsWith("\'"))
text = quote + text.substring(1);
else
text = quote + text;
}
// ending
if (!text.endsWith(quote)) {
if (// $NON-NLS-1$ //$NON-NLS-2$
text.endsWith("\"") || text.endsWith("\'"))
text = text.substring(0, text.length() - 1) + quote;
else
text = text + quote;
}
}
return text;
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method appendSpaceBefore.
/**
*/
protected void appendSpaceBefore(ICSSNode node, String toAppend, StringBuffer source) {
if (node == null || source == null)
return;
if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
// for not formatting case on cleanup action
return;
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (toAppend != null && toAppend.startsWith("{") && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
// $NON-NLS-1$
source.append(getLineDelimiter(node));
source.append(getIndent(node));
return;
} else if (/* ! mgr.isOnePropertyPerLine() && */
preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int n = getLastLineLength(node, source);
int append = (toAppend != null) ? TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, toAppend, 0)[0] : 0;
if (toAppend != null)
append = (append < 0) ? toAppend.length() : append;
if (n + append + 1 > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(getIndentString());
return;
}
}
// just verify if the source and the toAppend strings do not end with a whitespace to avoid the whitespace duplication.
if (!(source.length() > 0 && source.toString().charAt(source.length() - 1) == ' ') && !(toAppend.length() > 0 && toAppend.charAt(toAppend.length() - 1) == ' ')) {
// $NON-NLS-1$
source.append(" ");
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method appendDelimBefore.
/**
*/
protected void appendDelimBefore(ICSSNode node, CompoundRegion toAppend, StringBuffer source) {
if (node == null || source == null)
return;
if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
// for not formatting case on cleanup action
return;
String delim = getLineDelimiter(node);
boolean needIndent = !(node instanceof ICSSStyleSheet);
if (toAppend == null) {
source.append(delim);
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
} else {
String type = toAppend.getType();
if (type == CSSRegionContexts.CSS_COMMENT) {
RegionIterator it = new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
it.prev();
ITextRegion prev = it.prev();
int[] result = null;
if (prev == null || (prev.getType() == CSSRegionContexts.CSS_S && (result = TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), 0))[0] >= 0)) {
// Collapse to one empty line if there's more than one.
if (result != null) {
int offset = result[0] + DefaultLineTracker.DELIMITERS[result[1]].length();
if (offset < it.getStructuredDocumentRegion().getText(prev).length()) {
if (TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), offset)[0] >= 0) {
source.append(delim);
}
}
source.append(delim);
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
}
} else if (prev.getType() == CSSRegionContexts.CSS_COMMENT) {
String fullText = toAppend.getDocumentRegion().getFullText(prev);
String trimmedText = toAppend.getDocumentRegion().getText(prev);
// $NON-NLS-1$
String whiteSpaces = "";
if (fullText != null && trimmedText != null)
whiteSpaces = fullText.substring(trimmedText.length());
int[] delimiterFound = TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, whiteSpaces, 0);
if (delimiterFound[0] != -1) {
source.append(delim);
} else {
appendSpaceBefore(node, toAppend.getText(), source);
/*If two comments can't be adjusted in one line(combined length exceeds line width),
* a tab is also appended along with next line delimiter , we need to remove that.
*/
if (source.toString().endsWith(getIndentString())) {
source.delete((source.length() - getIndentString().length()), source.length());
}
}
} else {
appendSpaceBefore(node, toAppend.getText(), source);
}
} else if (type == CSSRegionContexts.CSS_DELIMITER || type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
RegionIterator it = new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
it.prev();
ITextRegion prev = it.prev();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (prev.getType() == CSSRegionContexts.CSS_S && TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), 0)[0] >= 0) {
source.append(delim);
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
} else if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int length = getLastLineLength(node, source);
int append = 1;
if (length + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
}
}
} else if (type == CSSRegionContexts.CSS_RBRACE || type == CSSRegionContexts.CSS_LBRACE) {
source.append(delim);
source.append(getIndent(node));
} else {
source.append(delim);
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
}
}
}
use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method decoratedIdentRegion.
/**
*/
protected String decoratedIdentRegion(CompoundRegion region, CSSCleanupStrategy stgy) {
if (isFormat())
return region.getText();
String text = null;
if (!stgy.isFormatSource())
text = region.getFullText();
else
text = region.getText();
if (region.getType() == CSSRegionContexts.CSS_STRING || region.getType() == CSSRegionContexts.CSS_URI)
return decoratedRegion(region, 0, stgy);
if (isCleanup()) {
if (stgy.getIdentCase() == CSSCleanupStrategy.ASIS || region.getType() == CSSRegionContexts.CSS_COMMENT)
return text;
else if (stgy.getIdentCase() == CSSCleanupStrategy.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (region.getType() == CSSRegionContexts.CSS_COMMENT)
return text;
else if (preferences.getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
return text.toUpperCase();
else
return text.toLowerCase();
}
Aggregations