Search in sources :

Example 66 with IStructuredDocumentRegion

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

the class JSONModelImpl method getIndexedRegion.

@Override
public IndexedRegion getIndexedRegion(int offset) {
    if (this.document == null)
        return null;
    // search in document children
    IJSONNode parent = null;
    int length = this.document.getEndOffset();
    if (offset * 2 < length) {
        // search from the first
        IJSONNode child = (IJSONNode) this.document.getFirstChild();
        while (child != null) {
            if (child.getEndOffset() <= offset) {
                child = (IJSONNode) child.getNextSibling();
                continue;
            }
            if (child.getStartOffset() > offset) {
                break;
            }
            IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
            if (startStructuredDocumentRegion != null) {
                if (startStructuredDocumentRegion.getEnd() > offset)
                    return child;
            }
            IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                if (endStructuredDocumentRegion.getStart() <= offset) {
                    if (child instanceof IJSONPair) {
                        IJSONValue value = ((IJSONPair) child).getValue();
                        if (value instanceof IJSONObject || value instanceof IJSONArray) {
                            if (value.getStartOffset() < offset) {
                                child = value;
                                continue;
                            }
                        }
                    }
                    return child;
                }
            }
            // dig more
            parent = child;
            if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
                IJSONPair pair = (IJSONPair) parent;
                child = pair.getValue();
            } else {
                child = (IJSONNode) parent.getFirstChild();
            }
        }
    } else {
        // search from the last
        IJSONNode child = (IJSONNode) this.document.getLastChild();
        while (child != null) {
            if (child.getStartOffset() > offset) {
                child = (IJSONNode) child.getPreviousSibling();
                continue;
            }
            if (child.getEndOffset() <= offset) {
                break;
            }
            IStructuredDocumentRegion startStructuredDocumentRegion = child.getStartStructuredDocumentRegion();
            if (startStructuredDocumentRegion != null) {
                if (startStructuredDocumentRegion.getEnd() > offset)
                    return child;
            }
            IStructuredDocumentRegion endStructuredDocumentRegion = child.getEndStructuredDocumentRegion();
            if (endStructuredDocumentRegion != null) {
                if (endStructuredDocumentRegion.getStart() <= offset) {
                    if (child instanceof IJSONPair) {
                        IJSONValue value = ((IJSONPair) child).getValue();
                        if (value instanceof IJSONObject || value instanceof IJSONArray) {
                            if (value.getStartOffset() < offset) {
                                child = value;
                                continue;
                            }
                        }
                    }
                    return child;
                }
            }
            // dig more
            parent = child;
            if (parent != null && parent.getNodeType() == IJSONNode.PAIR_NODE) {
                IJSONPair pair = (IJSONPair) parent;
                child = pair.getValue();
            } else {
                child = (IJSONNode) parent.getLastChild();
            }
        }
    }
    return parent != null ? parent : document.getFirstChild();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IJSONArray(org.eclipse.wst.json.core.document.IJSONArray) IJSONPair(org.eclipse.wst.json.core.document.IJSONPair) IJSONValue(org.eclipse.wst.json.core.document.IJSONValue) IJSONObject(org.eclipse.wst.json.core.document.IJSONObject) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode)

Example 67 with IStructuredDocumentRegion

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

the class JSONModelImpl method regionChanged.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.sse.core.internal.provisional.events.
	 * IStructuredDocumentListener
	 * #regionChanged(org.eclipse.wst.sse.core.internal
	 * .provisional.events.RegionChangedEvent)
	 */
