use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getRegions.
/**
*/
protected CompoundRegion[] getRegions(IStructuredDocument model, IRegion reg, IRegion exceptFor, String pickupType) {
int start = reg.getOffset();
int end = reg.getOffset() + reg.getLength();
int startE = (exceptFor != null) ? exceptFor.getOffset() : -1;
int endE = (exceptFor != null) ? exceptFor.getOffset() + exceptFor.getLength() : 0;
ArrayList list = new ArrayList();
IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
boolean pickuped = false;
while (flatNode != null && flatNode.getStartOffset() < end) {
ITextRegionList regionList = flatNode.getRegions();
Iterator it = regionList.iterator();
while (it.hasNext()) {
ITextRegion region = (ITextRegion) it.next();
if (flatNode.getStartOffset(region) < start)
continue;
if (end <= flatNode.getStartOffset(region))
break;
if (startE >= 0 && startE <= flatNode.getStartOffset(region) && flatNode.getEndOffset(region) <= endE)
continue;
if (region.getType() == CSSRegionContexts.CSS_COMMENT || region.getType() == CSSRegionContexts.CSS_CDC || region.getType() == CSSRegionContexts.CSS_CDO)
list.add(new CompoundRegion(flatNode, region));
else if (!pickuped && region.getType() == pickupType) {
list.add(new CompoundRegion(flatNode, region));
pickuped = true;
}
}
flatNode = flatNode.getNext();
}
if (list.size() > 0) {
CompoundRegion[] regions = new CompoundRegion[list.size()];
list.toArray(regions);
return regions;
}
return new CompoundRegion[0];
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getRegionsWithoutWhiteSpaces.
/**
*/
protected CompoundRegion[] getRegionsWithoutWhiteSpaces(IStructuredDocument model, IRegion reg, CSSCleanupStrategy stgy) {
int start = reg.getOffset();
int end = reg.getOffset() + reg.getLength() - 1;
ArrayList list = new ArrayList();
IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
while (flatNode != null && flatNode.getStartOffset() <= end) {
ITextRegionList regionList = flatNode.getRegions();
Iterator it = regionList.iterator();
while (it.hasNext()) {
ITextRegion region = (ITextRegion) it.next();
if (flatNode.getStartOffset(region) < start)
continue;
if (end < flatNode.getStartOffset(region))
break;
if (// for
region.getType() != CSSRegionContexts.CSS_S || (isCleanup() && !stgy.isFormatSource()))
// not
// formatting
// case
// on
// cleanup
// action
list.add(new CompoundRegion(flatNode, region));
}
flatNode = flatNode.getNext();
}
if (list.size() > 0) {
CompoundRegion[] regions = new CompoundRegion[list.size()];
list.toArray(regions);
return regions;
}
return new CompoundRegion[0];
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion 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.text.IStructuredDocumentRegion 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class ImportRuleFormatter 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 (!ICSSImportRule.HREF.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);
it.next();
} else
context.start = it.getStructuredDocumentRegion().getStartOffset(region);
it.next();
it.next();
if (it.hasNext()) {
ITextRegion next = it.next();
if (next.getType() == CSSRegionContexts.CSS_S)
context.end = it.getStructuredDocumentRegion().getEndOffset(next);
else
context.end = it.getStructuredDocumentRegion().getEndOffset(region);
} else
context.end = it.getStructuredDocumentRegion().getEndOffset(region);
} else {
ICSSNode child = node.getFirstChild();
IStructuredDocumentRegion flatNode = null;
ITextRegion region = null;
if (child == null) {
flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(((IndexedRegion) node).getEndOffset() - 1);
region = flatNode.getRegionAtCharacterOffset(((IndexedRegion) node).getEndOffset() - 1);
} else {
flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(((IndexedRegion) child).getStartOffset() - 1);
region = flatNode.getRegionAtCharacterOffset(((IndexedRegion) child).getStartOffset() - 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());
// $NON-NLS-1$
appendSpaceBefore(node, "", buf);
}
return buf;
}
Aggregations