Search in sources :

Example 51 with ITextRegionContainer

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

the class JSPTranslator method unescapeRegion.

/**
 * @param r
 *            the region to be unescaped (XMLContent, XML ENTITY
 *            REFERENCE, or CDATA)
 * @param sb
 *            the stringbuffer to append the text to
 * @return the number of characters removed in unescaping this text
 */
protected int unescapeRegion(ITextRegion r, StringBuffer sb) {
    // $NON-NLS-1$
    String s = "";
    int lengthBefore = 0, lengthAfter = 0, cdata_tags_length = 0;
    if (r != null && (r.getType() == DOMRegionContext.XML_CONTENT || r.getType() == DOMRegionContext.XML_ENTITY_REFERENCE)) {
        lengthBefore = (getCurrentNode() != r) ? getCurrentNode().getFullText(r).length() : getCurrentNode().getFullText().length();
        s = EscapedTextUtil.getUnescapedText(getCurrentNode(), r);
        lengthAfter = s.length();
        sb.append(s);
    } else if (r != null && r.getType() == DOMRegionContext.XML_CDATA_TEXT) {
        if (// only interested in
        r instanceof ITextRegionContainer) // contents
        {
            // navigate to next region container (which should be a JSP
            // region)
            Iterator it = ((ITextRegionContainer) r).getRegions().iterator();
            ITextRegion temp = null;
            while (it.hasNext()) {
                temp = (ITextRegion) it.next();
                if (temp instanceof ITextRegionContainer || temp.getType() == DOMRegionContext.XML_CDATA_TEXT) {
                    sb.append(getCurrentNode().getFullText(temp));
                } else if (temp.getType() == DOMRegionContext.XML_CDATA_OPEN || temp.getType() == DOMRegionContext.XML_CDATA_CLOSE) {
                    cdata_tags_length += temp.getLength();
                }
            }
        }
    }
    return (lengthBefore - lengthAfter + cdata_tags_length);
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 52 with ITextRegionContainer

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

the class JSPJavaCompletionProposalComputer method computeCompletionProposals.

/**
 * <p>Return a list of proposed code completions based on the specified
 * location within the document that corresponds to the current cursor
 * position within the text-editor control.</p>
 *
 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
 */
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
    List results = new ArrayList(0);
    if (isValidContext(context)) {
        ITextViewer viewer = context.getViewer();
        int documentPosition = context.getInvocationOffset();
        IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition);
        // get results from JSP completion processor
        results = computeJavaCompletionProposals(viewer, documentPosition, 0);
        IDOMNode xNode = null;
        IStructuredDocumentRegion flat = null;
        if (treeNode instanceof IDOMNode) {
            xNode = (IDOMNode) treeNode;
            flat = xNode.getFirstStructuredDocumentRegion();
            if (flat != null && flat.getType() == DOMJSPRegionContexts.JSP_CONTENT) {
                flat = flat.getPrevious();
            }
        }
        // this is in case it's a <%@, it will be a region container...
        ITextRegion openRegion = null;
        if (flat != null && flat instanceof ITextRegionContainer) {
            ITextRegionList v = ((ITextRegionContainer) flat).getRegions();
            if (v.size() > 0)
                openRegion = v.get(0);
        }
        // ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG
        if (flat != null && flat.getType() != DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_DECLARATION_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_EXPRESSION_OPEN && flat.getType() != DOMRegionContext.BLOCK_TEXT && (openRegion != null && openRegion.getType() != DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) && !inAttributeRegion(flat, documentPosition)) {
            // determine if cursor is before or after selected range
            int adjustedDocPosition = documentPosition;
            int realCaretPosition = viewer.getTextWidget().getCaretOffset();
            int selectionLength = viewer.getSelectedRange().y;
            if (documentPosition > realCaretPosition) {
                adjustedDocPosition -= selectionLength;
            }
            CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
            results.add(cdataProposal);
        }
    }
    return results;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ArrayList(java.util.ArrayList) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) List(java.util.List) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

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