use of org.eclipse.jface.text.IDocumentPartitioner in project webtools.sourceediting by eclipse.
the class FileBufferDocumentTester method doTestCreate.
private void doTestCreate(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws CoreException, IOException {
IFile file = (IFile) fTestProject.findMember(filePath);
assertNotNull("Test Case in error. Could not find file " + filePath, file);
IPath fullPath = file.getFullPath();
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
bufferManager.connect(fullPath, LocationKind.IFILE, null);
ITextFileBuffer buffer = bufferManager.getTextFileBuffer(fullPath);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertTrue("wrong class of document: " + (document != null ? document.getClass() : null), expectedDocumentClass.isInstance(document));
assertTrue("document does not implement IDocumentExtension3", document instanceof IDocumentExtension3);
IDocumentPartitioner actualPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
assertTrue("wrong partitioner in document: " + actualPartitioner, expectedPartioner.isInstance(actualPartitioner));
bufferManager.disconnect(fullPath, LocationKind.IFILE, null);
// doTestCreateWithFacade(file, expectedDocumentClass, expectedPartioner);
}
use of org.eclipse.jface.text.IDocumentPartitioner in project dbeaver by serge-rider.
the class XMLEditor method setupDocument.
private void setupDocument() {
IDocument document = getDocument();
if (document != null) {
IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(), new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
partitioner.connect(document);
((IDocumentExtension3) document).setDocumentPartitioner(XMLPartitionScanner.XML_PARTITIONING, partitioner);
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project dbeaver by serge-rider.
the class JSONTextEditor method setupDocument.
private void setupDocument() {
IDocument document = getDocument();
if (document != null) {
IDocumentPartitioner partitioner = new FastPartitioner(new JSONPartitionScanner(), new String[] { JSONPartitionScanner.JSON_STRING });
partitioner.connect(document);
((IDocumentExtension3) document).setDocumentPartitioner(JSONPartitionScanner.JSON_PARTITIONING, partitioner);
}
}
use of org.eclipse.jface.text.IDocumentPartitioner in project xtext-xtend by eclipse.
the class PartitionTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
document = get(XtextDocument.class);
IDocumentPartitioner partitioner = get(IDocumentPartitioner.class);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
}
use of org.eclipse.jface.text.IDocumentPartitioner in project xtext-xtend by eclipse.
the class RichStringAwareSourceViewer method shift.
@SuppressWarnings("deprecation")
@Override
protected void shift(boolean useDefaultPrefixes, boolean right, boolean ignoreWhitespace) {
if (useDefaultPrefixes && ignoreWhitespace) {
// let's assume we toggled comments
if (fUndoManager != null)
fUndoManager.beginCompoundChange();
IDocument d = getDocument();
Map<String, IDocumentPartitioner> partitioners = null;
DocumentRewriteSession rewriteSession = null;
try {
ITextSelection selection = (ITextSelection) getSelection();
IRegion block = copiedGetTextBlockFromSelection(selection);
ITypedRegion[] regions = TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false);
regions = merger.merge(regions);
int lineCount = 0;
// [start line, end line, start line, end line, ...]
int[] lines = new int[regions.length * 2];
for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
// start line of region
lines[j] = copiedGetFirstCompleteLineOfRegion(regions[i]);
// end line of region
int length = regions[i].getLength();
int offset = regions[i].getOffset() + length;
if (length > 0)
offset--;
lines[j + 1] = (lines[j] == -1 ? -1 : d.getLineOfOffset(offset));
lineCount += lines[j + 1] - lines[j] + 1;
}
if (d instanceof IDocumentExtension4) {
IDocumentExtension4 extension = (IDocumentExtension4) d;
rewriteSession = extension.startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
} else {
setRedraw(false);
startSequentialRewriteMode(true);
}
if (lineCount >= 20)
partitioners = TextUtilities.removeDocumentPartitioners(d);
// Perform the shift operation.
@SuppressWarnings("rawtypes") Map map = fDefaultPrefixChars;
for (int i = 0, j = 0; i < regions.length; i++, j += 2) {
String[] prefixes = (String[]) copiedSelectContentTypePlugin(regions[i].getType(), map);
if (prefixes != null && prefixes.length > 0 && lines[j] >= 0 && lines[j + 1] >= 0) {
if (right)
copiedShiftRight(lines[j], lines[j + 1], prefixes[0]);
else
copiedShiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace);
}
}
} catch (BadLocationException x) {
log.debug(x.getMessage(), x);
} finally {
if (partitioners != null)
TextUtilities.addDocumentPartitioners(d, partitioners);
if (d instanceof IDocumentExtension4) {
IDocumentExtension4 extension = (IDocumentExtension4) d;
extension.stopRewriteSession(rewriteSession);
} else {
stopSequentialRewriteMode();
setRedraw(true);
}
if (fUndoManager != null)
fUndoManager.endCompoundChange();
}
} else {
super.shift(useDefaultPrefixes, right, ignoreWhitespace);
}
}
Aggregations