Search in sources :

Example 36 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method initialize.

protected void initialize() {
    partitionScanner.setRange(document, 0, document.getLength());
    try {
        for (IToken token = partitionScanner.nextToken(); !token.isEOF(); token = partitionScanner.nextToken()) {
            String contentType = getTokenContentType(token);
            if (isSupportedContentType(contentType)) {
                TypedPosition p = createPosition(partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(), contentType);
                addPosition(document, positionCategory, p);
            }
        }
    } catch (BadLocationException _ex) {
    } catch (BadPositionCategoryException _ex) {
    }
}
Also used : IToken(org.eclipse.jface.text.rules.IToken) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 37 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method getPartition.

public ITypedRegion getPartition(int offset) {
    try {
        Position[] category = document.getPositions(positionCategory);
        if (category == null || category.length == 0) {
            // $NON-NLS-1$
            return new TypedRegion(0, document.getLength(), "__dftl_partition_content_type");
        }
        int index = document.computeIndexInCategory(positionCategory, 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) {
                // $NON-NLS-1$
                return new TypedRegion(0, next.offset, "__dftl_partition_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();
            // $NON-NLS-1$
            return new TypedRegion(endOffset, next.getOffset() - endOffset, "__dftl_partition_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();
        // $NON-NLS-1$
        return new TypedRegion(endOffset, document.getLength() - endOffset, "__dftl_partition_content_type");
    } catch (BadPositionCategoryException _ex) {
    } catch (BadLocationException _ex) {
    }
    // $NON-NLS-1$
    return new TypedRegion(0, document.getLength(), "__dftl_partition_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 38 with TypedPosition

use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method documentChanged2.

public IRegion documentChanged2(DocumentEvent e) {
    try {
        IDocument d = e.getDocument();
        Position[] category = d.getPositions(positionCategory);
        IRegion line = d.getLineInformationOfOffset(e.getOffset());
        int reparseStart = line.getOffset();
        int partitionStart = -1;
        String contentType = null;
        int first = d.computeIndexInCategory(positionCategory, reparseStart);
        if (first > 0) {
            TypedPosition partition = (TypedPosition) category[first - 1];
            if (partition.includes(reparseStart)) {
                partitionStart = partition.getOffset();
                contentType = partition.getType();
                if (e.getOffset() == partition.getOffset() + partition.getLength()) {
                    reparseStart = partitionStart;
                }
                first--;
            } else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
                partitionStart = partition.getOffset();
                contentType = partition.getType();
                reparseStart = partitionStart;
                first--;
            } else {
                partitionStart = partition.getOffset() + partition.getLength();
                // $NON-NLS-1$
                contentType = "__dftl_partition_content_type";
            }
        }
        positionUpdater.update(e);
        for (int i = first; i < category.length; i++) {
            Position p = category[i];
            if (!p.isDeleted) {
                continue;
            }
            rememberDeletedOffset(e.getOffset());
            break;
        }
        category = d.getPositions(positionCategory);
        partitionScanner.setPartialRange(d, reparseStart, d.getLength() - reparseStart, contentType, partitionStart);
        int lastScannedPosition = reparseStart;
        for (IToken token = partitionScanner.nextToken(); !token.isEOF(); ) {
            contentType = getTokenContentType(token);
            if (!isSupportedContentType(contentType)) {
                token = partitionScanner.nextToken();
            } else {
                int start = partitionScanner.getTokenOffset();
                int length = partitionScanner.getTokenLength();
                lastScannedPosition = (start + length) - 1;
                for (; first < category.length; first++) {
                    TypedPosition p = (TypedPosition) category[first];
                    if (lastScannedPosition < p.offset + p.length && (!p.overlapsWith(start, length) || d.containsPosition(positionCategory, start, length) && contentType.equals(p.getType()))) {
                        break;
                    }
                    rememberRegion(p.offset, p.length);
                    d.removePosition(positionCategory, p);
                }
                if (d.containsPosition(positionCategory, start, length)) {
                    if (lastScannedPosition > e.getOffset()) {
                        return createRegion();
                    }
                    first++;
                } else {
                    try {
                        TypedPosition p = createPosition(start, length, contentType);
                        addPosition(d, positionCategory, p);
                        rememberRegion(start, length);
                    } catch (BadPositionCategoryException _ex) {
                    } catch (BadLocationException _ex) {
                    }
                }
                token = partitionScanner.nextToken();
            }
        }
        if (lastScannedPosition != reparseStart)
            lastScannedPosition++;
        for (first = d.computeIndexInCategory(positionCategory, lastScannedPosition); first < category.length; ) {
            TypedPosition p = (TypedPosition) category[first++];
            d.removePosition(positionCategory, p);
            rememberRegion(p.offset, p.length);
        }
    } catch (BadPositionCategoryException _ex) {
    } catch (BadLocationException _ex) {
    }
    return createRegion();
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) Position(org.eclipse.jface.text.Position) IToken(org.eclipse.jface.text.rules.IToken) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

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