use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion 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.sse.core.internal.provisional.IndexedRegion 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();
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method getFirstChildRegionLength.
/**
*/
private int getFirstChildRegionLength(ICSSNode node) {
ICSSNode firstChild = node.getFirstChild();
if (firstChild == null)
return 1;
int start = ((IndexedRegion) firstChild).getStartOffset();
RegionIterator itr = new RegionIterator(node.getOwnerDocument().getModel().getStructuredDocument(), start);
while (itr.hasNext()) {
ITextRegion reg = itr.next();
if (reg != null && reg.getType() != CSSRegionContexts.CSS_S)
return reg.getTextLength();
}
return 1;
}
use of org.eclipse.wst.sse.core.internal.provisional.IndexedRegion 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.IndexedRegion in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatAttrChanged.
/**
*/
public StringBuffer formatAttrChanged(ICSSNode node, ICSSAttr attr, boolean insert, AttrChangeContext context) {
StringBuffer buf = new StringBuffer();
if (node == null || attr == null)
return buf;
if (!ICSSStyleDeclItem.IMPORTANT.equalsIgnoreCase(attr.getName()))
return buf;
// get region to replace
if (context != null && ((IndexedRegion) node).getEndOffset() > 0) {
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0) {
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(((IndexedRegion) attr).getStartOffset());
ITextRegion region = flatNode.getRegionAtCharacterOffset(((IndexedRegion) attr).getStartOffset());
RegionIterator it = new RegionIterator(flatNode, region);
it.prev();
if (it.hasPrev()) {
ITextRegion prev = it.prev();
if (prev.getType() == CSSRegionContexts.CSS_S)
context.start = it.getStructuredDocumentRegion().getStartOffset(prev);
else
context.start = it.getStructuredDocumentRegion().getStartOffset(region);
} else
context.start = it.getStructuredDocumentRegion().getStartOffset(region);
context.end = it.getStructuredDocumentRegion().getEndOffset(region);
} else {
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(((IndexedRegion) node).getEndOffset() - 1);
ITextRegion region = flatNode.getRegionAtCharacterOffset(((IndexedRegion) node).getEndOffset() - 1);
if (region.getType() == CSSRegionContexts.CSS_S) {
context.start = flatNode.getStartOffset(region);
context.end = flatNode.getEndOffset(region);
} else {
context.start = flatNode.getEndOffset();
context.end = flatNode.getEndOffset();
}
}
}
// generate text
if (insert && attr.getValue() != null && attr.getValue().length() > 0) {
appendSpaceBefore(node, attr.getValue(), buf);
buf.append(attr.getValue());
}
return buf;
}
Aggregations