Search in sources :

Example 66 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project hale by halestudio.

the class GroovySourceViewerUtil method setupDocument.

/**
 * Setup a Groovy document.
 *
 * @param doc the document
 */
public static void setupDocument(IDocument doc) {
    IPartitionTokenScanner scanner = new GroovyPartitionScanner();
    IDocumentPartitioner partitioner = new FastPartitioner(scanner, GroovyPartitionScanner.LEGAL_CONTENT_TYPES);
    doc.setDocumentPartitioner(partitioner);
    partitioner.connect(doc);
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner) IPartitionTokenScanner(org.eclipse.jface.text.rules.IPartitionTokenScanner) GroovyPartitionScanner(eu.esdihumboldt.hale.ui.util.groovy.internal.GroovyPartitionScanner)

Example 67 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project xtext-eclipse by eclipse.

the class XtextDocumentProvider method createDocument.

@Override
protected IDocument createDocument(Object element) throws CoreException {
    IDocument document = null;
    if (isWorkspaceExternalEditorInput(element)) {
        document = createEmptyDocument();
        if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
            setupDocument(element, document);
        }
    } else {
        document = super.createDocument(element);
    }
    if (document != null) {
        IDocumentPartitioner partitioner = documentPartitioner.get();
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);
    }
    return document;
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IDocument(org.eclipse.jface.text.IDocument)

Example 68 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project egit by eclipse.

the class DiffDocument method connect.

/**
 * Sets up the document to use information from the given
 * {@link DiffRegionFormatter} for partitioning the document into
 * partitions for file headlines, hunk headers, and added or removed lines.
 * It is assumed that the given formatter has been used to generate content
 * into the document.
 *
 * @param formatter
 *            to obtain information from
 */
public void connect(DiffRegionFormatter formatter) {
    regions = formatter.getRegions();
    fileRegions = formatter.getFileRegions();
    if ((fileRegions == null || fileRegions.length == 0) && defaultRepository != null && defaultFileDiff != null) {
        fileRegions = new FileDiffRegion[] { new FileDiffRegion(defaultRepository, defaultFileDiff, 0, getLength()) };
    }
    newPathPattern = Pattern.compile(// $NON-NLS-1$
    Pattern.quote(formatter.getNewPrefix()) + "\\S+");
    oldPathPattern = Pattern.compile(// $NON-NLS-1$
    Pattern.quote(formatter.getOldPrefix()) + "\\S+");
    maximumLineNumbers = formatter.getMaximumLineNumbers();
    // Connect a new partitioner.
    IDocumentPartitioner partitioner = new FastPartitioner(new DiffPartitionTokenScanner(), new String[] { IDocument.DEFAULT_CONTENT_TYPE, HEADLINE_CONTENT_TYPE, HUNK_CONTENT_TYPE, ADDED_CONTENT_TYPE, REMOVED_CONTENT_TYPE });
    IDocumentPartitioner oldPartitioner = getDocumentPartitioner();
    if (oldPartitioner != null) {
        oldPartitioner.disconnect();
    }
    partitioner.connect(this);
    setDocumentPartitioner(partitioner);
}
Also used : IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) FileDiffRegion(org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion) FastPartitioner(org.eclipse.jface.text.rules.FastPartitioner)

Example 69 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project mylyn.docs by eclipse.

the class MarkupEditor method getMarkupLanguage.

public MarkupLanguage getMarkupLanguage() {
    IDocument document = getDocumentProvider().getDocument(getEditorInput());
    IDocumentPartitioner partitioner = document.getDocumentPartitioner();
    MarkupLanguage markupLanguage = null;
    if (partitioner instanceof FastMarkupPartitioner) {
        markupLanguage = ((FastMarkupPartitioner) partitioner).getMarkupLanguage();
    }
    return markupLanguage;
}
Also used : FastMarkupPartitioner(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) AbstractMarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.AbstractMarkupLanguage) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) IDocument(org.eclipse.jface.text.IDocument)

Example 70 with IDocumentPartitioner

use of org.eclipse.jface.text.IDocumentPartitioner in project mylyn.docs by eclipse.

the class MarkupTokenScanner method setRange.

