Search in sources :

Example 11 with ITextRegionCollection

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

the class JSPDirectiveValidator method performValidation.

protected void performValidation(IFile f, IReporter reporter, IStructuredDocument sDoc) {
    loadPreferences(f);
    setProject(f.getProject());
    /*
		 * when validating an entire file need to clear dupes or else you're
		 * comparing between files
		 */
    fPrefixValueRegionToDocumentRegionMap.clear();
    fTaglibPrefixesInUse.clear();
    fAttributeNamesInUse.clear();
    IRegionComparible comparer = null;
    if (sDoc instanceof IRegionComparible)
        comparer = (IRegionComparible) sDoc;
    // iterate all document regions
    IStructuredDocumentRegion region = sDoc.getFirstStructuredDocumentRegion();
    while (region != null && !reporter.isCancelled()) {
        // only checking directives
        if (region.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
            processDirective(reporter, f, sDoc, region);
        } else // To check directives inside script tag.
        if (region.getType() == DOMRegionContext.BLOCK_TEXT) {
            Iterator it = region.getRegions().iterator();
            while (it.hasNext()) {
                Object blockRegion = it.next();
                if (blockRegion instanceof ITextRegionCollection) {
                    processDirective(reporter, f, sDoc, (ITextRegionCollection) blockRegion);
                }
            }
        } else // requires tag name, attribute, equals, and value
        if (comparer != null && region.getNumberOfRegions() > 4) {
            ITextRegion nameRegion = region.getRegions().get(1);
            if (comparer.regionMatches(region.getStartOffset(nameRegion), nameRegion.getTextLength(), "jsp:include")) {
                // $NON-NLS-1$
                processInclude(reporter, f, sDoc, region, JSP11Namespace.ATTR_NAME_PAGE);
            } else // https://bugs.eclipse.org/bugs/show_bug.cgi?id=295950
            if (comparer.regionMatches(region.getStartOffset(nameRegion), 14, "jsp:directive.")) {
                // $NON-NLS-1$
                processDirective(reporter, f, sDoc, region);
            }
        }
        region = region.getNext();
    }
    if (!reporter.isCancelled()) {
        reportTaglibDuplicatePrefixes(f, reporter, sDoc);
    }
    fPrefixValueRegionToDocumentRegionMap.clear();
    fTaglibPrefixesInUse.clear();
    fAttributeNamesInUse.clear();
    setProject(null);
    unloadPreferences();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IRegionComparible(org.eclipse.wst.sse.core.internal.text.IRegionComparible) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 12 with ITextRegionCollection

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

the class ScannerUnitTests method testDirectiveInTagBody.

public void testDirectiveInTagBody() {
    String text = "<BODY <%@ include file=\"commonEventHandlers.jspf\" %> dir=\"ltr\"> ";
    IStructuredDocumentRegionList documentRegionList = setUpJSP(text);
    verifyLengths(0, documentRegionList, text);
    checkSimpleRegionTypes(documentRegionList.item(0).getRegions(), new String[] { DOMRegionContext.XML_TAG_OPEN, DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, DOMRegionContext.XML_TAG_CLOSE });
    ITextRegionCollection coll = (ITextRegionCollection) documentRegionList.item(0).getRegions().get(2);
    checkSimpleRegionTypes(coll.getRegions(), new String[] { DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN, DOMRegionContext.WHITE_SPACE, DOMJSPRegionContexts.JSP_DIRECTIVE_NAME, DOMRegionContext.WHITE_SPACE, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, DOMRegionContext.WHITE_SPACE, DOMJSPRegionContexts.JSP_DIRECTIVE_CLOSE });
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 13 with ITextRegionCollection

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

the class AbstractLineStyleProvider method prepareTextRegions.

private boolean prepareTextRegions(IStructuredDocumentRegion structuredDocumentRegion, int partitionStartOffset, int partitionLength, Collection holdResults) {
    boolean handled = false;
    final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
    while (structuredDocumentRegion != null && structuredDocumentRegion.getStartOffset() <= partitionEndOffset) {
        ITextRegion region = null;
        ITextRegionList regions = structuredDocumentRegion.getRegions();
        int nRegions = regions.size();
        StyleRange styleRange = null;
        for (int i = 0; i < nRegions; i++) {
            region = regions.get(i);
            TextAttribute attr = null;
            TextAttribute previousAttr = null;
            if (structuredDocumentRegion.getStartOffset(region) > partitionEndOffset)
                break;
            if (structuredDocumentRegion.getEndOffset(region) <= partitionStartOffset)
                continue;
            if (region instanceof ITextRegionCollection) {
                boolean handledCollection = (prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults));
                handled = (!handled) ? handledCollection : handled;
            } else {
                attr = getAttributeFor(structuredDocumentRegion, region);
                if (attr != null) {
                    handled = true;
                    // regions correctly
                    if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) {
                        styleRange.length += region.getLength();
                    } else {
                        styleRange = createStyleRange(structuredDocumentRegion, region, attr, partitionStartOffset, partitionLength);
                        holdResults.add(styleRange);
                        // technically speaking, we don't need to update
                        // previousAttr
                        // in the other case, because the other case is
                        // when it hasn't changed
                        previousAttr = attr;
                    }
                } else {
                    previousAttr = null;
                }
            }
            if (Debug.syntaxHighlighting && !handled) {
                // $NON-NLS-1$
                System.out.println("not handled in prepareRegions");
            }
        }
        structuredDocumentRegion = structuredDocumentRegion.getNext();
    }
    return handled;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 14 with ITextRegionCollection

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

the class Debug method dump.

public static final void dump(IStructuredDocument structuredDocument, boolean verbose) {
    ITextRegionCollection flatNode = null;
    // $NON-NLS-1$
    System.out.println("Dump of structuredDocument:");
    IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
    Enumeration<?> structuredDocumentRegions = flatNodes.elements();
    while (structuredDocumentRegions.hasMoreElements()) {
        flatNode = (ITextRegionCollection) structuredDocumentRegions.nextElement();
        if (!verbose) {
            String outString = flatNode.toString();
            outString = org.eclipse.wst.sse.core.utils.StringUtils.escape(outString);
            System.out.println(outString);
        } else {
            dump(flatNode, verbose);
        }
    }
    System.out.println();
    // $NON-NLS-1$
    System.out.println("= = = = = =");
    System.out.println();
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 15 with ITextRegionCollection

use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection 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)

Aggregations

ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)20 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)16 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)8 Iterator (java.util.Iterator)7 TextAttribute (org.eclipse.jface.text.TextAttribute)4 StyleRange (org.eclipse.swt.custom.StyleRange)4 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)3 IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)3 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 IRegion (org.eclipse.jface.text.IRegion)1 Position (org.eclipse.jface.text.Position)1 Region (org.eclipse.jface.text.Region)1 ZeroStructuredDocumentRegion (org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion)1