Search in sources :

Example 1 with CSSContentAssistProcessor

use of org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor in project webtools.sourceediting by eclipse.

the class HTMLContentAssistProcessor method getCSSProposals.

protected ICompletionProposal[] getCSSProposals(ITextViewer viewer, int pos, IDOMNode element, int offset, char quote) {
    CSSContentAssistProcessor cssProcessor = new CSSContentAssistProcessor();
    cssProcessor.setDocumentOffset(offset);
    cssProcessor.setQuoteCharOfStyleAttribute(quote);
    return cssProcessor.computeCompletionProposals(viewer, pos);
}
Also used : CSSContentAssistProcessor(org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor)

Example 2 with CSSContentAssistProcessor

use of org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor in project webtools.sourceediting by eclipse.

the class NoRegionContentAssistProcessorForHTML method initPartitionToProcessorMap.

protected void initPartitionToProcessorMap() {
    super.initPartitionToProcessorMap();
    IContentAssistProcessor htmlProcessor = new HTMLContentAssistProcessor();
    addPartitionProcessor(IHTMLPartitions.HTML_DEFAULT, htmlProcessor);
    addPartitionProcessor(IHTMLPartitions.HTML_COMMENT, htmlProcessor);
    IContentAssistProcessor jsContentAssistProcessor = new StructuredTextViewerConfigurationHTML().getContentAssistant(null).getContentAssistProcessor(IHTMLPartitions.SCRIPT);
    addPartitionProcessor(IHTMLPartitions.SCRIPT, jsContentAssistProcessor);
    IContentAssistProcessor cssContentAssistProcessor = new CSSContentAssistProcessor();
    addPartitionProcessor(ICSSPartitions.STYLE, cssContentAssistProcessor);
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) CSSContentAssistProcessor(org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor)

Example 3 with CSSContentAssistProcessor

use of org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor in project webtools.sourceediting by eclipse.

the class JSPContentAssistProcessor method computeCompletionProposals.

