下面列出了怎么用org.eclipse.jface.text.AbstractDocument的API类实例代码及写法,或者点击链接到github查看源代码。
private void workaroundOmniSharpIssue1088(IDocument document) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Wait for document to be connected
Method getDocumentListenersMethod = AbstractDocument.class.getDeclaredMethod("getDocumentListeners");
getDocumentListenersMethod.setAccessible(true);
new DisplayHelper() {
@Override protected boolean condition() {
try {
return ((Collection<?>)getDocumentListenersMethod.invoke(document)).stream().anyMatch(o -> o.getClass().getName().contains("lsp4e"));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return false;
}
}
}.waitForCondition(Display.getDefault(), 5000);
assertNotEquals("LS Document listener was not setup after 5s", Collections.emptyList(), getDocumentListenersMethod.invoke(document));
// workaround https://github.com/OmniSharp/omnisharp-roslyn/issues/1445
DisplayHelper.sleep(5000);
// force fake modification for OmniSharp to wake up
document.set(document.get().replace("Hello", "Kikoo"));
DisplayHelper.sleep(500);
}
/**
* Determine the current Line delimiter at the given offset.
*
* @param doc
* the document to query for the newline sequence.
* @param offset
* absolute character position
* @return the new line sequence used in the line containing offset
* @throws BadLocationException
* in case offset doesn't fit a legal position
*/
public static String lineDelimiter(IXtextDocument doc, int offset) throws BadLocationException {
String nl = doc.getLineDelimiter(doc.getLineOfOffset(offset));
if (nl == null) {
if (doc instanceof AbstractDocument) {
nl = ((AbstractDocument) doc).getDefaultLineDelimiter();
}
}
return nl;
}