Search in sources :

Example 21 with ITextRegionContainer

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer 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 22 with ITextRegionContainer

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

the class UnitTests method testDeepEmbeddedJSP3.

public void testDeepEmbeddedJSP3() {
    // CMVC 245586
    // this is a test to make sure ContextRegionContainer returns what we expect
    setUpJSP();
    String startString = "<html><head><script> <%! String testvar = \"testvar\"; %> var test = <%= testvar %> </script></head></html>";
    String expectedText = "<%! String testvar = \"testvar\"; %>";
    // $NON-NLS-1$
    ((XMLSourceParser) fModel.getParser()).addBlockMarker(new BlockMarker("script", null, DOMRegionContext.BLOCK_TEXT, false));
    fModel.setText(null, startString);
    fModel.getRegionList();
    IStructuredDocumentRegion scriptBlockRegion = fModel.getRegionAtCharacterOffset(21);
    ITextRegionList blockRegions = scriptBlockRegion.getRegions();
    ITextRegionContainer jspDecl = (ITextRegionContainer) blockRegions.get(1);
    String fullText = jspDecl.getFullText();
    // assertTrue("ContextRegionContainer.getFullText()", fullText.equals(expectedText));
    assertEquals("ContextRegionContainer.getFullText() value incorrect: ", expectedText, fullText);
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) BlockMarker(org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) XMLSourceParser(org.eclipse.wst.xml.core.internal.parser.XMLSourceParser)

Example 23 with ITextRegionContainer

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

the class UnitTests method testDeepEmbeddedJSP.

public void testDeepEmbeddedJSP() {
    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 "));
    eRegion = eRegions.get(2);
    testText = cRegion.getText(eRegion);
    assertTrue("text retrieve", testText.equals("%>"));
    testText = cRegion.getFullText(eRegion);
    assertTrue("text retrieve", testText.equals("%>"));
    eRegion = eRegions.get(3);
    testText = cRegion.getText(eRegion);
    assertTrue("text retrieve", testText.equals(""));
    testText = cRegion.getFullText(eRegion);
    assertTrue("text retrieve", testText.equals("  "));
    // ====
    region = regionList.get(3);
    testText = testR.getText(region);
    assertTrue("text retrieve", testText.equals(">"));
    testText = testR.getFullText(region);
    assertTrue("text retrieve", testText.equals(">"));
}
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 24 with ITextRegionContainer

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

the class MarkupValidator method checkForAttributeValue.

private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
    if (structuredDocumentRegion.isDeleted()) {
        return;
    }
    // check for attributes without a value
    // track the attribute/equals/value sequence using a state of 0, 1 ,2
    // representing the name, =, and value, respectively
    int attrState = 0;
    ITextRegionList textRegions = structuredDocumentRegion.getRegions();
    // ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
    // getScope());
    int errorCount = 0;
    for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) {
        ITextRegion textRegion = textRegions.get(i);
        if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
            // dangling name and '='
            if ((attrState == 2) && (i >= 2)) {
                // create annotation
                ITextRegion nameRegion = textRegions.get(i - 2);
                if (!(nameRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(nameRegion) };
                    String messageText = NLS.bind(XMLUIMessages.Attribute__is_missing_a_value, args);
                    int start = structuredDocumentRegion.getStartOffset(nameRegion);
                    int end = structuredDocumentRegion.getEndOffset();
                    int lineNo = getLineNumber(start);
                    int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
                    LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    // quick fix info
                    ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
                    int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
                    Object[] additionalFixInfo = { structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset) };
                    if (reporter instanceof IncrementalReporter) {
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.MissingAttrValue);
                        processor.setAdditionalFixInfo(additionalFixInfo);
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                    errorCount++;
                }
            } else // name but no '=' (XML only)
            if ((attrState == 1) && (i >= 1)) {
                // create annotation
                ITextRegion previousRegion = textRegions.get(i - 1);
                if (!(previousRegion instanceof ITextRegionContainer)) {
                    Object[] args = { structuredDocumentRegion.getText(previousRegion) };
                    String messageText = NLS.bind(XMLUIMessages.Attribute__has_no_value, args);
                    int start = structuredDocumentRegion.getStartOffset(previousRegion);
                    int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
                    int lineNo = getLineNumber(start);
                    LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
                    message.setOffset(start);
                    message.setLength(textLength);
                    message.setLineNo(lineNo);
                    if (reporter instanceof IncrementalReporter) {
                        MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
                        processor.setProblemId(ProblemIDsXML.NoAttrValue);
                        processor.setAdditionalFixInfo(structuredDocumentRegion.getText(previousRegion));
                        message.setAttribute(QUICKASSISTPROCESSOR, processor);
                        AnnotationInfo info = new AnnotationInfo(message);
                        ((IncrementalReporter) reporter).addAnnotationInfo(this, info);
                    } else {
                        reporter.addMessage(this, message);
                    }
                    errorCount++;
                }
            }
            attrState = 1;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
            attrState = 2;
        } else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
            attrState = 0;
        }
    }
}
Also used : IncrementalReporter(org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter) 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) LocalizedMessage(org.eclipse.wst.validation.internal.operations.LocalizedMessage) AnnotationInfo(org.eclipse.wst.sse.ui.internal.reconcile.validator.AnnotationInfo)

Example 25 with ITextRegionContainer

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

the class SourceValidator method hasNestedRegion.

/**
 * True if the text has nested regions, meaning container is probably too
 * complicated (like EL regions) to validate with this validator.
 *
 * @param text
 * @return
 */
private boolean hasNestedRegion(TextImpl text) {
    boolean done = false;
    IStructuredDocumentRegion currRegion = text.getFirstStructuredDocumentRegion();
    IStructuredDocumentRegion lastRegion = text.getLastStructuredDocumentRegion();
    while (currRegion != null && !done) {
        ITextRegionList regions = currRegion.getRegions();
        for (int i = 0; i < regions.size(); ++i) {
            ITextRegion container = regions.get(i);
            if ((container instanceof ITextRegionContainer)) {
                ITextRegionList regions2 = ((ITextRegionContainer) container).getRegions();
                if (regions2 != null) {
                    return true;
                }
            }
        }
        done = currRegion == lastRegion;
        currRegion = currRegion.getNext();
    }
    return false;
}
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)

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