use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatPost.
/**
*/
protected void formatPost(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(decoratedIdentRegion(regions[i], stgy));
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter 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);
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
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++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropNameRegion(regions[i], stgy));
}
} else {
// generatoe source
ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER)
source.append(item.getPropertyName().toUpperCase());
else
source.append(item.getPropertyName());
int k = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
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 + k + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(getIndentString());
// no space is necessary
k = 0;
}
}
// no delimiter case
while (k-- > 0) // $NON-NLS-1$
source.append(" ");
// $NON-NLS-1$
source.append(":");
}
if (node.getFirstChild() != null && (!isCleanup() || getCleanupStrategy(node).isFormatSource())) {
appendAfterColonSpace(node, source);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class UnknownRuleFormatter 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(decoratedPropValueRegion(regions[i], stgy));
}
if (needS(outside[1]) && !isIncludesPreEnd(node, region))
appendSpaceBefore(node, outside[1], source);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class CSSStyleSheetImpl method insertRule.
/**
* Used to insert a new rule into the style sheet. The new rule now
* becomes part of the cascade.
*
* @param rule
* The parsable text representing the rule. For rule sets this
* contains both the selector and the style declaration. For
* at-rules, this specifies both the at-identifier and the rule
* content.
* @param index
* The index within the style sheet's rule list of the rule
* before which to insert the specified rule. If the specified
* index is equal to the length of the style sheet's rule
* collection, the rule will be added to the end of the style
* sheet.
* @return The index within the style sheet's rule collection of the newly
* inserted rule.
* @exception DOMException
* HIERARCHY_REQUEST_ERR: Raised if the rule cannot be
* inserted at the specified index e.g. if an
* <code>@import</code> rule is inserted after a standard rule set or other
* at-rule. <br>
* INDEX_SIZE_ERR: Raised if the specified index is not a valid
* insertion point. <br>
* NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is
* readonly. <br>
* SYNTAX_ERR: Raised if the specified rule has a syntax error and
* is unparsable.
*/
public int insertRule(String rule, int index) throws DOMException {
int length = getCssRules().getLength();
if (index < 0 || length < index)
// $NON-NLS-1$
throw new DOMException(DOMException.INDEX_SIZE_ERR, "");
IStructuredDocument doc = getModel().getStructuredDocument();
CSSRuleImpl refRule = (length != index) ? getIndexedRule(index) : null;
int offset = (refRule != null) ? refRule.getStartOffset() : doc.getLength();
doc.replaceText(this, offset, 0, rule);
// insertBefore((CSSNodeImpl) createCSSRule(rule),refRule);
return index;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method removeText.
/**
*/
private StructuredDocumentEvent removeText(int start, int length) {
StructuredDocumentEvent result = null;
IStructuredDocument structuredDocument = fModel.getStructuredDocument();
if (structuredDocument != null) {
// $NON-NLS-1$
result = structuredDocument.replaceText(fModel, start, length, new String(""));
}
return result;
}
Aggregations