use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method testGetBufferForDocument.
@Test
public void testGetBufferForDocument() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertNotNull(buffer);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertSame(buffer, fManager.getTextFileBuffer(document));
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test6.
/*
* Test revert.
*/
@Test
public void test6() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
// set dirty bit
IDocument document = fileBuffer.getDocument();
String originalContent = document.get();
document.replace(document.getLength(), 0, "appendix");
// invalidate synchronization state
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
if (fileInfo.exists())
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
// revert
fileBuffer.revert(null);
// check assertions
assertEquals(originalContent, document.get());
assertFalse(fileBuffer.isDirty());
assertTrue(fileBuffer.isSynchronized());
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class LastSaveReferenceProvider method readDocument.
/**
* Reads in the saved document into <code>fReference</code>.
*
* @param monitor a progress monitor, or <code>null</code>
* @param force <code>true</code> if the reference document should also
* be read if the current document is <code>null</code>,<code>false</code>
* if it should only be updated if it already existed.
*/
private void readDocument(IProgressMonitor monitor, boolean force) {
// protect against concurrent disposal
IDocumentProvider prov = fDocumentProvider;
IEditorInput inp = fEditorInput;
IDocument doc = fReference;
ITextEditor editor = fEditor;
if (prov instanceof IStorageDocumentProvider && inp instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput) inp;
IStorageDocumentProvider provider = (IStorageDocumentProvider) prov;
if (doc == null)
if (force || fDocumentRead)
doc = new Document();
else
return;
IJobManager jobMgr = Job.getJobManager();
try {
IStorage storage = input.getStorage();
// check for null for backward compatibility (we used to check before...)
if (storage == null)
return;
fProgressMonitor = monitor;
ISchedulingRule rule = getSchedulingRule(storage);
// delay for any other job requiring the lock on file
try {
lockDocument(monitor, jobMgr, rule);
String encoding;
if (storage instanceof IEncodedStorage)
encoding = ((IEncodedStorage) storage).getCharset();
else
encoding = null;
boolean skipUTF8BOM = isUTF8BOM(encoding, storage);
setDocumentContent(doc, storage, encoding, monitor, skipUTF8BOM);
} finally {
unlockDocument(jobMgr, rule);
fProgressMonitor = null;
}
} catch (CoreException e) {
return;
}
if (monitor != null && monitor.isCanceled())
return;
// update state
synchronized (fLock) {
if (fDocumentProvider == provider && fEditorInput == input) {
// only update state if our provider / input pair has not
// been updated in between (dispose or setActiveEditor)
fReference = doc;
fDocumentRead = true;
addElementStateListener(editor, prov);
}
}
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class GotoLineTest method goToLine.
private void goToLine(int line, int expectedResult) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart part = IDE.openEditor(page, fFile);
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
Accessor accessor = new Accessor(action, GotoLineAction.class);
accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
int caretLine = -1;
StyledText styledText = (StyledText) control;
int caret = styledText.getCaretOffset();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
caretLine = document.getLineOfOffset(caret);
} catch (BadLocationException e1) {
fail();
}
assertEquals(expectedResult, caretLine);
} else
fail();
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class MarkerAnnotationOrderTest method testDirectDependency.
@Test
public void testDirectDependency() {
final ArrayList<IStatus> list = new ArrayList<>(2);
Bundle bundle = Platform.getBundle(EditorsUI.PLUGIN_ID);
ILog log = Platform.getLog(bundle);
log.addLogListener(new ILogListener() {
@Override
public void logging(IStatus status, String plugin) {
list.add(status);
}
});
TestMarkerAnnotationModel t1 = new TestMarkerAnnotationModel();
Position position = new Position(0);
position.delete();
IDocument d = null;
try {
t1.updateMarker(d, null, position);
} catch (CoreException e) {
fail("update marker failed to execute");
log(e);
}
assertEquals("Wrong number of messages", 2, list.size());
assertEquals("Wrong Message for first status", "Marker Updater 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest2' and 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1' depend on each other, 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest2' will run before 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1'", ((Status) list.get(0)).getMessage());
assertEquals("Wrong Message for second status", "Marker Updater 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest4' and 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1' depend on each other, 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest4' will run before 'org.eclipse.ui.texteditor.BasicMarkerUpdaterTest1'", ((Status) list.get(1)).getMessage());
}
Aggregations