Search in sources :

Example 71 with ITextRegion

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

the class ScannerUnitTests method checkSimpleRegionTypes.

public static boolean checkSimpleRegionTypes(ITextRegionList regions, String[] contexts) {
    for (int i = 0; i < contexts.length; i++) {
        ITextRegion region = regions.get(i);
        assertEquals("region type " + i, contexts[i], region.getType());
    }
    return true;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 72 with ITextRegion

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

the class StructuredDocumentReParser method replaceRegions.

protected void replaceRegions(IStructuredDocumentRegion oldNode, ITextRegionList oldRegions, IStructuredDocumentRegion newNode, ITextRegionList newRegions) {
    int insertPos = -1;
    ITextRegionList regions = oldNode.getRegions();
    // offset
    if (oldRegions.size() == 0) {
        ITextRegion firstNewRegion = newRegions.get(0);
        int firstOffset = newNode.getStartOffset(firstNewRegion);
        // if at beginning, insert there
        if (firstOffset == 0) {
            insertPos = 0;
        } else {
            // 
            ITextRegion regionAtOffset = oldNode.getRegionAtCharacterOffset(firstOffset);
            if (regionAtOffset == null)
                insertPos = regions.size();
            else
                insertPos = regions.indexOf(regionAtOffset);
        }
    } else {
        // else, delete old ones before inserting new ones in their place
        ITextRegion firstOldRegion = oldRegions.get(0);
        insertPos = regions.indexOf(firstOldRegion);
        regions.removeAll(oldRegions);
    }
    regions.addAll(insertPos, newRegions);
    // now regions vector of each node should be of equal length,
    // so go through each, and make sure the old regions
    // offsets matches the new regions offsets
    // (we'll just assign them all, but could be slightly more effiecient)
    ITextRegionList allNewRegions = newNode.getRegions();
    for (int i = 0; i < regions.size(); i++) {
        ITextRegion nextOldishRegion = regions.get(i);
        ITextRegion nextNewRegion = allNewRegions.get(i);
        nextOldishRegion.equatePositions(nextNewRegion);
        checkAndAssignParent(oldNode, nextOldishRegion);
    }
    oldNode.setLength(newNode.getLength());
    oldNode.setEnded(newNode.isEnded());
    oldNode.setParentDocument(newNode.getParentDocument());
// removed concept of part of these regions, so no longer need to do.
// for (int i = 0; i < oldRegions.size(); i++) {
// ITextRegion region = (ITextRegion) oldRegions.elementAt(i);
// region.setParent(holdOldStructuredDocumentRegion);
// }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 73 with ITextRegion

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

the class StructuredDocumentReParser method transferEmbeddedRegions.

/**
 * The purpose of this method is to "reuse" the old container region, when
 * found to be same (so same instance doesn't change). The goal is to
 * "transform" the old region, so its equivelent to the newly parsed one.
 */
private void transferEmbeddedRegions(IStructuredDocumentRegion oldNode, ITextRegionContainer oldRegion, ITextRegionContainer newRegion) {
    // the oldRegion should already have the right parent, since
    // we got here because all's equivelent except the region
    // postions have changed.
    // oldRegion.setParent(newRegion.getParent());
    // but we should check if there's "nested" embedded regions, and if
    // so, we can just move them over. setting their parent as this old
    // region.
    ITextRegionList newRegionsToTransfer = newRegion.getRegions();
    oldRegion.setRegions(newRegionsToTransfer);
    Iterator newRegionsInOldOne = newRegionsToTransfer.iterator();
    while (newRegionsInOldOne.hasNext()) {
        ITextRegion newOne = (ITextRegion) newRegionsInOldOne.next();
        if (isCollectionRegion(newOne)) {
            // ||
            // hasContainerRegions(newOne)) {
            // ((ITextRegionContainer) newOne).setParent(oldRegion);
            oldRegion.setRegions(newRegion.getRegions());
        }
    }
}
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 74 with ITextRegion

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

the class StructuredTextPartitioner method internalGetPartition.

/**
 * Returns the partition containing the given character position of the
 * given document. The document has previously been connected to the
 * partitioner. If the checkBetween parameter is true, an offset between a
 * start and end tag will return a zero-length region.
 */
private void internalGetPartition(int offset, boolean checkBetween) {
    if (fStructuredDocument == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("document partitioner is not connected");
    }
    boolean partitionFound = false;
    int docLength = fStructuredDocument.getLength();
    // get document region type and map to partition type :
    // Note: a partion can be smaller than a flatnode, if that flatnode
    // contains a region container.
    // That's why we need to get "relevent region".
    IStructuredDocumentRegion structuredDocumentRegion = fStructuredDocument.getRegionAtCharacterOffset(offset);
    // this is king of a "normal case" for empty document
    if (structuredDocumentRegion == null) {
        if (docLength == 0) {
            /*
				 * In order to prevent infinite error loops, this partition
				 * must never have a zero length unless the document is also
				 * zero length
				 */
            setInternalPartition(offset, 0, getDefaultPartitionType());
            partitionFound = true;
        } else {
            /*
				 * This case is "unusual". When would region be null, and
				 * document longer than 0. I think this means something's "out
				 * of sync". And we may want to "flag" that fact and just
				 * return one big region of 'unknown', instead of one
				 * character at a time.
				 */
            setInternalPartition(offset, 1, getUnknown());
            partitionFound = true;
        }
    } else if (checkBetween) {
        // else
        if (structuredDocumentRegion.getStartOffset() == offset) {
            IStructuredDocumentRegion previousStructuredDocumentRegion = getParserSpecificPreviousRegion(structuredDocumentRegion);
            if (previousStructuredDocumentRegion != null) {
                ITextRegion next = structuredDocumentRegion.getRegionAtCharacterOffset(offset);
                ITextRegion previousStart = previousStructuredDocumentRegion.getRegionAtCharacterOffset(previousStructuredDocumentRegion.getStartOffset());
                partitionFound = doParserSpecificCheck(offset, partitionFound, structuredDocumentRegion, previousStructuredDocumentRegion, next, previousStart);
            }
        }
    }
    if (!partitionFound && structuredDocumentRegion != null) {
        /* We want the actual ITextRegion and not a possible ITextRegionCollection that
			 * could be returned by IStructuredDocumentRegion#getRegionAtCharacterOffset
			 * This allows for correct syntax highlighting and content assist.
			 */
        DeepRegion resultRegion = getDeepRegionAtCharacterOffset(structuredDocumentRegion, offset);
        partitionFound = isDocumentRegionBasedPartition(structuredDocumentRegion, resultRegion.region, offset);
        if (!partitionFound) {
            if (resultRegion.region != null) {
                String type = getPartitionType(resultRegion.region, offset);
                setInternalPartition(offset, resultRegion.end - offset, type);
            } else {
                // can happen at EOF
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=224886
                // The unknown type was causing problems with content assist in JSP documents
                setInternalPartition(offset, 1, getDefaultPartitionType());
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 75 with ITextRegion

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

the class BasicStructuredDocumentRegion method getType.

/**
 * Provides the type of IStructuredDocumentRegion ... not to be confused
 * with type of XML node! This is subclassed, if something other than type
 * of first region is desired.
 */
public String getType() {
    String result = UNDEFINED;
    ITextRegionList subregions = getRegions();
    if (subregions != null && subregions.size() > 0) {
        ITextRegion firstRegion = subregions.get(0);
        if (firstRegion != null) {
            result = firstRegion.getType();
        }
    }
    return result;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)447 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)179 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)174 Iterator (java.util.Iterator)75 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)58 ArrayList (java.util.ArrayList)40 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)39 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)35 List (java.util.List)33 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)31 BadLocationException (org.eclipse.jface.text.BadLocationException)30 RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)19 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)16 Node (org.w3c.dom.Node)16 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)15 IOException (java.io.IOException)13 IRegion (org.eclipse.jface.text.IRegion)13 StyleRange (org.eclipse.swt.custom.StyleRange)13