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);
}
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;
}
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);
}
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;
}
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();
}
}
Aggregations