本文整理汇总了Java中com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.getTopLevelEditor方法的典型用法代码示例。如果您正苦于以下问题:Java InjectedLanguageUtil.getTopLevelEditor方法的具体用法?Java InjectedLanguageUtil.getTopLevelEditor怎么用?Java InjectedLanguageUtil.getTopLevelEditor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
的用法示例。
在下文中一共展示了InjectedLanguageUtil.getTopLevelEditor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rememberDocumentState
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static Runnable rememberDocumentState(final Editor _editor) {
final Editor editor = InjectedLanguageUtil.getTopLevelEditor(_editor);
final String documentText = editor.getDocument().getText();
final int caret = editor.getCaretModel().getOffset();
final int selStart = editor.getSelectionModel().getSelectionStart();
final int selEnd = editor.getSelectionModel().getSelectionEnd();
final int vOffset = editor.getScrollingModel().getVerticalScrollOffset();
final int hOffset = editor.getScrollingModel().getHorizontalScrollOffset();
return new Runnable() {
@Override
public void run() {
DocumentEx document = (DocumentEx) editor.getDocument();
document.replaceString(0, document.getTextLength(), documentText);
editor.getCaretModel().moveToOffset(caret);
editor.getSelectionModel().setSelection(selStart, selEnd);
editor.getScrollingModel().scrollHorizontally(hOffset);
editor.getScrollingModel().scrollVertically(vOffset);
}
};
}
示例2: insertLookupString
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private void insertLookupString(LookupElement item, final int prefix) {
final String lookupString = getCaseCorrectedLookupString(item);
final Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
@Override
public void perform(Caret caret) {
EditorModificationUtil.deleteSelectedText(hostEditor);
final int caretOffset = hostEditor.getCaretModel().getOffset();
int lookupStart = Math.min(caretOffset, Math.max(caretOffset - prefix, 0));
int len = hostEditor.getDocument().getTextLength();
LOG.assertTrue(lookupStart >= 0 && lookupStart <= len,
"ls: " + lookupStart + " caret: " + caretOffset + " prefix:" + prefix + " doc: " + len);
LOG.assertTrue(caretOffset >= 0 && caretOffset <= len, "co: " + caretOffset + " doc: " + len);
hostEditor.getDocument().replaceString(lookupStart, caretOffset, lookupString);
int offset = lookupStart + lookupString.length();
hostEditor.getCaretModel().moveToOffset(offset);
hostEditor.getSelectionModel().removeSelection();
}
});
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
示例3: maySaveDocument
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public boolean maySaveDocument(@NotNull Document document, boolean isSaveExplicit) {
if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) {
return true;
}
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (!project.isInitialized() || project.isDisposed()) {
continue;
}
LookupEx lookup = LookupManager.getInstance(project).getActiveLookup();
if (lookup != null) {
Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor());
if (editor.getDocument() == document) {
return false;
}
}
}
return true;
}
示例4: preprocessEnter
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(@NotNull PsiFile file,
@NotNull Editor editor,
@NotNull Ref<Integer> caretOffset,
@NotNull Ref<Integer> caretAdvance,
@NotNull DataContext dataContext,
EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!(file instanceof PyFile)) {
return Result.Continue;
}
// honor dedent (PY-3009)
if (BackspaceHandler.isWhitespaceBeforeCaret(editor)) {
return Result.DefaultSkipIndent;
}
return Result.Continue;
}
示例5: rememberDocumentState
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static Runnable rememberDocumentState(final Editor _editor) {
final Editor editor = InjectedLanguageUtil.getTopLevelEditor(_editor);
final String documentText = editor.getDocument().getText();
final int caret = editor.getCaretModel().getOffset();
final int selStart = editor.getSelectionModel().getSelectionStart();
final int selEnd = editor.getSelectionModel().getSelectionEnd();
final int vOffset = editor.getScrollingModel().getVerticalScrollOffset();
final int hOffset = editor.getScrollingModel().getHorizontalScrollOffset();
return () -> {
DocumentEx document = (DocumentEx) editor.getDocument();
document.replaceString(0, document.getTextLength(), documentText);
editor.getCaretModel().moveToOffset(caret);
editor.getSelectionModel().setSelection(selStart, selEnd);
editor.getScrollingModel().scrollHorizontally(hOffset);
editor.getScrollingModel().scrollVertically(vOffset);
};
}
示例6: maySaveDocument
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public boolean maySaveDocument(@Nonnull Document document, boolean isSaveExplicit) {
if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) {
return true;
}
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
if (!project.isInitialized() || project.isDisposed()) {
continue;
}
LookupEx lookup = LookupManager.getInstance(project).getActiveLookup();
if (lookup != null) {
Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor());
if (editor.getDocument() == document) {
return false;
}
}
}
return true;
}
示例7: invokeCompletion
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public static void invokeCompletion(@NotNull CompletionType completionType,
boolean autopopup,
Project project, Editor editor, int time, boolean restart) {
if (editor.isDisposed()) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
// retrieve the injected file from scratch since our typing might have destroyed the old one completely
Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(topLevelEditor.getDocument());
if (file == null) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
LOG.error("Non-committed document");
PsiDocumentManager.getInstance(project).commitAllDocuments();
}
Editor newEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(topLevelEditor, topLevelFile);
try {
new CodeCompletionHandlerBase(completionType, false, autopopup, false).invokeCompletion(project, newEditor, time, false, restart);
}
catch (IndexNotReadyException ignored) {
}
}
示例8: getActiveLookup
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static LookupEx getActiveLookup(@Nullable Editor editor) {
if (editor == null) return null;
final Project project = editor.getProject();
if (project == null || project.isDisposed()) return null;
final LookupEx lookup = getInstance(project).getActiveLookup();
if (lookup == null) return null;
return InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor()) == InjectedLanguageUtil.getTopLevelEditor(editor) ? lookup : null;
}
示例9: revertStateOnFinish
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
protected void revertStateOnFinish() {
final Editor editor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
if (editor == FileEditorManager.getInstance(myProject).getSelectedTextEditor()) {
((EditorImpl)editor).startDumb();
}
revertState();
}
示例10: preprocessEnter
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public Result preprocessEnter(
PsiFile file,
Editor editor,
Ref<Integer> caretOffset,
Ref<Integer> caretAdvance,
DataContext dataContext,
EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!isApplicable(file, dataContext) || !insertIndent(file, offset)) {
return Result.Continue;
}
int indent = SectionParser.INDENT;
editor.getCaretModel().moveToOffset(offset);
Document doc = editor.getDocument();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
LogicalPosition position = editor.getCaretModel().getLogicalPosition();
if (position.column < indent) {
String spaces = StringUtil.repeatSymbol(' ', indent - position.column);
doc.insertString(editor.getCaretModel().getOffset(), spaces);
}
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent));
return Result.Stop;
}
示例11: AbstractJavaInplaceIntroducer
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public AbstractJavaInplaceIntroducer(final Project project,
Editor editor,
PsiExpression expr,
PsiVariable localVariable,
PsiExpression[] occurrences,
TypeSelectorManagerImpl typeSelectorManager, String title) {
super(project, InjectedLanguageUtil.getTopLevelEditor(editor), expr, localVariable, occurrences, title, StdFileTypes.JAVA);
myTypeSelectorManager = typeSelectorManager;
}
示例12: invokeCompletion
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public static void invokeCompletion(CompletionType completionType,
boolean autopopup,
Project project, Editor editor, int time, boolean restart) {
if (editor.isDisposed()) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
// retrieve the injected file from scratch since our typing might have destroyed the old one completely
Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(topLevelEditor.getDocument());
if (file == null) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
LOG.error("Non-committed document");
PsiDocumentManager.getInstance(project).commitAllDocuments();
}
Editor newEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(topLevelEditor, topLevelFile);
try {
new CodeCompletionHandlerBase(completionType, false, autopopup, false).invokeCompletion(project, newEditor, time, false, restart);
}
catch (IndexNotReadyException ignored) {
}
}
示例13: showBalloon
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
protected void showBalloon() {
final JComponent component = getComponent();
if (component == null) return;
if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(component, null).setSmallVariant(true);
myBalloon = balloonBuilder.createBalloon();
Disposer.register(myProject, myBalloon);
Disposer.register(myBalloon, new Disposable() {
@Override
public void dispose() {
releaseIfNotRestart();
}
});
final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
topLevelEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
myBalloon.show(new PositionTracker<Balloon>(topLevelEditor.getContentComponent()) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
if (myTarget != null && !popupFactory.isBestPopupLocationVisible(topLevelEditor)) {
return myTarget;
}
final RelativePoint target = popupFactory.guessBestPopupLocation(topLevelEditor);
if (target == null) return myTarget;
final Point screenPoint = target.getScreenPoint();
int y = screenPoint.y;
if (target.getPoint().getY() > topLevelEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
y -= topLevelEditor.getLineHeight();
}
myTarget = new RelativePoint(new Point(screenPoint.x, y));
return myTarget;
}
}, Balloon.Position.above);
}
示例14: invokeCompletion
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
public static void invokeCompletion(@Nonnull CompletionType completionType,
boolean autopopup,
Project project, Editor editor, int time, boolean restart) {
if (editor.isDisposed()) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
// retrieve the injected file from scratch since our typing might have destroyed the old one completely
Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(topLevelEditor.getDocument());
if (file == null) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
return;
}
PsiFile topLevelFile = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
LOG.error("Non-committed document");
PsiDocumentManager.getInstance(project).commitAllDocuments();
}
Editor newEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(topLevelEditor, topLevelFile);
try {
CodeCompletionHandlerBase.createHandler(completionType, false, autopopup, false).invokeCompletion(project, newEditor, time, false, restart);
}
catch (IndexNotReadyException ignored) {
}
}
示例15: showBalloon
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
protected void showBalloon() {
final JComponent component = getComponent();
if (component == null) return;
if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(component, null).setSmallVariant(true);
myBalloon = balloonBuilder.createBalloon();
final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
Disposer.register(myProject, myBalloon);
Disposer.register(myBalloon, new Disposable() {
@Override
public void dispose() {
releaseIfNotRestart();
topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
}
});
topLevelEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
myBalloon.show(new PositionTracker<Balloon>(topLevelEditor.getContentComponent()) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
if (myTarget != null && !popupFactory.isBestPopupLocationVisible(topLevelEditor)) {
return myTarget;
}
if (myCaretRangeMarker != null && myCaretRangeMarker.isValid()) {
topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION,
topLevelEditor.offsetToVisualPosition(myCaretRangeMarker.getStartOffset()));
}
final RelativePoint target = popupFactory.guessBestPopupLocation(topLevelEditor);
final Point screenPoint = target.getScreenPoint();
int y = screenPoint.y;
if (target.getPoint().getY() > topLevelEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
y -= topLevelEditor.getLineHeight();
}
myTarget = new RelativePoint(new Point(screenPoint.x, y));
return myTarget;
}
}, Balloon.Position.above);
}