Search in sources :

Example 1 with ContentAssistRequest

use of org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest in project liferay-ide by liferay.

the class ServiceXmlContentAssistProcessor method computeContentProposals.

@Override
protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
    ContentAssistRequest request = super.computeContentProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node);
    _entityProposalIfNeeded(request);
    return request;
}
Also used : ContentAssistRequest(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest)

Example 2 with ContentAssistRequest

use of org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest in project webtools.sourceediting by eclipse.

the class HTMLContentAssistProcessor method computeCompletionProposals.

protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
    ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
    // bug115927 use original document position for all/any region templates
    addTemplates(request, TemplateContextTypeIdsHTML.ALL, documentPosition);
    return request;
}
Also used : ContentAssistRequest(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest)

Example 3 with ContentAssistRequest

use of org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest in project webtools.sourceediting by eclipse.

the class JSPCompletionProposalComputer method computeCompletionProposals.

/**
 * @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#computeCompletionProposals(java.lang.String, org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion, org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode, org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
 */
protected ContentAssistRequest computeCompletionProposals(String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode, CompletionProposalInvocationContext context) {
    // be sure to get the super proposals
    ContentAssistRequest request = super.computeCompletionProposals(matchString, completionRegion, treeNode, xmlnode, context);
    // calculate JSP specific proposals
    int documentPosition = context.getInvocationOffset();
    IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(context.getViewer(), documentPosition);
    Document doc = null;
    if (xmlnode != null) {
        if (xmlnode.getNodeType() == Node.DOCUMENT_NODE) {
            doc = (Document) xmlnode;
        } else {
            doc = xmlnode.getOwnerDocument();
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] directiveNames = { "page", "include", "taglib" };
    ITextRegion prevTextRegion = null;
    try {
        int offset = sdRegion.getStartOffset(completionRegion);
        if (offset > 0) {
            offset--;
        }
        ITypedRegion prevRegion = context.getDocument().getPartition(offset);
        prevTextRegion = sdRegion.getRegionAtCharacterOffset(prevRegion.getOffset());
    } catch (BadLocationException e) {
        // this should never happen
        Logger.logException(e);
    }
    // suggest JSP Expression inside of XML comments
    if (completionRegion.getType() == DOMRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) {
        if (request == null) {
            request = new ContentAssistRequest(treeNode, xmlnode, sdRegion, completionRegion, documentPosition, 0, // $NON-NLS-1$
            "");
        }
        request.addProposal(new // $NON-NLS-1$
        CustomCompletionProposal(// $NON-NLS-1$
        "<%=  %>", documentPosition, 0, 4, JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP), "jsp:expression", null, "&lt;%= %&gt;", // $NON-NLS-1$ //$NON-NLS-2$
        XMLRelevanceConstants.R_JSP));
    } else /* handle proposals in and around JSP_DIRECTIVE_OPEN,
		 * JSP_DIRECTIVE_CLOSE (preceded by OPEN) and JSP_DIRECTIVE_NAME
		 */
    if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition >= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition <= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && prevTextRegion != null && prevTextRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition <= sdRegion.getTextEndOffset(completionRegion))) {
        if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN || completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE) {
            if (request == null) {
                request = new ContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, documentPosition, 0, matchString);
            }
            // determine if there is any part of a directive name already existing
            Iterator regions = sdRegion.getRegions().iterator();
            String nameString = null;
            int begin = request.getReplacementBeginPosition();
            int length = request.getReplacementLength();
            while (regions.hasNext()) {
                ITextRegion region = (ITextRegion) regions.next();
                if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
                    nameString = sdRegion.getText(region);
                    begin = sdRegion.getStartOffset(region);
                    length = region.getTextLength();
                    break;
                }
            }
            if (nameString == null) {
                // $NON-NLS-1$
                nameString = "";
            }
            /* Suggest the directive names that have been determined to be
				 * appropriate based on existing content
				 */
            for (int i = 0; i < directiveNames.length; i++) {
                if (directiveNames[i].startsWith(nameString) || documentPosition <= begin) {
                    request.addProposal(new CustomCompletionProposal(directiveNames[i], begin, length, directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
                }
            }
        } else // by default, JSP_DIRECTIVE_NAME
        {
            if (request == null) {
                request = new ContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
            }
            // add each of the directive names as a proposal
            for (int i = 0; i < directiveNames.length; i++) {
                if (directiveNames[i].startsWith(matchString)) {
                    request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
                }
            }
        }
    } else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition > sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion))) {
        if (request == null) {
            request = computeAttributeProposals(matchString, completionRegion, treeNode, xmlnode, context);
        }
    } else // no name?: <%@ %>
    if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion)) {
        if (request != null) {
            request = computeAttributeProposals(matchString, completionRegion, treeNode, xmlnode, context);
        }
        Iterator regions = sdRegion.getRegions().iterator();
        String nameString = null;
        while (regions.hasNext()) {
            ITextRegion region = (ITextRegion) regions.next();
            if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
                nameString = sdRegion.getText(region);
                break;
            }
        }
        if (nameString == null) {
            for (int i = 0; i < directiveNames.length; i++) {
                request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
            }
        }
    }
    return request;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ITypedRegion(org.eclipse.jface.text.ITypedRegion) Document(org.w3c.dom.Document) BadLocationException(org.eclipse.jface.text.BadLocationException) ContentAssistRequest(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest)

