use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet 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.wst.css.core.internal.provisional.document.ICSSStyleSheet in project webtools.sourceediting by eclipse.
the class CSSStyleSheetImpl method getRules.
private void getRules(CSSRuleListImpl list, ICSSStyleSheet sheet, Stack refs) {
String href = sheet.getHref();
if (href != null) {
// Avoid circular @imports
if (refs.contains(href))
return;
refs.push(href);
}
boolean acceptImports = true;
for (ICSSNode node = sheet.getFirstChild(); node != null; node = node.getNextSibling()) {
// @import rules must precede all other rules, according to the spec
if (node.getNodeType() == ICSSNode.IMPORTRULE_NODE && acceptImports) {
CSSStyleSheet importSheet = ((ICSSImportRule) node).getStyleSheet();
if (importSheet instanceof ICSSStyleSheet)
getRules(list, (ICSSStyleSheet) importSheet, refs);
else
list.appendNode(node);
} else // Add the rule to the list
if (node instanceof CSSRule) {
list.appendNode(node);
if (node.getNodeType() != ICSSNode.CHARSETRULE_NODE)
acceptImports = false;
}
}
if (href != null)
refs.pop();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet in project webtools.sourceediting by eclipse.
the class CSSImportRuleImpl method releaseRule.
/**
*/
void releaseRule() {
if (fStyleSheet != null) {
ICSSStyleSheet sheet = fStyleSheet;
// to prevent loop, we must reset fStyleSheet
fStyleSheet = null;
// before all closing action
sheet.getModel().removeStyleListener(getOwnerDocument().getModel());
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) getAdapterFor(IModelProvideAdapter.class);
// }
if (adapter != null)
adapter.modelReleased(sheet.getModel());
sheet.getModel().releaseFromRead();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet in project webtools.sourceediting by eclipse.
the class CSSImportRuleImpl method closeStyleSheet.
/**
*/
void closeStyleSheet() {
if (fStyleSheet != null) {
ICSSStyleSheet sheet = fStyleSheet;
// to prevent loop, we must reset fStyleSheet
fStyleSheet = null;
// before all closing action
sheet.getModel().removeStyleListener(getOwnerDocument().getModel());
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) getAdapterFor(IModelProvideAdapter.class);
// }
if (adapter != null)
adapter.modelRemoved(sheet.getModel());
sheet.getModel().releaseFromRead();
}
}
Aggregations