@Override
public void regionChanged(RegionChangedEvent event) {
    if (event == null)
        return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
        return;
    ITextRegion region = event.getRegion();
    if (region == null)
        return;
    JSONModelUpdater updater = getActiveUpdater();
    if (updater != null) {
        // being updated
        try {
            updater.changeRegion(event, flatNode, region);
        } catch (Exception ex) {
            Logger.logException(ex);
            this.refresh = true;
            handleRefresh();
        } finally {
            setActive(null);
        }
        // checkForReinit();
        return;
    }
    JSONModelNotifier notifier = getModelNotifier();
    boolean isChanging = notifier.isChanging();
    if (!isChanging)
        notifier.beginChanging();
    JSONModelParser parser = getModelParser();
    setActive(parser);
    try {
        parser.changeRegion(event, flatNode, region);
    /* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486860 */
    // this.refresh = true;
    // handleRefresh();
    } catch (Exception ex) {
        Logger.logException(ex);
        this.refresh = true;
        handleRefresh();
    } finally {
        setActive(null);
        if (!isChanging) {
            notifier.endChanging();
            handleRefresh();
        }
    }
// checkForReinit();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 68 with IStructuredDocumentRegion

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

the class JSPActionValidator method performValidation.

protected void performValidation(IFile f, IReporter reporter, IStructuredModel model, IRegion validateRegion) {
    loadPreferences(f);
    IStructuredDocument sDoc = model.getStructuredDocument();
    fIsELIgnored = isElIgnored(f.getFullPath(), model);
    // iterate all document regions
    IStructuredDocumentRegion region = sDoc.getRegionAtCharacterOffset(validateRegion.getOffset());
    while (region != null && !reporter.isCancelled() && (region.getStartOffset() <= (validateRegion.getOffset() + validateRegion.getLength()))) {
        if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
            // only checking directives
            processDirective(reporter, f, model, region);
            fTaglibPrefixes.clear();
        } else if (region.getType() == DOMRegionContext.XML_TAG_NAME) {
            // and jsp tags
            String tagName = getStartTagName(region);
            int colonPosition = tagName.indexOf(':');
            if (colonPosition > -1) {
                // get tag's prefix and check if it's really a jsp action
                // tag
                String prefix = tagName.substring(0, colonPosition);
                if (getTaglibPrefixes(sDoc).contains(prefix))
                    processDirective(reporter, f, model, region);
            }
        }
        region = region.getNext();
    }
    unloadPreferences();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 69 with IStructuredDocumentRegion

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

the class JSPReParser method isBreakingWithNestedTag.

/**
 * Verifies that the regions given, representing the regions touched by a
 * text change have: 1) ...an insertion at the textEndOffset of an
 * XML_TAG_OPEN that's in it's own IStructuredDocumentRegion and preceded
 * by an unended IStructuredDocumentRegion 2) ...a deletion happening in
 * an XML_EMPTY_TAG_CLOSE that ends a ITextRegionContainer 3) ...an
 * insertion happening with a ' <' character somewhere in an XML attribute
 * name or value 4) ...a deletion of a normal XML_TAG_CLOSE since
 * subsequent tags become attribute values
 */
private boolean isBreakingWithNestedTag(boolean changesIncludeA_lt, boolean delsIncludeA_gt, IStructuredDocumentRegion parent, ITextRegion region) {
    boolean result = false;
    IStructuredDocumentRegion previous = parent.getPrevious();
    // case 1 test
    if (parent.getRegions().size() == 1 && region.getType() == DOMRegionContext.XML_TAG_OPEN && (previous == null || (!previous.isEnded() || previous.getType() == DOMRegionContext.XML_CONTENT))) {
        result = true;
    }
    // case 2 test
    if (region instanceof ITextRegionContainer) {
        ITextRegionContainer container = (ITextRegionContainer) region;
        ITextRegion internal = container.getRegions().get(container.getRegions().size() - 1);
        if (internal.getType() == DOMRegionContext.WHITE_SPACE && container.getRegions().size() >= 2)
            internal = container.getRegions().get(container.getRegions().size() - 2);
        if (internal.getType() == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
            result = true;
        }
    }
    // case 3 test
    if (changesIncludeA_lt && (region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME || region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)) {
        result = true;
    }
    // case 4 test
    if (delsIncludeA_gt && region.getType() == DOMRegionContext.XML_TAG_CLOSE) {
        result = true;
    }
    return result;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 70 with IStructuredDocumentRegion

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

the class JSPReParser method findDirtyEnd.

protected IStructuredDocumentRegion findDirtyEnd(int end) {
    IStructuredDocumentRegion result = super.findDirtyEnd(end);
    // check it first.
    if (isJSPEmbeddedStartOrEnd(result)) {
        result = fStructuredDocument.getLastStructuredDocumentRegion();
    } else {
        // flatnodes needlessly.
        if (result != dirtyStart) {
            IStructuredDocumentRegion searchNode = dirtyStart;
            do {
                if (isJSPEmbeddedStartOrEnd(searchNode)) {
                    result = fStructuredDocument.getLastStructuredDocumentRegion();
                    break;
                } else {
                    searchNode = searchNode.getNext();
                }
            // if we get to the current dirty end, or end of
            // flatnodes, without finding JSP region then we
            // don't need to check further
            } while ((searchNode != result) && (searchNode != null));
        }
    }
    // from being changed to null
    if (result != null)
        fStructuredDocument.setCachedDocumentRegion(result);
    dirtyEnd = result;
    return dirtyEnd;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

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