use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertSemiColonForRule.
/**
*/
private CSSNodeImpl insertSemiColonForRule(IStructuredDocumentRegion region) {
IStructuredDocumentRegion keyRegion = CSSUtil.findPreviousSignificantNode(region);
String type = CSSUtil.getStructuredDocumentRegionType(keyRegion);
CSSNodeImpl inserted = null;
if (type == CSSRegionContexts.CSS_IMPORT) {
inserted = insertImportRule(keyRegion, region);
} else if (type == CSSRegionContexts.CSS_CHARSET) {
inserted = insertCharsetRule(keyRegion, region);
}
return inserted;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertStructuredDocumentRegions.
/**
*/
private void insertStructuredDocumentRegions(IStructuredDocumentRegionList regionList) {
for (Enumeration e = regionList.elements(); e.hasMoreElements(); ) {
IStructuredDocumentRegion region = (IStructuredDocumentRegion) e.nextElement();
if (region == null) {
continue;
}
insertStructuredDocumentRegion(region);
if (fCreationContext.isToReparse()) {
int origStart = region.getEnd();
int origEnd = regionList.item(regionList.getLength() - 1).getEnd();
int newStart = fCreationContext.getReparseStart();
int newEnd = fCreationContext.getReparseEnd();
if (newStart < origStart || origEnd < newEnd) {
IStructuredDocumentRegionList newNodeList = getStructuredDocumentRegionList(newStart, newEnd);
setupCreationContext(newNodeList.item(0));
insertStructuredDocumentRegions(newNodeList);
return;
} else {
fCreationContext.resetReparseRange();
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method findBraceClose.
/**
*/
private IStructuredDocumentRegion findBraceClose(int depth, IStructuredDocumentRegion start, boolean bBreakSibling) {
IStructuredDocumentRegion result = null;
int braceLevel = 0;
IStructuredDocumentRegion prevNode = null;
IStructuredDocumentRegion region = start.getNext();
for (; region != null; region = region.getNext()) {
int offset = region.getStart();
if (offset < 0) {
Assert.isTrue(false);
break;
}
CSSNodeImpl node = getNodeAt(offset);
int depthHit = (node != null) ? CSSModelUtil.getDepth(node) : -1;
if (depth <= depthHit) {
// sibling is found before "}"
if (bBreakSibling) {
CSSNodeImpl parent = (CSSNodeImpl) node.getParentNode();
while (depth <= CSSModelUtil.getDepth(parent)) {
node = parent;
parent = (CSSNodeImpl) parent.getParentNode();
}
if (parent != null && node != null) {
parent.removeChild(node);
}
} else {
result = prevNode;
break;
}
}
String type = CSSUtil.getStructuredDocumentRegionType(region);
if (type == CSSRegionContexts.CSS_LBRACE) {
braceLevel++;
}
if (type == CSSRegionContexts.CSS_RBRACE) {
braceLevel--;
if (braceLevel < 0) {
result = region;
break;
}
}
prevNode = region;
}
if (result == null && region == null) {
// reach the end of document
result = prevNode;
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSModelParser method resetCreationTarget.
/**
*/
private void resetCreationTarget(IStructuredDocumentRegion newStructuredDocumentRegion) {
if (newStructuredDocumentRegion == null || newStructuredDocumentRegion.getStartOffset() <= 0) {
// top of document
fCreationContext.setTargetNode(fDocument);
fCreationContext.setNextNode(fDocument.getFirstChild());
return;
}
int cursorPos = newStructuredDocumentRegion.getStartOffset();
CSSNodeImpl cursorNode = getNodeAt(cursorPos);
if (cursorNode == null) {
// end of document
cursorNode = (CSSNodeImpl) fDocument;
}
// find edge of tree node
CSSNodeImpl node = null;
// boolean bOverSemiColon = false;
boolean bOverOpenBrace = false;
IStructuredDocumentRegion flatNode;
for (flatNode = newStructuredDocumentRegion; flatNode != null; flatNode = flatNode.getPrevious()) {
node = getNodeAt(flatNode.getStartOffset());
if (node == null) {
node = (CSSNodeImpl) fDocument;
}
if (node != cursorNode || node.getStartOffset() == flatNode.getStartOffset()) {
break;
}
if (flatNode != newStructuredDocumentRegion) {
String type = CSSUtil.getStructuredDocumentRegionType(flatNode);
// } else
if (type == CSSRegionContexts.CSS_LBRACE) {
bOverOpenBrace = true;
}
}
}
CSSNodeImpl targetNode = null;
// } else
if (cursorNode == node) {
// BBBBBBBBBB cursorNode:A , node:B -> target is A
if (bOverOpenBrace && cursorNode instanceof CSSRuleDeclContainer) {
targetNode = (CSSNodeImpl) ((CSSRuleDeclContainer) cursorNode).getStyle();
} else {
targetNode = cursorNode;
}
} else {
// v<--|
// AAA
// BBBBBBBBBB cursorNode:B , node:A -> depend on A's node type
short nodeType = node.getNodeType();
if (nodeType == ICSSNode.STYLEDECLITEM_NODE || nodeType == ICSSNode.CHARSETRULE_NODE || nodeType == ICSSNode.IMPORTRULE_NODE) {
// targetNode = (CSSNodeImpl)((bOverSemiColon) ?
// node.getParentNode() : node); // NP
String regionType = CSSUtil.getStructuredDocumentRegionType(flatNode);
if (regionType == CSSRegionContexts.CSS_DELIMITER || regionType == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
targetNode = (CSSNodeImpl) node.getParentNode();
} else {
targetNode = node;
}
} else if (CSSUtil.getStructuredDocumentRegionType(flatNode) == CSSRegionContexts.CSS_RBRACE) {
targetNode = (CSSNodeImpl) node.getParentNode();
} else {
targetNode = node;
}
}
fCreationContext.setTargetNode(targetNode);
ICSSNode next = null;
if (targetNode.hasChildNodes()) {
for (ICSSNode child = targetNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof CSSStructuredDocumentRegionContainer && cursorPos < ((CSSStructuredDocumentRegionContainer) child).getStartOffset()) {
next = child;
break;
}
}
}
fCreationContext.setNextNode(next);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.
the class CSSStyleDeclItemImpl method getCSSValueText.
/**
* @return java.lang.String
*/
public java.lang.String getCSSValueText() {
if (getFirstChild() == null)
// $NON-NLS-1$
return "";
// check whether children has flatnodes
ICSSNode child = getFirstChild();
while (child != null) {
if (((IndexedRegion) child).getEndOffset() <= 0)
return generateValueSource();
child = child.getNextSibling();
}
IStructuredDocumentRegion node = getFirstStructuredDocumentRegion();
int start = ((IndexedRegion) getFirstChild()).getStartOffset() - node.getStartOffset();
int end = ((IndexedRegion) getLastChild()).getEndOffset() - node.getStartOffset();
return node.getText().substring(start, end);
}
Aggregations