public void setRange(IDocument document, int offset, int length) {
    IDocumentPartitioner partitioner = document.getDocumentPartitioner();
    List<Token> tokens = null;
    if (partitioner instanceof FastMarkupPartitioner) {
        FastMarkupPartitioner fastMarkupPartitioner = (FastMarkupPartitioner) partitioner;
        ITypedRegion[] partitioning = partitioner.computePartitioning(offset, length);
        if (partitioning != null) {
            tokens = new ArrayList<>();
            ITypedRegion[] partitions = ((FastMarkupPartitioner) partitioner).getScanner().computePartitions(document, offset, length);
            int lastEnd = offset;
            Token defaultToken;
            {
                StyleRange styleRange = styleManager.createStyleRange(defaultState, 0, 1);
                TextAttribute textAttribute = createTextAttribute(styleRange);
                defaultToken = new Token(defaultState, textAttribute, offset, length);
            }
            if (partitions != null) {
                for (ITypedRegion region : partitions) {
                    if (region.getOffset() >= (offset + length)) {
                        break;
                    }
                    if ((region.getOffset() + region.getLength()) < offset) {
                        continue;
                    }
                    if (region instanceof MarkupPartition) {
                        MarkupPartition partition = (MarkupPartition) region;
                        if (lastEnd < partition.getOffset()) {
                            Token blockBridgeToken = new Token(defaultToken.fontState, defaultToken.getData(), lastEnd, partition.getOffset() - lastEnd);
                            addToken(tokens, blockBridgeToken);
                        }
                        // a token that spans the whole block
                        Token blockToken = createToken(partition);
                        if (blockToken == null) {
                            blockToken = defaultToken;
                        }
                        if (!partition.getBlock().isSpansComputed()) {
                            fastMarkupPartitioner.reparse(document, partition.getBlock());
                        }
                        List<Span> spans = partition.getSpans();
                        if (spans != null) {
                            for (Span span : spans) {
                                if (span.getOffset() < lastEnd) {
                                    continue;
                                }
                                Token spanToken = createToken(blockToken.getFontState(), span);
                                if (spanToken != null) {
                                    int blockTokenStartOffset = lastEnd < offset ? offset : lastEnd;
                                    if (blockTokenStartOffset < spanToken.getOffset()) {
                                        int blockTokenLength = spanToken.getOffset() - blockTokenStartOffset;
                                        final Token blockBridgeToken = new Token(blockToken.fontState, blockToken.getData(), blockTokenStartOffset, blockTokenLength);
                                        addToken(tokens, blockBridgeToken);
                                    }
                                    Token[] spanTokens = null;
                                    if (!span.getChildren().isEmpty()) {
                                        spanTokens = splitSpan(spanToken, span, defaultToken);
                                    }
                                    if (spanTokens != null) {
                                        for (Token spanSplitToken : spanTokens) {
                                            addToken(tokens, spanSplitToken);
                                        }
                                    } else {
                                        addToken(tokens, spanToken);
                                    }
                                    lastEnd = spanToken.offset + spanToken.length;
                                    if (lastEnd > partition.getOffset() + partition.getLength()) {
                                        throw new IllegalStateException();
                                    }
                                }
                            }
                        }
                        final int partitionEnd = partition.getOffset() + partition.getLength();
                        if (lastEnd < partitionEnd) {
                            final int realLastEnd = Math.max(lastEnd, partition.getOffset());
                            int diff = (partitionEnd) - realLastEnd;
                            if (diff > 0) {
                                int blockTokenStartOffset = realLastEnd;
                                int blockTokenLength = diff;
                                final Token blockBridgeToken = new Token(blockToken.fontState, blockToken.getData(), blockTokenStartOffset, blockTokenLength);
                                addToken(tokens, blockBridgeToken);
                                lastEnd = blockTokenStartOffset + blockTokenLength;
                                if (lastEnd > partition.getOffset() + partition.getLength()) {
                                    throw new IllegalStateException();
                                }
                            }
                        }
                    }
                }
            }
            if (lastEnd < (offset + length)) {
                addToken(tokens, new Token(defaultToken.fontState, defaultToken.getData(), lastEnd, length - (lastEnd - offset)));
            }
        }
    }
    currentToken = null;
    if (tokens == null || tokens.isEmpty()) {
        tokenIt = null;
    } else {
        Iterator<Token> it = tokens.iterator();
        while (it.hasNext()) {
            Token next = it.next();
            if (next.getOffset() < offset) {
                it.remove();
            } else if (next.getOffset() + next.getLength() > (offset + length)) {
                it.remove();
            }
        }
        tokenIt = tokens.iterator();
    }
}
Also used : TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange) IToken(org.eclipse.jface.text.rules.IToken) MarkupPartition(org.eclipse.mylyn.internal.wikitext.ui.editor.syntax.FastMarkupPartitioner.MarkupPartition) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Aggregations

IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)72 IDocument (org.eclipse.jface.text.IDocument)27 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)27 FastPartitioner (org.eclipse.jface.text.rules.FastPartitioner)25 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)12 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)9 IFile (org.eclipse.core.resources.IFile)7 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)7 IStructuredTextPartitioner (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)6 BadLocationException (org.eclipse.jface.text.BadLocationException)5 ITypedRegion (org.eclipse.jface.text.ITypedRegion)5 DocumentEvent (org.eclipse.jface.text.DocumentEvent)4 IDocumentListener (org.eclipse.jface.text.IDocumentListener)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)3 IPath (org.eclipse.core.runtime.IPath)3 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)3 SQLDocument (com.cubrid.common.ui.query.editor.SQLDocument)2 SQLPartitionScanner (com.cubrid.common.ui.query.editor.SQLPartitionScanner)2