当前位置: 首页>>代码示例>>Java>>正文


Java InjectedLanguageUtil.getTopLevelEditor方法代码示例

本文整理汇总了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);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CodeCompletionHandlerBase.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LookupImpl.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:LookupDocumentSavingVetoer.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PyEnterAtIndentHandler.java

示例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);
  };
}
 
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:CodeCompletionHandlerBase.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:21,代码来源:LookupDocumentSavingVetoer.java

示例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) {
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:CompletionAutoPopupHandler.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:LookupManager.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:MemberInplaceRenamer.java

示例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;
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:33,代码来源:ProjectViewEnterHandler.java

示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:10,代码来源:AbstractJavaInplaceIntroducer.java

示例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) {
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:CompletionAutoPopupHandler.java

示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:35,代码来源:InplaceRefactoring.java

示例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) {
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:29,代码来源:CompletionAutoPopupHandler.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:39,代码来源:InplaceRefactoring.java


注:本文中的com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.getTopLevelEditor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。