Search in sources :

Example 46 with ITextRegionContainer

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

the class UnitTests method testDeepEmbeddedJSP2.

public void testDeepEmbeddedJSP2() {
    setUpJSP();
    eventCase = GENERIC_REGIONS_REPLACED_EVENT_CASE;
    String startString = "<script><a   >c</a></script>";
    String changes = "<%= b %";
    String expectedString = "<script><a <%= b %  >c</a></script>";
    int startOfChanges = 11;
    int lengthToReplace = 0;
    fModel.setText(null, startString);
    fModel.replaceText(null, startOfChanges, lengthToReplace, changes);
    String resultString = fModel.getText();
    boolean result = (expectedString.equals(resultString));
    assertTrue("text update", result);
    assertTrue("event type", eventResult);
    IStructuredDocumentRegion testR = fModel.getRegionAtCharacterOffset(11);
    String testText = testR.getText();
    assertTrue("text retrieve", testText.equals("<a <%= b %  >"));
    testText = testR.getFullText();
    assertTrue("text retrieve", testText.equals("<a <%= b %  >"));
    ITextRegionList regionList = testR.getRegions();
    ITextRegion region = regionList.get(0);
    testText = testR.getText(region);
    assertTrue("text retrieve", testText.equals("<"));
    region = regionList.get(1);
    testText = testR.getText(region);
    assertTrue("text retrieve", testText.equals("a"));
    testText = testR.getFullText(region);
    assertTrue("text retrieve", testText.equals("a "));
    region = regionList.get(2);
    testText = testR.getText(region);
    assertTrue("text retrieve", testText.equals("<%= b %  >"));
    testText = testR.getFullText(region);
    assertTrue("text retrieve", testText.equals("<%= b %  >"));
    // ===
    ITextRegionContainer cRegion = (ITextRegionContainer) region;
    ITextRegionList eRegions = cRegion.getRegions();
    ITextRegion eRegion = eRegions.get(0);
    testText = cRegion.getText(eRegion);
    assertTrue("text retrieve", testText.equals("<%="));
    testText = cRegion.getFullText(eRegion);
    assertTrue("text retrieve", testText.equals("<%="));
    eRegion = eRegions.get(1);
    testText = cRegion.getText(eRegion);
    assertTrue("text retrieve", testText.equals(" b %  >"));
    testText = cRegion.getFullText(eRegion);
    assertTrue("text retrieve", testText.equals(" b %  >"));
// ====
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) 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 47 with ITextRegionContainer

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

the class StructuredDocumentReParser method checkAndAssignParent.

