Search in sources :

Example 11 with IStructuredDocumentRegion

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

Example 12 with IStructuredDocumentRegion

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();
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Enumeration(java.util.Enumeration) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)

Example 13 with IStructuredDocumentRegion

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

Example 14 with IStructuredDocumentRegion

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

Example 15 with IStructuredDocumentRegion

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

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13