Search in sources :

Example 6 with ITextRegionCollection

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

the class LineStyleProviderForXSL method prepareTextRegion.

/**
 * @param region
 * @param start
 * @param length
 * @param holdResults
 * @return
 */
protected boolean prepareTextRegion(ITextRegionCollection blockedRegion, int partitionStartOffset, int partitionLength, Collection holdResults) {
    boolean handled = false;
    final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
    ITextRegion region = null;
    ITextRegionList regions = blockedRegion.getRegions();
    StyleRange styleRange = null;
    for (int i = 0; i < regions.size(); i++) {
        region = regions.get(i);
        TextAttribute attr = null;
        TextAttribute previousAttr = null;
        if (blockedRegion.getStartOffset(region) > partitionEndOffset)
            break;
        if (blockedRegion.getEndOffset(region) <= partitionStartOffset)
            continue;
        if (region instanceof ITextRegionCollection) {
            handled = prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults);
        } else {
            attr = getAttributeFor(blockedRegion, region);
            if (attr != null) {
                handled = true;
                styleRange = applyStyleRange(blockedRegion, partitionStartOffset, partitionLength, holdResults, region, styleRange, attr, previousAttr);
            } else {
                previousAttr = null;
            }
        }
    }
    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 7 with ITextRegionCollection

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

the class Debug method printChildRegions.

private static void printChildRegions(ITextRegionCollection region, int depth) {
    if (region != null) {
        // ==> // ITextRegionCollection regionCollection = region;
        System.out.println(region);
        ITextRegionList regionList = region.getRegions();
        for (int i = 0; i < regionList.size(); i++) {
            ITextRegion r = regionList.get(i);
            if (r instanceof ITextRegionCollection) {
                ITextRegionCollection rc = (ITextRegionCollection) r;
                printChildRegions(rc, depth++);
            } else {
                System.out.println(space(depth) + r);
                depth--;
            }
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 8 with ITextRegionCollection

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

the class JsValidator method createMessageFromProblem.

/**
 * Creates an IMessage from an IProblem
 *
 * @param problem
 * @param f
 * @param translation
 * @param textDoc
 * @return message representation of the problem, or null if it could not
 *         create one
 */
private IMessage createMessageFromProblem(IProblem problem, IFile f, IJsTranslation translation, IDocument textDoc) {
    int sourceStart = problem.getSourceStart();
    int sourceEnd = problem.getSourceEnd();
    if (sourceStart == -1) {
        return null;
    }
    sourceStart = translation.getWebPageOffset(sourceStart);
    sourceEnd = translation.getWebPageOffset(sourceEnd);
    /*
		 * Bug 241794 - Validation shows errors when using JSP Expressions
		 * inside JavaScript code
		 */
    IStructuredDocument doc = (IStructuredDocument) textDoc;
    IStructuredDocumentRegion documentRegion = doc.getRegionAtCharacterOffset(sourceStart);
    if (documentRegion != null) {
        ITextRegion textRegion = documentRegion.getRegionAtCharacterOffset(sourceStart);
        /*
			 * Filter out problems from areas that aren't simple JavaScript,
			 * e.g. JSP.
			 */
        if (textRegion != null && textRegion instanceof ITextRegionCollection)
            return null;
    }
    int sev = problem.isError() ? IMessage.HIGH_SEVERITY : (problem.isWarning() ? IMessage.NORMAL_SEVERITY : IMessage.LOW_SEVERITY);
    IMessage m = new LocalizedMessage(sev, problem.getMessage(), f);
    // line numbers from document starts @ 0
    try {
        int lineNo = textDoc.getLineOfOffset(sourceStart) + 1;
        m.setLineNo(lineNo);
        m.setOffset(sourceStart);
        m.setLength(sourceEnd - sourceStart + 1);
    } catch (BadLocationException e) {
        Logger.logException(e);
    }
    return m;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 9 with ITextRegionCollection

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

the class Debug method printChildRegions.

private static void printChildRegions(ITextRegionCollection region, int depth) {
    if (region != null) {
        // ==> // ITextRegionCollection regionCollection = region;
        System.out.println(region);
        ITextRegionList regionList = region.getRegions();
        for (int i = 0; i < regionList.size(); i++) {
            ITextRegion r = regionList.get(i);
            if (r instanceof ITextRegionCollection) {
                ITextRegionCollection rc = (ITextRegionCollection) r;
                printChildRegions(rc, depth++);
            } else {
                System.out.println(space(depth) + r);
                depth--;
            }
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 10 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 : Enumeration(java.util.Enumeration) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) 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