Search in sources :

Example 16 with ITextRegionList

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

the class SyntaxValidator method isEndTagCorrupted.

private boolean isEndTagCorrupted(ElementInfo info) {
    ITextRegionList regions = info.endTag.getRegions();
    if (regions == null || regions.isEmpty())
        return false;
    Iterator iter = regions.iterator();
    while (iter.hasNext()) {
        ITextRegion rgn = (ITextRegion) iter.next();
        if (!isValidRegion(rgn))
            // found invalid region type.
            return true;
    }
    // all regions are valid.
    return false;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Example 17 with ITextRegionList

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

the class SyntaxValidator method getEndTagFullText.

private String getEndTagFullText(ElementInfo info) {
    // $NON-NLS-1$
    String hint = "";
    ITextRegionList regions = info.endTag.getRegions();
    Iterator iter = regions.iterator();
    while (iter.hasNext()) {
        ITextRegion rgn = (ITextRegion) iter.next();
        String type = rgn.getType();
        if (type == null)
            continue;
        if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_TAG_CLOSE)
            continue;
        hint += info.endTag.getFullText(rgn);
    }
    return hint;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Example 18 with ITextRegionList

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

the class AbstractStructuredFoldingStrategy method getIndexedRegions.

/**
 * <p>Gets all of the {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the given
 * {@link IStructuredDocumentRegion}s.</p>
 *
 * @param model the {@link IStructuredModel} used to get the {@link IndexedRegion}s
 * @param structRegions get the {@link IndexedRegion}s spanned by these {@link IStructuredDocumentRegion}s
 * @return the {@link Set} of {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the
 * given {@link IStructuredDocumentRegion}s.
 */
private Set getIndexedRegions(IStructuredModel model, IStructuredDocumentRegion[] structRegions) {
    Set indexedRegions = new HashSet(structRegions.length);
    // for each text region in each structured document region find the indexed region it spans/is in
    for (int structRegionIndex = 0; structRegionIndex < structRegions.length && fProjectionAnnotationModel != null; ++structRegionIndex) {
        IStructuredDocumentRegion structuredDocumentRegion = structRegions[structRegionIndex];
        int offset = structuredDocumentRegion.getStartOffset();
        IndexedRegion indexedRegion = model.getIndexedRegion(offset);
        indexedRegions.add(indexedRegion);
        if (structuredDocumentRegion.getEndOffset() <= indexedRegion.getEndOffset())
            continue;
        ITextRegionList textRegions = structuredDocumentRegion.getRegions();
        int textRegionCount = textRegions.size();
        for (int textRegionIndex = 1; textRegionIndex < textRegionCount; ++textRegionIndex) {
            offset = structuredDocumentRegion.getStartOffset(textRegions.get(textRegionIndex));
            indexedRegion = model.getIndexedRegion(offset);
            indexedRegions.add(indexedRegion);
        }
    }
    return indexedRegions;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) HashSet(java.util.HashSet) Set(java.util.Set) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) HashSet(java.util.HashSet)

Example 19 with ITextRegionList

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

the class JsTranslator method translateInlineJSNode.

/* (non-Javadoc)
	 * @see org.eclipse.wst.jsdt.web.core.javascript.IJsTranslator#translateInlineJSNode(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)
	 */
