本文整理汇总了Java中org.eclipse.che.ide.api.editor.texteditor.TextEditor.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java TextEditor.getDocument方法的具体用法?Java TextEditor.getDocument怎么用?Java TextEditor.getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.che.ide.api.editor.texteditor.TextEditor
的用法示例。
在下文中一共展示了TextEditor.getDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isCursorInRightPlace
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; //导入方法依赖的package包/类
private boolean isCursorInRightPlace(TextEditor activeEditor, int offset) {
Document document = activeEditor.getDocument();
int lineIndex = document.getLineAtOffset(offset);
int nextLineIndex = lineIndex + 1;
int nextLineStart = document.getLineStart(nextLineIndex);
String contentRange =
activeEditor.getDocument().getContentRange(offset, nextLineStart - offset);
return contentRange.contains(")");
}
示例2: computeCompletionProposals
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; //导入方法依赖的package包/类
@Override
public void computeCompletionProposals(
TextEditor editor, int offset, boolean triggered, CodeAssistCallback callback) {
Document document = editor.getDocument();
TextPosition position = document.getPositionFromIndex(offset);
String currentLine = editor.getDocument().getLineContent(position.getLine());
final String currentWord = getCurrentWord(currentLine, position.getCharacter());
List<CompletionProposal> result = new ArrayList<>();
if (triggered && !lastCompletion.isGoodFor(currentWord, offset)) {
lastCompletion.offset = offset;
lastCompletion.wordStartOffset = offset - currentWord.length(); // start completion word
lastCompletion.word = currentWord;
}
List<Macro> macros = registry.getMacros();
for (Macro macro : macros) {
List<Match> matches = fuzzyMatches.fuzzyMatch(currentWord, macro.getName());
if (matches != null) {
MacroCompletionProposal proposal =
new MacroCompletionProposal(
macro, matches, resources, lastCompletion.wordStartOffset, currentWord.length());
result.add(proposal);
}
}
result.sort(
(o1, o2) -> {
MacroCompletionProposal p1 = ((MacroCompletionProposal) o1);
MacroCompletionProposal p2 = ((MacroCompletionProposal) o2);
return p1.getMacro().getName().compareTo(p2.getMacro().getName());
});
callback.proposalComputed(result);
}
示例3: computeOccurrences
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; //导入方法依赖的package包/类
@Override
public JsPromise<OrionOccurrenceOverlay[]> computeOccurrences(
OrionOccurrenceContextOverlay context) {
final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
return null;
}
final TextEditor editor = ((TextEditor) activeEditor);
if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
return null;
}
final LanguageServerEditorConfiguration configuration =
(LanguageServerEditorConfiguration) editor.getConfiguration();
if (configuration.getServerCapabilities().getDocumentHighlightProvider() == null
|| !configuration.getServerCapabilities().getDocumentHighlightProvider()) {
return null;
}
final Document document = editor.getDocument();
final TextDocumentPositionParams paramsDTO = helper.createTDPP(document, context.getStart());
Promise<List<DocumentHighlight>> promise = client.documentHighlight(paramsDTO);
Promise<OrionOccurrenceOverlay[]> then =
promise.then(
new Function<List<DocumentHighlight>, OrionOccurrenceOverlay[]>() {
@Override
public OrionOccurrenceOverlay[] apply(List<DocumentHighlight> highlights)
throws FunctionException {
final OrionOccurrenceOverlay[] occurrences =
new OrionOccurrenceOverlay[highlights.size()];
for (int i = 0; i < occurrences.length; i++) {
DocumentHighlight highlight = highlights.get(i);
final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create();
Position start = highlight.getRange().getStart();
Position end = highlight.getRange().getEnd();
int startIndex =
document.getIndexFromPosition(
new TextPosition(start.getLine(), start.getCharacter()));
int endIndex =
document.getIndexFromPosition(
new TextPosition(end.getLine(), end.getCharacter()));
occurrence.setStart(startIndex);
occurrence.setEnd(endIndex + 1);
occurrences[i] = occurrence;
}
return occurrences;
}
});
return (JsPromise<OrionOccurrenceOverlay[]>) then;
}
示例4: getLineStartOffset
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; //导入方法依赖的package包/类
private int getLineStartOffset(TextEditor activeEditor, int offset) {
Document document = activeEditor.getDocument();
int lineIndex = document.getLineAtOffset(offset);
return document.getLineStart(lineIndex);
}
示例5: computeQuickAssistProposals
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; //导入方法依赖的package包/类
@Override
public void computeQuickAssistProposals(
final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
final TextEditor textEditor = quickAssistContext.getTextEditor();
final Document document = textEditor.getDocument();
LinearRange tempRange;
tempRange = textEditor.getSelectedLinearRange();
final LinearRange range = tempRange;
final boolean goToClosest = (range.getLength() == 0);
final QueryAnnotationsEvent.AnnotationFilter filter =
new QueryAnnotationsEvent.AnnotationFilter() {
@Override
public boolean accept(final Annotation annotation) {
if (!(annotation instanceof JavaAnnotation)) {
return false;
} else {
JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
return (!javaAnnotation
.isMarkedDeleted()) /*&& JavaAnnotationUtil.hasCorrections(annotation)*/;
}
}
};
final QueryAnnotationsEvent.QueryCallback queryCallback =
new QueryAnnotationsEvent.QueryCallback() {
@Override
public void respond(final Map<Annotation, Position> annotations) {
List<Problem> problems = new ArrayList<>();
/*final Map<Annotation, Position> problems =*/
int offset =
collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
if (offset != range.getStartOffset()) {
TextEditor presenter = ((TextEditor) textEditor);
presenter.getCursorModel().setCursorPosition(offset);
}
setupProposals(callback, textEditor, offset, problems);
}
};
final QueryAnnotationsEvent event =
new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
document.getDocumentHandle().getDocEventBus().fireEvent(event);
}