use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertSemiColonForStyleDeclarationItem.
/**
*/
private CSSNodeImpl insertSemiColonForStyleDeclarationItem(IStructuredDocumentRegion region) {
// only target/net node is changed. nothing to do.
CSSNodeImpl targetNode = fCreationContext.getTargetNode();
if (targetNode instanceof ICSSStyleDeclItem) {
int offset = targetNode.getStartOffset();
// widen document region range
// ((CSSStyleDeclItemImpl)targetNode).setLastStructuredDocumentRegion(region);
CSSModelUtil.expandStructuredDocumentRegionContainer((CSSStyleDeclItemImpl) targetNode, region);
// psStructuredDocumentRegion indicates CSSStyleDeclItem
ICSSNode parentNode = targetNode.getParentNode();
fCreationContext.setTargetNode(parentNode);
ICSSNode next = null;
if (parentNode.hasChildNodes()) {
for (ICSSNode child = targetNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof CSSStructuredDocumentRegionContainer && offset < ((CSSStructuredDocumentRegionContainer) child).getStartOffset()) {
next = child;
break;
}
}
}
fCreationContext.setNextNode(next);
return targetNode;
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSModelParser method shrinkContainer.
/**
*/
void shrinkContainer(CSSStructuredDocumentRegionContainer parent, CSSStructuredDocumentRegionContainer child) {
if (child == null) {
return;
}
boolean bModified = false;
bModified = bModified || cleanupLastNode(child.getLastStructuredDocumentRegion(), parent);
bModified = bModified || cleanupFirstNode(child.getFirstStructuredDocumentRegion(), parent);
if (bModified) {
if (parent != null) {
for (ICSSNode node = parent.getFirstChild(); node != null; node = node.getNextSibling()) {
if (child != node && node instanceof CSSStructuredDocumentRegionContainer) {
((CSSStructuredDocumentRegionContainer) node).propagateRangeStructuredDocumentRegion();
}
}
}
}
child.setRangeStructuredDocumentRegion(null, null);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode 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.css.core.internal.provisional.document.ICSSNode 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);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSStyleDeclItemImpl method setCssValueText.
/**
* @param value
* java.lang.String
* @exception org.w3c.dom.DOMException
* The exception description.
*/
public void setCssValueText(String value) throws DOMException {
ICSSNode child = getFirstChild();
while (child != null) {
ICSSNode next = child.getNextSibling();
if (child instanceof ICSSPrimitiveValue) {
removeChild((CSSNodeImpl) child);
}
child = next;
}
setCssValueTextCore(value);
}
Aggregations