private void checkAndAssignParent(IStructuredDocumentRegion oldNode, ITextRegion region) {
    if (region instanceof ITextRegionContainer) {
        ((ITextRegionContainer) region).setParent(oldNode);
        return;
    }
    if (region instanceof ITextRegionCollection) {
        ITextRegionCollection textRegionCollection = (ITextRegionCollection) region;
        ITextRegionList regionList = textRegionCollection.getRegions();
        for (int i = 0; i < regionList.size(); i++) {
            ITextRegion innerRegion = regionList.get(i);
            checkAndAssignParent(oldNode, innerRegion);
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 48 with ITextRegionContainer

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

the class StructuredTextPartitioner method getReleventRegionType.

/**
 * Return the ITextRegion at the given offset. For most cases, this will
 * be the flatNode itself. Should it contain an embedded
 * ITextRegionContainer, will return the internal region at the offset
 *
 * @param flatNode
 * @param offset
 * @return ITextRegion
 */
private String getReleventRegionType(IStructuredDocumentRegion flatNode, int offset) {
    // * Note: the original form of this method -- which returned "deep"
    // region, isn't that
    // * useful, after doing parent elimination refactoring,
    // * since once the deep region is returned, its hard to get its text
    // or offset without
    // * proper parent.
    ITextRegion resultRegion = null;
    if (containsEmbeddedRegion(flatNode)) {
        resultRegion = flatNode.getRegionAtCharacterOffset(offset);
        if (resultRegion instanceof ITextRegionContainer) {
            resultRegion = flatNode.getRegionAtCharacterOffset(offset);
            ITextRegionList regions = ((ITextRegionContainer) resultRegion).getRegions();
            for (int i = 0; i < regions.size(); i++) {
                ITextRegion region = regions.get(i);
                if (flatNode.getStartOffset(region) <= offset && offset < flatNode.getEndOffset(region)) {
                    resultRegion = region;
                    break;
                }
            }
        }
    } else {
        resultRegion = flatNode;
    }
    return resultRegion.getType();
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 49 with ITextRegionContainer

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

the class StructuredTextPartitioner method containsEmbeddedRegion.

/**
 * Determines if the given ITextRegionContainer itself contains another
 * ITextRegionContainer
 *
 * @param ITextRegionContainer
 * @return boolean
 */
protected boolean containsEmbeddedRegion(IStructuredDocumentRegion container) {
    boolean containsEmbeddedRegion = false;
    ITextRegionList regions = container.getRegions();
    for (int i = 0; i < regions.size(); i++) {
        ITextRegion region = regions.get(i);
        if (region instanceof ITextRegionContainer) {
            containsEmbeddedRegion = true;
            break;
        }
    }
    return containsEmbeddedRegion;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 50 with ITextRegionContainer

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

the class JSPTranslator method getUnescapedRegionText.

/**
 * this piece of code iterates through fCurrentNodes and clumps them
 * together in a big text string - unescaping characters if they are not
 * CDATA - simply appending if they are CDATA it stops iteration when it
 * hits a node that is an XML_TAG_NAME (which should be the region closing
 * tag)
 */
protected String getUnescapedRegionText(ITextRegionCollection stRegion, int JSPType) {
    StringBuffer buffer = new StringBuffer();
    int start = stRegion.getStartOffset();
    int end = stRegion.getEndOffset();
    // adjustment necessary for embedded region containers
    if (stRegion instanceof ITextRegionContainer && stRegion.getType() == DOMRegionContext.BLOCK_TEXT) {
        if (stRegion.getRegions() != null && stRegion.getRegions().size() > 1) {
            // should
            ITextRegion jspContent = stRegion.getRegions().get(1);
            // be
            // jspContent
            // region
            start = stRegion.getStartOffset(jspContent);
            end = stRegion.getEndOffset(jspContent);
        }
    }
    // number of characters lost in conversion
    int CDATAOffset = 0;
    int bufferSize = 0;
    if (// need
    stRegion.getType() == DOMJSPRegionContexts.JSP_CONTENT || stRegion.getType() == DOMRegionContext.BLOCK_TEXT || // regions
    stRegion.getType() == // need
    DOMRegionContext.XML_TAG_NAME) // this
    // in
    // case
    // there's
    // no
    // region...
    {
        fInCodeRegion = (start <= fSourcePosition && fSourcePosition <= end);
        if (fInCodeRegion) {
            setCursorOwner(JSPType);
            setRelativeOffset((fSourcePosition - start) + getCursorOwner().length());
            if (JSPType == EXPRESSION) {
                // if an expression, add then length of the enclosing
                // paren..
                setCursorInExpression(true);
                setRelativeOffset(getRelativeOffset() + EXPRESSION_PREFIX.length());
            }
        }
        ITextRegion jspContent = null;
        if (stRegion.getRegions() != null && stRegion.getRegions().size() > 1)
            jspContent = stRegion.getRegions().get(1);
        // don't
        return (jspContent != null) ? stRegion.getFullText(jspContent) : stRegion.getFullText();
    // unescape
    // if
    // it's
    // not
    // an
    // XMLJSP
    // tag
    } else if (stRegion.getType() == DOMJSPRegionContexts.JSP_CLOSE) {
        // need to determine cursor owner so that the fCurosorPosition
        // will be
        // correct even if there is no region after the cursor in the JSP
        // file
        setCursorOwner(JSPType);
    }
    // tag name)
    while (// need to stop on the ending tag name...
    getCurrentNode() != null && getCurrentNode().getType() != DOMRegionContext.XML_TAG_NAME && getCurrentNode().getType() != DOMJSPRegionContexts.JSP_CLOSE) {
        start = getCurrentNode().getStartOffset();
        end = getCurrentNode().getEndOffset();
        bufferSize = buffer.length();
        CDATAOffset = unescapeRegion(getCurrentNode(), buffer);
        fInCodeRegion = (start <= fSourcePosition && fSourcePosition <= end);
        if (fInCodeRegion) {
            setCursorOwner(JSPType);
            // this offset is sort of complicated...
            // it's composed of:
            // 1. the length of the start of the current region up till
            // where the cursor is
            // 2. minus the number of characters lost in CDATA translation
            // 3. plus the length of the escaped buffer before the current
            // region, but
            // is still within the jsp tag
            setRelativeOffset((fSourcePosition - getCurrentNode().getStartOffset()) + getCursorOwner().length() - CDATAOffset + bufferSize);
            if (JSPType == EXPRESSION) {
                setCursorInExpression(true);
                // if an expression, add then length of the enclosing
                // paren..
                setRelativeOffset(getRelativeOffset() + EXPRESSION_PREFIX.length());
            }
        }
        if (getCurrentNode() != null)
            advanceNextNode();
    }
    return buffer.toString();
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Aggregations

ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)52 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)39 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)26 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)25 IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)11 Iterator (java.util.Iterator)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 List (java.util.List)8 ArrayList (java.util.ArrayList)7 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)3 ITextViewer (org.eclipse.jface.text.ITextViewer)3 Image (org.eclipse.swt.graphics.Image)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)3 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)3 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)3 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3