use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion 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.text.ITextRegion 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.ITextRegion in project webtools.sourceediting by eclipse.
the class CSSDocumentCharsetDetector method getType.
private String getType(IStructuredDocumentRegion node) {
if (node == null)
return null;
ITextRegionList regions = node.getRegions();
if (regions == null || regions.size() == 0)
return null;
ITextRegion region = regions.get(0);
String result = region.getType();
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class MediaRuleFormatter method getLengthToReformatAfter.
/**
* @return int
* @param node
* org.eclipse.wst.css.core.model.interfaces.ICSSNode
* @param insertPos
* int
*/
public int getLengthToReformatAfter(ICSSNode node, int insertPos) {
if (node == null)
return 0;
IndexedRegion nnode = (IndexedRegion) node;
if (insertPos <= 0 || !nnode.contains(insertPos - 1))
return 0;
if (node.getFirstChild().getNextSibling() == node.getLastChild()) {
// inserted
// first style rule
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(insertPos);
if (flatNode == null)
return 0;
ITextRegion region = flatNode.getRegionAtCharacterOffset(insertPos);
if (region == null)
return 0;
RegionIterator it = new RegionIterator(flatNode, region);
while (it.hasNext()) {
region = it.next();
if (region.getType() == CSSRegionContexts.CSS_LBRACE)
break;
if (nnode.getEndOffset() <= it.getStructuredDocumentRegion().getEndOffset(region))
break;
}
int pos = it.getStructuredDocumentRegion().getStartOffset(region) - insertPos;
return (pos >= 0) ? pos : 0;
}
return super.getLengthToReformatAfter(node, insertPos);
}
Aggregations