Search in sources :

Example 91 with IStructuredDocumentRegion

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

the class CSSModelCreationContext method setLast.

/**
 */
void setLast() {
    fNextNode = null;
    if (!(fRootNode instanceof CSSStructuredDocumentRegionContainer)) {
        fTargetNode = fRootNode;
    } else {
        IStructuredDocumentRegion lastStructuredDocumentRegion = ((CSSStructuredDocumentRegionContainer) fRootNode).getLastStructuredDocumentRegion();
        CSSNodeImpl node = fRootNode;
        while (node != null) {
            ICSSNode lastChild = node.getLastChild();
            if (lastChild instanceof CSSStructuredDocumentRegionContainer && ((CSSStructuredDocumentRegionContainer) lastChild).getLastStructuredDocumentRegion() == lastStructuredDocumentRegion) {
                node = (CSSNodeImpl) lastChild;
            } else {
                break;
            }
        }
        fTargetNode = node;
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 92 with IStructuredDocumentRegion

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

the class CSSModelImpl method regionsReplaced.

public void regionsReplaced(RegionsReplacedEvent structuredDocumentEvent) {
    if (structuredDocumentEvent == null)
        return;
    IStructuredDocumentRegion flatNode = structuredDocumentEvent.getStructuredDocumentRegion();
    if (flatNode == null)
        return;
    ITextRegionList oldRegions = structuredDocumentEvent.getOldRegions();
    ITextRegionList newRegions = structuredDocumentEvent.getNewRegions();
    if (oldRegions == null && newRegions == null)
        return;
    fStructuredDocumentUpdate = true;
    CSSModelParser parser = getParser();
    parser.setStructuredDocumentEvent(structuredDocumentEvent);
    parser.replaceRegions(flatNode, newRegions, oldRegions);
    fStructuredDocumentUpdate = false;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 93 with IStructuredDocumentRegion

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

the class CSSModelImpl method regionChanged.

public void regionChanged(RegionChangedEvent structuredDocumentEvent) {
    if (structuredDocumentEvent == null) {
        return;
    }
    IStructuredDocumentRegion flatNode = structuredDocumentEvent.getStructuredDocumentRegion();
    if (flatNode == null) {
        return;
    }
    ITextRegion region = structuredDocumentEvent.getRegion();
    if (region == null) {
        return;
    }
    fStructuredDocumentUpdate = true;
    CSSModelParser parser = getParser();
    parser.setStructuredDocumentEvent(structuredDocumentEvent);
    parser.changeRegion(flatNode, region);
    fStructuredDocumentUpdate = false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 94 with IStructuredDocumentRegion

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

the class CSSModelDeletionContext method setupContext.

/**
 */
void setupContext(IStructuredDocumentRegionList newStructuredDocumentRegions, IStructuredDocumentRegionList oldStructuredDocumentRegions) {
    IStructuredDocumentRegion flatNode = null;
    fOldLength = CSSUtil.getTextLength(oldStructuredDocumentRegions);
    if (oldStructuredDocumentRegions != null && 0 < oldStructuredDocumentRegions.getLength() && (flatNode = oldStructuredDocumentRegions.item(0)) != null) {
        fOldStart = flatNode.getStart();
    } else {
        fOldStart = -1;
    }
    fNewLength = CSSUtil.getTextLength(newStructuredDocumentRegions);
    if (newStructuredDocumentRegions != null && 0 < newStructuredDocumentRegions.getLength() && (flatNode = newStructuredDocumentRegions.item(0)) != null) {
        fNewStart = flatNode.getStart();
        fRemovedRangeBegin = fNewStart;
        fRemovedRangeEnd = fNewStart + fNewLength;
    } else {
        fNewStart = -1;
        fRemovedRangeBegin = fRemovedRangeEnd = -1;
    }
    fLengthDifference = fNewLength - fOldLength;
    fOldRegionsList = new HashSet();
    final Enumeration elements = oldStructuredDocumentRegions.elements();
    while (elements.hasMoreElements()) {
        fOldRegionsList.add(elements.nextElement());
    }
    // cleanup nodes
    while (0 < fNodesToBeRemoved.getLength()) {
        fNodesToBeRemoved.removeNode(0);
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Enumeration(java.util.Enumeration) HashSet(java.util.HashSet)

Example 95 with IStructuredDocumentRegion

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

the class CSSModelDeletionContext method findDeletionTarget.

/**
 */
CSSStructuredDocumentRegionContainer findDeletionTarget(CSSNodeImpl parent, IStructuredDocumentRegion flatNode) {
    CSSStructuredDocumentRegionContainer target = findContainer(parent, flatNode);
    if (target == null) {
        return null;
    }
    // System.out.print(flatNode.toString() + ": ");
    // child a(=====)b(=====)c
    // parent (================) a,c can remove parent, but b cannot.
    ICSSNode child;
    for (child = target.getFirstChild(); child != null && !(child instanceof CSSStructuredDocumentRegionContainer); child = child.getNextSibling()) {
    // just advancing
    }
    if (child == null) {
        // has no child containers.
        return target;
    } else {
        IStructuredDocumentRegion firstNode = ((CSSStructuredDocumentRegionContainer) child).getFirstStructuredDocumentRegion();
        if (flatNode.getStart() < getOriginalOffset(firstNode)) {
            // a
            return target;
        }
    }
    for (child = target.getLastChild(); child != null && !(child instanceof CSSStructuredDocumentRegionContainer); child = child.getPreviousSibling()) {
    // just advancing
    }
    if (child == null) {
        // has no child containers.
        return target;
    } else {
        IStructuredDocumentRegion firstNode = ((CSSStructuredDocumentRegionContainer) child).getFirstStructuredDocumentRegion();
        if (getOriginalOffset(firstNode) < flatNode.getStart()) {
            // c
            return target;
        }
    }
    // b
    return null;
}
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