public void translateInlineJSNode(IStructuredDocumentRegion container) {
    // System.out
    // .println("JSPTranslator.translateInlineJSNode Entered
    // w/ScriptOffset:"
    // + scriptOffset);
    // NodeHelper nh = new NodeHelper(container);
    // System.out.println("inline js node looking at:\n" + nh);
    /* start a function header.. will amend later */
    ITextRegionList t = container.getRegions();
    ITextRegion r;
    Iterator regionIterator = t.iterator();
    while (regionIterator.hasNext() && !isCanceled()) {
        r = (ITextRegion) regionIterator.next();
        if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
            int start = r.getStart();
            int offset = r.getTextEnd();
            String tagAttrname = container.getText(r);
            /*
					 * Attribute values aren't case sensative, also make sure next
					 * region is attrib value
					 */
            if (NodeHelper.isInArray(JsDataTypes.HTMLATREVENTS, tagAttrname)) {
                if (regionIterator.hasNext()) {
                    regionIterator.next();
                }
                if (regionIterator.hasNext()) {
                    r = ((ITextRegion) regionIterator.next());
                }
                if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                    int valStartOffset = container.getStartOffset(r);
                    // int valEndOffset = r.getTextEnd();
                    String rawText = container.getText(r);
                    if (rawText == null || rawText.length() == 0) {
                        continue;
                    }
                    /* Strip quotes */
                    switch(rawText.charAt(0)) {
                        case '\'':
                        case '"':
                            rawText = rawText.substring(1);
                            valStartOffset++;
                    }
                    if (rawText == null || rawText.length() == 0) {
                        continue;
                    }
                    switch(rawText.charAt(rawText.length() - 1)) {
                        case '\'':
                        case '"':
                            rawText = rawText.substring(0, rawText.length() - 1);
                    }
                    // Position inScript = new Position(scriptOffset,
                    // rawText.length());
                    /* Quoted text starts +1 and ends -1 char */
                    Position inHtml = new Position(valStartOffset, rawText.length());
                    /* need to pad the script text with spaces */
                    char[] spaces = Util.getPad(Math.max(0, valStartOffset - scriptOffset - EVENT_HANDLER_PRE_LENGTH));
                    for (int i = 0; i < spaces.length; i++) {
                        try {
                            char c = fStructuredDocument.getChar(scriptOffset + i);
                            if (c == '\n' || c == '\r' || c == '\t')
                                spaces[i] = c;
                        } catch (BadLocationException e) {
                            Logger.logException(e);
                        }
                    }
                    fScriptText.append(spaces);
                    fScriptText.append(EVENT_HANDLER_PRE);
                    appendAndTrack(rawText, valStartOffset);
                    // $NON-NLS-1$
                    if (ADD_SEMICOLON_AT_INLINE)
                        fScriptText.append(";");
                    if (r.getLength() > rawText.length()) {
                        fScriptText.append(EVENT_HANDLER_POST);
                        spaces = Util.getPad(Math.max(0, r.getLength() - rawText.length() - EVENT_HANDLER_POST_LENGTH));
                        fScriptText.append(spaces);
                    }
                    scriptOffset = container.getEndOffset(r);
                }
            }
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) Position(org.eclipse.jface.text.Position) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 20 with ITextRegionList

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

the class NodeHelper method AttrToString.

public String AttrToString() {
    if (region == null) {
        return null;
    }
    // For debugging
    ITextRegionList t = region.getRegions();
    ITextRegion r;
    Iterator regionIterator = t.iterator();
    // $NON-NLS-1$ //$NON-NLS-2$
    String structuredValue = Messages.NodeHelper00 + getTagName() + Messages.NodeHelper01;
    while (regionIterator.hasNext()) {
        r = (ITextRegion) regionIterator.next();
        if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
            // $NON-NLS-1$
            structuredValue += "\t\t" + region.getText(r);
            /*
				 * Theres a XML_TAG_ATTRIBUTE_EQUALS after the
				 * XML_TAG_ATTRIBUTE_NAME we have to get rid of
				 */
            if (regionIterator.hasNext()) {
                regionIterator.next();
            }
            if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
                if (regionIterator.hasNext()) {
                    r = ((ITextRegion) regionIterator.next());
                }
                if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    structuredValue += "\t\t" + stripEndQuotes(region.getText(r)) + "\n";
                }
            }
        }
    }
    return structuredValue;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Aggregations

ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)193 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)171 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)74 Iterator (java.util.Iterator)46 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)27 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)24 ArrayList (java.util.ArrayList)21 List (java.util.List)18 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)16 StyleRange (org.eclipse.swt.custom.StyleRange)13 TextAttribute (org.eclipse.jface.text.TextAttribute)12 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)12 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)9 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8 DOMException (org.w3c.dom.DOMException)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)7