Search in sources :

Example 1 with ICSSNode

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;
}
Also used : ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 2 with ICSSNode

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);
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 3 with ICSSNode

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);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 4 with ICSSNode

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);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 5 with ICSSNode

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);
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Aggregations

ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)95 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)21 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)13 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)12 DOMException (org.w3c.dom.DOMException)12 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)11 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)11 Iterator (java.util.Iterator)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)9 Region (org.eclipse.jface.text.Region)8 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)6 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)5 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)5 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5