Example 4 with ContentAssistRequest

use of org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest in project webtools.sourceediting by eclipse.

the class JSPContentAssistProcessor method computeCompletionProposals.

/**
 * @see AbstractContentAssistProcessor#computeCompletionProposals(int,
 *      String, ITextRegion, IDOMNode, IDOMNode)
 */
protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
    ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
    IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(fTextViewer, documentPosition);
    Document doc = null;
    if (xmlnode != null) {
        if (xmlnode.getNodeType() == Node.DOCUMENT_NODE)
            doc = (Document) xmlnode;
        else
            doc = xmlnode.getOwnerDocument();
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] directiveNames = { "page", "include", "taglib" };
    // suggest JSP Expression inside of XML comments
    if (completionRegion.getType() == DOMRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) {
        if (request == null)
            // $NON-NLS-1$
            request = newContentAssistRequest(treeNode, xmlnode, sdRegion, completionRegion, documentPosition, 0, "");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        request.addProposal(new CustomCompletionProposal("<%=  %>", documentPosition, 0, 4, JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), "jsp:expression", null, "&lt;%= %&gt;", XMLRelevanceConstants.R_JSP));
    } else // JSP_DIRECTIVE_NAME
    if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition >= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition <= sdRegion.getTextEndOffset(completionRegion))) {
        if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) {
            if (request == null)
                request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, documentPosition, 0, matchString);
            Iterator regions = sdRegion.getRegions().iterator();
            String nameString = null;
            int begin = request.getReplacementBeginPosition();
            int length = request.getReplacementLength();
            while (regions.hasNext()) {
                ITextRegion region = (ITextRegion) regions.next();
                if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
                    nameString = sdRegion.getText(region);
                    begin = sdRegion.getStartOffset(region);
                    length = region.getTextLength();
                    break;
                }
            }
            if (nameString == null)
                // $NON-NLS-1$
                nameString = "";
            for (int i = 0; i < directiveNames.length; i++) {
                if (directiveNames[i].startsWith(nameString) || documentPosition <= begin)
                    request.addProposal(new CustomCompletionProposal(directiveNames[i], begin, length, directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
            }
        } else {
            // by default, JSP_DIRECTIVE_NAME
            if (request == null)
                request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString);
            for (int i = 0; i < directiveNames.length; i++) {
                if (directiveNames[i].startsWith(matchString))
                    request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
            }
        }
    } else if ((completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition > sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion))) {
        if (request == null)
            request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
        super.addTagCloseProposals(request);
    // CMVC 274033, this is being added for all <jsp:* tags
    // in addAttributeNameProposals(contentAssistRequest)
    // super.addAttributeNameProposals(request);
    } else // no name?: <%@ %>
    if (completionRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion)) {
        if (request != null)
            request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode);
        Iterator regions = sdRegion.getRegions().iterator();
        String nameString = null;
        while (regions.hasNext()) {
            ITextRegion region = (ITextRegion) regions.next();
            if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
                nameString = sdRegion.getText(region);
                break;
            }
        }
        if (nameString == null) {
            for (int i = 0; i < directiveNames.length; i++) {
                request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP));
            }
        }
    }
    // bug115927 use original document position for all/any region
    // templates
    addTemplates(request, TemplateContextTypeIdsJSP.ALL, documentPosition);
    return request;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) Iterator(java.util.Iterator) Document(org.w3c.dom.Document) JSPCMDocument(org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument) IDocument(org.eclipse.jface.text.IDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ContentAssistRequest(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest)

Aggregations

ContentAssistRequest (org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest)4 Iterator (java.util.Iterator)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)2 Document (org.w3c.dom.Document)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 JSPCMDocument (org.eclipse.wst.html.core.internal.contentmodel.JSPCMDocument)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1