use of org.eclipse.jface.text.IDocument in project bndtools by bndtools.
the class FileUtils method readFully.
public static IDocument readFully(IFile file) throws CoreException, IOException {
if (file.exists()) {
InputStream stream = file.getContents();
byte[] bytes = readFully(stream);
String string = new String(bytes, file.getCharset());
return new Document(string);
}
return null;
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test3.
/*
* Tests isDirty.
*/
@Test
public void test3() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertFalse(fileBuffer.isDirty());
IDocument document = fileBuffer.getDocument();
document.replace(document.getLength(), 0, "appendix");
assertTrue(fileBuffer.isDirty());
} 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 test11_2.
/*
* Test IFileBufferListener#dirtyStateChanged
*/
@Test
public void test11_2() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
public boolean isDirty;
@Override
public void dirtyStateChanged(IFileBuffer buf, boolean state) {
++count;
this.buffer = buf;
this.isDirty = state;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
IDocument document = fileBuffer.getDocument();
document.replace(0, 0, "prefix");
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(listener.isDirty);
fileBuffer.revert(null);
assertTrue(listener.count == 2);
assertTrue(listener.buffer == fileBuffer);
assertFalse(listener.isDirty);
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class FileStoreFileBufferFunctions method test11_1.
/*
* Test IFileBufferListener#dirtyStateChanged
*/
@Test
public void test11_1() throws Exception {
class Listener extends FileBufferListener {
public IFileBuffer buffer;
public int count;
public boolean isDirty;
@Override
public void dirtyStateChanged(IFileBuffer buf, boolean state) {
++count;
this.buffer = buf;
this.isDirty = state;
}
}
Listener listener = new Listener();
fManager.addFileBufferListener(listener);
try {
ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
assertTrue(listener.count == 0 && listener.buffer == null);
fManager.connectFileStore(fFileStore, null);
try {
fileBuffer = fManager.getFileStoreTextFileBuffer(fFileStore);
IDocument document = fileBuffer.getDocument();
document.replace(0, 0, "prefix");
assertTrue(listener.count == 1);
assertTrue(listener.buffer == fileBuffer);
assertTrue(listener.isDirty);
fileBuffer.commit(null, true);
assertTrue(listener.count == 2);
assertTrue(listener.buffer == fileBuffer);
assertFalse(listener.isDirty);
} finally {
fManager.disconnectFileStore(fFileStore, null);
}
} finally {
fManager.removeFileBufferListener(listener);
}
}
use of org.eclipse.jface.text.IDocument in project eclipse.platform.text by eclipse.
the class AbstractFileBufferDocCreationTests method assertParticipantsInvoked.
/* Utilities */
private void assertParticipantsInvoked(String path, Class<?>[] expectedDSPsArray) {
LocationKind[] lks = getSupportLocationKinds();
for (int i = 0; i < lks.length; i++) {
IDocument document = fManager.createEmptyDocument(new Path(path), lks[i]);
String content = document.get();
Set<String> expectedDSPs = new HashSet<>(Arrays.asList(toString(expectedDSPsArray)));
Set<String> actualDSPs = new HashSet<>(Arrays.asList(content.split("\n")));
assertEquals(expectedDSPs, actualDSPs);
}
}
Aggregations