/**
 * This method is acting as a "catch all" for pulling together content
 * assist proposals from different Processors when document partitioning
 * alone couldn't determine definitively what content assist should show
 * up at that particular position in the document
 *
 * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer,
 *      int)
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) {
    fTemplateContexts.clear();
    IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion(viewer, documentPosition);
    fViewer = viewer;
    ICompletionProposal[] jspResults = EMPTY_PROPOSAL_SET;
    ICompletionProposal[] embeddedResults = EMPTY_PROPOSAL_SET;
    // check the actual partition type
    String partitionType = getPartitionType(viewer, documentPosition);
    IStructuredDocument structuredDocument = (IStructuredDocument) viewer.getDocument();
    IStructuredDocumentRegion fn = structuredDocument.getRegionAtCharacterOffset(documentPosition);
    // check for xml-jsp tags...
    if (partitionType == IJSPPartitions.JSP_DIRECTIVE && fn != null) {
        IStructuredDocumentRegion possibleXMLJSP = ((fn.getType() == DOMRegionContext.XML_CONTENT) && fn.getPrevious() != null) ? fn.getPrevious() : fn;
        ITextRegionList regions = possibleXMLJSP.getRegions();
        if (regions.size() > 1) {
            // check bounds cases
            ITextRegion xmlOpenOrClose = regions.get(0);
            if (xmlOpenOrClose.getType() == DOMRegionContext.XML_TAG_OPEN && documentPosition == possibleXMLJSP.getStartOffset()) {
            // do regular jsp content assist
            } else if (xmlOpenOrClose.getType() == DOMRegionContext.XML_END_TAG_OPEN && documentPosition > possibleXMLJSP.getStartOffset()) {
            // do regular jsp content assist
            } else {
                // possible xml-jsp
                ITextRegion nameRegion = regions.get(1);
                String name = possibleXMLJSP.getText(nameRegion);
                if (name.equals("jsp:scriptlet") || name.equals("jsp:expression") || name.equals("jsp:declaration")) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    return getJSPJavaCompletionProposals(viewer, documentPosition);
                }
            }
        }
    }
    // check for XML-JSP in a <script> region
    if (partitionType == IJSPPartitions.JSP_CONTENT_JAVASCRIPT || partitionType == IHTMLPartitions.SCRIPT) {
        // fn should be block text
        IStructuredDocumentRegion decodedSDRegion = decodeScriptBlock(fn.getFullText());
        // decodedSDRegion.getEndOffset()));
        if (decodedSDRegion != null) {
            IStructuredDocumentRegion sdr = decodedSDRegion;
            while (sdr != null) {
                // sdr.getEndOffset()));
                if (sdr.getType() == DOMJSPRegionContexts.JSP_CONTENT) {
                    if (documentPosition >= fn.getStartOffset() + sdr.getStartOffset() && documentPosition <= fn.getStartOffset() + sdr.getEndOffset()) {
                        return getJSPJavaCompletionProposals(viewer, documentPosition);
                    }
                } else if (sdr.getType() == DOMRegionContext.XML_TAG_NAME) {
                    if (documentPosition > fn.getStartOffset() + sdr.getStartOffset() && documentPosition < fn.getStartOffset() + sdr.getEndOffset()) {
                        return EMPTY_PROPOSAL_SET;
                    } else if (documentPosition == fn.getStartOffset() + sdr.getEndOffset() && sdr.getNext() != null && sdr.getNext().getType() == DOMJSPRegionContexts.JSP_CONTENT) {
                        // <jsp:scriptlet>| blah </jsp:scriptlet>
                        return getJSPJavaCompletionProposals(viewer, documentPosition);
                    } else if (documentPosition == fn.getStartOffset() + sdr.getStartOffset() && sdr.getPrevious() != null && sdr.getPrevious().getType() == DOMRegionContext.XML_TAG_NAME) {
                        return getJSPJavaCompletionProposals(viewer, documentPosition);
                    }
                }
                sdr = sdr.getNext();
            }
        }
    }
    // check special JSP delimiter cases
    if (fn != null && partitionType == IJSPPartitions.JSP_CONTENT_DELIMITER) {
        IStructuredDocumentRegion fnDelim = fn;
        // if it's a nested JSP region, need to get the correct
        // StructuredDocumentRegion
        // not sure why this check was there...
        // if (fnDelim.getType() == XMLRegionContext.BLOCK_TEXT) {
        Iterator blockRegions = fnDelim.getRegions().iterator();
        ITextRegion temp = null;
        ITextRegionContainer trc;
        while (blockRegions.hasNext()) {
            temp = (ITextRegion) blockRegions.next();
            // we hit a nested
            if (temp instanceof ITextRegionContainer) {
                trc = (ITextRegionContainer) temp;
                // it's in this region
                if (documentPosition >= trc.getStartOffset() && documentPosition < trc.getEndOffset()) {
                    Iterator nestedJSPRegions = trc.getRegions().iterator();
                    while (nestedJSPRegions.hasNext()) {
                        temp = (ITextRegion) nestedJSPRegions.next();
                        if (XMLContentAssistUtilities.isJSPOpenDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) {
                            // adapter
                            if (documentPosition > 0) {
                                partitionType = getPartitionType(viewer, documentPosition - 1);
                                break;
                            }
                        } else if (XMLContentAssistUtilities.isJSPCloseDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) {
                            // JSP content assist
                            return getJSPJavaCompletionProposals(viewer, documentPosition);
                        }
                    }
                }
            }
        // }
        }
        // take care of XML-JSP delimter cases
        if (XMLContentAssistUtilities.isXMLJSPDelimiter(fnDelim)) {
            // since it's a delimiter, we know it's a ITextRegionContainer
            ITextRegion firstRegion = fnDelim.getRegions().get(0);
            if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == DOMRegionContext.XML_TAG_OPEN)) {
            // |<jsp:scriptlet> </jsp:scriptlet>
            // (pa) commented out so that we get regular behavior JSP
            // macros etc...
            // return getHTMLCompletionProposals(viewer,
            // documentPosition);
            } else if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == DOMRegionContext.XML_END_TAG_OPEN)) {
                // adapter get the proposals
                if (documentPosition > 0) {
                    String checkType = getPartitionType(viewer, documentPosition - 1);
                    if (checkType != IJSPPartitions.JSP_CONTENT_JAVASCRIPT) {
                        // javascript...)
                        return getJSPJavaCompletionProposals(viewer, documentPosition);
                    }
                    partitionType = IJSPPartitions.JSP_CONTENT_JAVASCRIPT;
                }
            } else if ((firstRegion.getType() == DOMRegionContext.XML_TAG_OPEN) && documentPosition >= fnDelim.getEndOffset()) {
                // anything else inbetween
                return getJSPJavaCompletionProposals(viewer, documentPosition);
            }
        } else if (XMLContentAssistUtilities.isJSPDelimiter(fnDelim)) {
            // the delimiter <%, <%=, <%!, ...
            if (XMLContentAssistUtilities.isJSPCloseDelimiter(fnDelim)) {
                if (documentPosition == fnDelim.getStartOffset()) {
                    // JAVASCRIPT adapter get the proposals
                    if (documentPosition > 0) {
                        String checkType = getPartitionType(viewer, documentPosition - 1);
                        if (checkType != IJSPPartitions.JSP_CONTENT_JAVASCRIPT) {
                            return getJSPJavaCompletionProposals(viewer, documentPosition);
                        }
                        partitionType = IJSPPartitions.JSP_CONTENT_JAVASCRIPT;
                    }
                }
            } else if (XMLContentAssistUtilities.isJSPOpenDelimiter(fnDelim)) {
                // use embedded HTML results
                if (documentPosition == fnDelim.getStartOffset()) {
                    embeddedResults = getHTMLCompletionProposals(viewer, documentPosition);
                } else if (documentPosition == fnDelim.getEndOffset()) {
                    // it's at the EOF <%|
                    return getJSPJavaCompletionProposals(viewer, documentPosition);
                }
            }
        }
    }
    // <!-- <% |%> -->
    if (fn != null && (fn.getType() == DOMRegionContext.XML_CDATA_TEXT || fn.getType() == DOMRegionContext.XML_COMMENT_TEXT)) {
        if (fn instanceof ITextRegionContainer) {
            Object[] cdataRegions = fn.getRegions().toArray();
            ITextRegion r = null;
            ITextRegion jspRegion = null;
            for (int i = 0; i < cdataRegions.length; i++) {
                r = (ITextRegion) cdataRegions[i];
                if (r instanceof ITextRegionContainer) {
                    // CDATA embedded container, or comment container
                    Object[] jspRegions = ((ITextRegionContainer) r).getRegions().toArray();
                    for (int j = 0; j < jspRegions.length; j++) {
                        jspRegion = (ITextRegion) jspRegions[j];
                        if (jspRegion.getType() == DOMJSPRegionContexts.JSP_CLOSE) {
                            if (sdRegion.getStartOffset(jspRegion) == documentPosition)
                                return getJSPJavaCompletionProposals(viewer, documentPosition);
                        }
                    }
                }
            }
        }
    }
    // check if it's in an attribute value, if so, don't add CDATA
    // proposal
    ITextRegion attrContainer = (fn != null) ? fn.getRegionAtCharacterOffset(documentPosition) : null;
    if (attrContainer != null && attrContainer instanceof ITextRegionContainer) {
        if (attrContainer.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
            // test location of the cursor
            // return null if it's in the middle of an open/close
            // delimeter
            Iterator attrRegions = ((ITextRegionContainer) attrContainer).getRegions().iterator();
            ITextRegion testRegion = null;
            while (attrRegions.hasNext()) {
                testRegion = (ITextRegion) attrRegions.next();
                // need to check for other valid attribute regions
                if (XMLContentAssistUtilities.isJSPOpenDelimiter(testRegion.getType())) {
                    if (!(((ITextRegionContainer) attrContainer).getEndOffset(testRegion) <= documentPosition))
                        return EMPTY_PROPOSAL_SET;
                } else if (XMLContentAssistUtilities.isJSPCloseDelimiter(testRegion.getType())) {
                    if (!(((ITextRegionContainer) attrContainer).getStartOffset(testRegion) >= documentPosition))
                        return EMPTY_PROPOSAL_SET;
                }
            }
            // TODO: handle non-Java code such as nested tags
            if (testRegion.getType().equals(DOMJSPRegionContexts.JSP_CONTENT))
                return getJSPJavaCompletionProposals(viewer, documentPosition);
            return EMPTY_PROPOSAL_SET;
        }
    }
    IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType);
    if (p != null) {
        embeddedResults = p.computeCompletionProposals(viewer, documentPosition);
        // get bean methods, objects, and constants if there are any...
        if (partitionType == IJSPPartitions.JSP_CONTENT_JAVASCRIPT || partitionType == IHTMLPartitions.SCRIPT) {
            ICompletionProposal[] beanResults = getJSPJavaBeanProposals(viewer, documentPosition);
            if (beanResults != null && beanResults.length > 0) {
                ICompletionProposal[] added = new ICompletionProposal[beanResults.length + embeddedResults.length];
                System.arraycopy(beanResults, 0, added, 0, beanResults.length);
                System.arraycopy(embeddedResults, 0, added, beanResults.length, embeddedResults.length);
                embeddedResults = added;
            }
        }
    } else {
    // the partition type is probably not mapped
    }
    // HTML content assist give JSP tags in between empty script tags
    if (!((getJSContentAssistProcessor() != null && getJSContentAssistProcessor().getClass().isInstance(p)) || p instanceof CSSContentAssistProcessor)) {
        fTemplateContexts.clear();
        jspResults = super.computeCompletionProposals(viewer, documentPosition);
    }
    // merge the embedded results
    if (useEmbeddedResults && embeddedResults != null && embeddedResults.length > 0) {
        jspResults = merge(jspResults, embeddedResults);
    }
    if (jspResults == null)
        jspResults = EMPTY_PROPOSAL_SET;
    setErrorMessage(jspResults.length == 0 ? UNKNOWN_CONTEXT : null);
    // check for |<%-- --%> first position of jsp comment
    if (partitionType == IJSPPartitions.JSP_COMMENT) {
        if (sdRegion.getStartOffset() == documentPosition) {
            ICompletionProposal[] htmlResults = getHTMLCompletionProposals(viewer, documentPosition);
            jspResults = merge(jspResults, htmlResults);
        }
    }
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86656
    if (partitionType == IJSPPartitions.JSP_DIRECTIVE) {
        ICompletionProposal[] importProposals = getImportProposals(viewer, documentPosition);
        if (importProposals.length > 0)
            jspResults = merge(jspResults, importProposals);
    }
    return jspResults;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) CSSContentAssistProcessor(org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 4 with CSSContentAssistProcessor

use of org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor in project webtools.sourceediting by eclipse.

the class TestCSSContentAssist method testContentAssistInsideMedia.

public void testContentAssistInsideMedia() throws Exception {
    try {
        CSSContentAssistProcessor processor = new CSSContentAssistProcessor();
        ICompletionProposal[] proposals = processor.computeCompletionProposals(sourceViewer, 24);
        assertTrue("No proposals at offset.", proposals.length > 0);
        ICompletionProposal proposal = proposals[0];
        assertEquals("Wrong proposal returned for ACRONYM.", "azimuth", proposal.getDisplayString());
    } finally {
        model.releaseFromEdit();
    }
}
Also used : CSSContentAssistProcessor(org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Aggregations

CSSContentAssistProcessor (org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)2 Iterator (java.util.Iterator)1 StructuredTextViewerConfigurationHTML (org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1