use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getIndent.
/**
*/
protected String getIndent(ICSSNode node) {
if (node == null)
// $NON-NLS-1$
return "";
ICSSNode parent = node.getParentNode();
if (node instanceof ICSSAttr)
parent = ((ICSSAttr) node).getOwnerCSSNode();
if (parent == null)
// $NON-NLS-1$
return "";
if (node instanceof org.w3c.dom.css.CSSStyleDeclaration)
parent = parent.getParentNode();
if (parent == null)
// $NON-NLS-1$
return "";
String parentIndent = getIndent(parent);
if (parent instanceof org.w3c.dom.css.CSSRule)
return parentIndent + getIndentString();
if (node.getParentNode() instanceof ICSSStyleDeclaration)
return parentIndent + getIndentString();
return parentIndent;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class AttrFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
ICSSAttr attr = (ICSSAttr) node;
CSSCleanupStrategy stgy = getCleanupStrategy(node);
int end = ((IndexedRegion) node).getEndOffset();
if (end > 0) {
// format source
int start = ((IndexedRegion) node).getStartOffset();
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBetween(node, regions[i - 1], regions[i], source);
source.append(decoratedRegion(regions[i], 0, stgy));
}
} else if (attr.getName().equals(ICSSImportRule.HREF)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
} else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
} else if (attr.getName() == null || attr.getName().length() == 0) {
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else {
// counter attributes
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropValueRegion(regions[i], stgy));
}
}
} else {
// generate source
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
String value = attr.getValue();
if (value == null)
// $NON-NLS-1$
value = "";
if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
} else if (attr.getName().equals(ICSSImportRule.HREF)) {
String uri = org.eclipse.wst.css.core.internal.util.CSSLinkConverter.stripFunc(value);
// $NON-NLS-2$//$NON-NLS-1$
String func = preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER ? "URL(" : "url(";
if (preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI)) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
quote = CSSUtil.detectQuote(uri, quote);
// $NON-NLS-1$
value = func + quote + uri + quote + ")";
} else {
// $NON-NLS-1$
value = func + uri + ")";
}
} else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
if (// $NON-NLS-2$//$NON-NLS-1$
!value.startsWith("\"") && !value.startsWith("\'"))
value = quote + value;
if (// $NON-NLS-2$//$NON-NLS-1$
!value.endsWith("\"") && !value.endsWith("\'"))
value = value + quote;
} else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
} else if (attr.getName() == null || attr.getName().length() == 0) {
if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
} else {
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
value = value.toUpperCase();
else
value = value.toLowerCase();
}
source.append(value);
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class CharsetRuleFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
CSSCleanupStrategy stgy = getCleanupStrategy(node);
if (!ICSSCharsetRule.ENCODING.equalsIgnoreCase(attrName))
return -1;
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICSSCharsetRule.ENCODING);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IndexedRegion iNode = (IndexedRegion) node;
if (iNode.getEndOffset() <= 0)
return -1;
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(node.getOwnerDocument().getModel().getStructuredDocument(), new FormatRegion(iNode.getStartOffset(), iNode.getEndOffset() - iNode.getStartOffset()), stgy);
for (int i = regions.length - 1; i >= 0; i--) {
if (regions[i].getType() != CSSRegionContexts.CSS_COMMENT)
return regions[i].getStartOffset();
}
return iNode.getEndOffset();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class CounterFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
IndexedRegion iNode = (IndexedRegion) node;
if (ICounter.IDENTIFIER.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.IDENTIFIER);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
if (iNode.getEndOffset() <= 0)
return -1;
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else if (ICounter.LISTSTYLE.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.LISTSTYLE);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR)
return it.getStructuredDocumentRegion().getEndOffset(region);
else if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else if (ICounter.SEPARATOR.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.SEPARATOR);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
boolean hasComma = false;
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR) {
if (!hasComma)
hasComma = true;
else
return it.getStructuredDocumentRegion().getEndOffset(region);
} else if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else
return -1;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
if (!ICSSStyleDeclItem.IMPORTANT.equalsIgnoreCase(attrName))
return -1;
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICSSStyleDeclItem.IMPORTANT);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IndexedRegion iNode = (IndexedRegion) node;
if (iNode.getEndOffset() <= 0)
return -1;
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(node.getOwnerDocument().getModel().getStructuredDocument(), new FormatRegion(iNode.getStartOffset(), iNode.getEndOffset() - iNode.getStartOffset()), getCleanupStrategy(node));
for (int i = regions.length - 1; i >= 0; i--) {
if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_IMPORTANT)
return regions[i].getStartOffset();
}
return iNode.getEndOffset();
}
Aggregations