Search in sources :

Example 21 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project che by eclipse.

the class FastPartitioner method initialize.

/**
	 * Performs the initial partitioning of the partitioner's document.
	 * <p>
	 * May be extended by subclasses.
	 * </p>
	 */
protected void initialize() {
    fIsInitialized = true;
    clearPositionCache();
    fScanner.setRange(fDocument, 0, fDocument.getLength());
    try {
        IToken token = fScanner.nextToken();
        while (!token.isEOF()) {
            String contentType = getTokenContentType(token);
            if (isSupportedContentType(contentType)) {
                TypedPosition p = new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
                fDocument.addPosition(fPositionCategory, p);
            }
            token = fScanner.nextToken();
        }
    } catch (BadLocationException x) {
    // cannot happen as offsets come from scanner
    } catch (BadPositionCategoryException x) {
    // cannot happen if document has been connected before
    }
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 22 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project eclipse.platform.text by eclipse.

the class DefaultPartitioner method initialize.

/**
 * Performs the initial partitioning of the partitioner's document.
 */
protected void initialize() {
    fIsInitialized = true;
    fScanner.setRange(fDocument, 0, fDocument.getLength());
    try {
        IToken token = fScanner.nextToken();
        while (!token.isEOF()) {
            String contentType = getTokenContentType(token);
            if (isSupportedContentType(contentType)) {
                TypedPosition p = new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
                fDocument.addPosition(fPositionCategory, p);
            }
            token = fScanner.nextToken();
        }
    } catch (BadLocationException x) {
    // cannot happen as offsets come from scanner
    } catch (BadPositionCategoryException x) {
    // cannot happen if document has been connected before
    }
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 23 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project eclipse.platform.text by eclipse.

the class DefaultPartitioner method getContentType.

@Override
public String getContentType(int offset) {
    checkInitialization();
    TypedPosition p = findClosestPosition(offset);
    if (p != null && p.includes(offset))
        return p.getType();
    return IDocument.DEFAULT_CONTENT_TYPE;
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition)

Example 24 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project eclipse.platform.text by eclipse.

the class DefaultPartitioner method getPartition.

@Override
public ITypedRegion getPartition(int offset) {
    checkInitialization();
    try {
        Position[] category = fDocument.getPositions(fPositionCategory);
        if (category == null || category.length == 0)
            return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
        int index = fDocument.computeIndexInCategory(fPositionCategory, offset);
        if (index < category.length) {
            TypedPosition next = (TypedPosition) category[index];
            if (offset == next.offset)
                return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
            if (index == 0)
                return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
            TypedPosition previous = (TypedPosition) category[index - 1];
            if (previous.includes(offset))
                return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
            int endOffset = previous.getOffset() + previous.getLength();
            return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
        }
        TypedPosition previous = (TypedPosition) category[category.length - 1];
        if (previous.includes(offset))
            return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
        int endOffset = previous.getOffset() + previous.getLength();
        return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
    } catch (BadPositionCategoryException x) {
    } catch (BadLocationException x) {
    }
    return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) Position(org.eclipse.jface.text.Position) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) ITypedRegion(org.eclipse.jface.text.ITypedRegion) TypedRegion(org.eclipse.jface.text.TypedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project eclipse.platform.text by eclipse.

the class FastPartitioner method getContentType.

/**
 * {@inheritDoc}
 * <p>
 * May be replaced or extended by subclasses.
 * </p>
 */
@Override
public String getContentType(int offset) {
    checkInitialization();
    TypedPosition p = findClosestPosition(offset);
    if (p != null && p.includes(offset))
        return p.getType();
    return IDocument.DEFAULT_CONTENT_TYPE;
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition)

Aggregations

TypedPosition (org.eclipse.jface.text.TypedPosition)38 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)26 BadLocationException (org.eclipse.jface.text.BadLocationException)23 Position (org.eclipse.jface.text.Position)19 ITypedRegion (org.eclipse.jface.text.ITypedRegion)13 TypedRegion (org.eclipse.jface.text.TypedRegion)12 ArrayList (java.util.ArrayList)7 IDocument (org.eclipse.jface.text.IDocument)7 IRegion (org.eclipse.jface.text.IRegion)5 IToken (org.eclipse.jface.text.rules.IToken)4 TextEdit (org.eclipse.text.edits.TextEdit)3 List (java.util.List)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 XMLNode (com.amalto.workbench.widgets.xmlviewer.model.XMLNode)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CoreException (org.eclipse.core.runtime.CoreException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1