Search in sources :

Example 36 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StructuredDocumentWalker method getPrevNodeInCurrent.

/**
 * Old Nodes: --[O1]--[O2]--[O3]--- : / \ Current Nodes:
 * ---[C1]-----[C2]-----[C3]-----[C4]---
 *
 * Input: O* -> Output: C1 Input: Cn -> Output: Cn-1
 */
public IStructuredDocumentRegion getPrevNodeInCurrent(IStructuredDocumentRegion node) {
    IStructuredDocumentRegion prevNode = null;
    if (isOldNode(node)) {
        IStructuredDocumentRegion oldStartNode = fOldStructuredDocumentRegionList.item(0);
        int newEnd = oldStartNode.getStart() - 1;
        prevNode = fStructuredDocument.getRegionAtCharacterOffset(newEnd);
    } else if (node != null) {
        prevNode = node.getPrevious();
    }
    return prevNode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 37 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StructuredDocumentWalker method getNextNodeInCurrent.

/**
 * Old Nodes: --[O1]--[O2]--[O3]--- : / \ Current Nodes:
 * ---[C1]-----[C2]-----[C3]-----[C4]---
 *
 * Input: O* -> Output: C4 Input: Cn -> Output: Cn+1
 */
public IStructuredDocumentRegion getNextNodeInCurrent(IStructuredDocumentRegion node) {
    IStructuredDocumentRegion nextNode = null;
    if (isOldNode(node)) {
        IStructuredDocumentRegion oldEndNode = fOldStructuredDocumentRegionList.item(fOldStructuredDocumentRegionList.getLength() - 1);
        int newStart = oldEndNode.getEnd() + fLengthDifference;
        nextNode = fStructuredDocument.getRegionAtCharacterOffset(newStart);
    } else if (node != null) {
        nextNode = node.getNext();
    }
    return nextNode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 38 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class CSSSourceParser method getRegions.

public List getRegions() {
    IStructuredDocumentRegion headNode = null;
    if (!getTokenizer().isEOF()) {
        headNode = getDocumentRegions();
    // throw new IllegalStateException("parsing has not finished");
    }
    // for memory recovery, we assume if someone
    // requests all regions, we can reset our big
    // memory consuming objects
    // but the new "getRegions" method is then more expensive.
    // I don't think its used much, though.
    List localRegionsList = getRegions(headNode);
    primReset();
    return localRegionsList;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 39 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class CSSSourceParser method getDocumentRegions.

public IStructuredDocumentRegion getDocumentRegions() {
    IStructuredDocumentRegion headnode = null;
    if (headnode == null) {
        if (Debug.perfTest) {
            fStartTime = System.currentTimeMillis();
        }
        headnode = parseNodes();
        if (Debug.perfTest) {
            fStopTime = System.currentTimeMillis();
            // $NON-NLS-1$
            System.out.println(" -- creating nodes of IStructuredDocument -- ");
            // $NON-NLS-2$//$NON-NLS-1$
            System.out.println(" Time parse and init all regions: " + (fStopTime - fStartTime) + " (msecs)");
            // System.out.println(" for " + fRegions.size() + "
            // Regions");//$NON-NLS-2$//$NON-NLS-1$
            // $NON-NLS-2$//$NON-NLS-1$
            System.out.println("      and " + _countNodes(headnode) + " Nodes");
        }
    }
    return headnode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 40 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class CSSSourceParser method parseNodes.

private IStructuredDocumentRegion parseNodes() {
    // regions are initially reported as complete offsets within the
    // scanned input
    // they are adjusted here to be indexes from the currentNode's start
    // offset
    IStructuredDocumentRegion headNode = null;
    IStructuredDocumentRegion lastNode = null;
    ITextRegion region = null;
    IStructuredDocumentRegion currentNode = null;
    String type = null;
    String currentRegionType = null;
    while ((region = getNextRegion()) != null) {
        type = region.getType();
        if (mustBeStart(type, currentRegionType) && currentNode != null) {
            currentNode.setEnded(true);
        }
        if ((currentNode != null && currentNode.isEnded()) || currentNode == null) {
            if (currentNode != null && !currentNode.isEnded()) {
                currentNode.setEnded(true);
            }
            lastNode = currentNode;
            currentNode = createStructuredDocumentRegion(type);
            currentRegionType = type;
            if (lastNode != null) {
                lastNode.setNext(currentNode);
            }
            currentNode.setPrevious(lastNode);
            currentNode.setStart(region.getStart());
        }
        currentNode.addRegion(region);
        currentNode.setLength(region.getStart() + region.getLength() - currentNode.getStart());
        region.adjustStart(-currentNode.getStart());
        if (mustBeEnd(type)) {
            currentNode.setEnded(true);
        }
        if (headNode == null && currentNode != null) {
            headNode = currentNode;
        }
    }
    if (currentNode != null && !currentNode.isEnded()) {
        currentNode.setEnded(true);
    }
    primReset();
    return headNode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

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