Java源码示例:com.intellij.lang.parameterInfo.ParameterInfoHandler

示例1
private static void showParameterHint(final PsiElement element,
                                      final Editor editor,
                                      final Object[] descriptors,
                                      final Project project,
                                      @Nullable Object highlighted,
                                      final int elementStart,
                                      final ParameterInfoHandler handler,
                                      final boolean requestFocus,
                                      boolean singleParameterInfo) {
  if (editor.isDisposed() || !editor.getComponent().isVisible()) return;

  PsiDocumentManager.getInstance(project).performLaterWhenAllCommitted(() -> {
    if (editor.isDisposed() || DumbService.isDumb(project) || !element.isValid() || (!ApplicationManager.getApplication().isUnitTestMode() && !EditorActivityManager.getInstance().isVisible(editor)))
      return;

    final Document document = editor.getDocument();
    if (document.getTextLength() < elementStart) return;

    ParameterInfoController controller = ParameterInfoController.findControllerAtOffset(editor, elementStart);
    if (controller == null) {
      new ParameterInfoController(project, editor, elementStart, descriptors, highlighted, element, handler, true, requestFocus);
    }
    else {
      controller.setDescriptors(descriptors);
      controller.showHint(requestFocus, singleParameterInfo);
    }
  });
}
 
示例2
private static void showLookupEditorHint(Object[] descriptors, final Editor editor, ParameterInfoHandler handler, boolean requestFocus) {
  ParameterInfoComponent component = new ParameterInfoComponent(descriptors, editor, handler, requestFocus, false);
  component.update(false);

  final LightweightHint hint = new LightweightHint(component);
  hint.setSelectingHint(true);
  final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  final Pair<Point, Short> pos = ParameterInfoController.chooseBestHintPosition(editor, null, hint, HintManager.DEFAULT, true);
  ApplicationManager.getApplication().invokeLater(() -> {
    if (!EditorActivityManager.getInstance().isVisible(editor)) return;
    hintManager.showEditorHint(hint, editor, pos.getFirst(), HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_LOOKUP_ITEM_CHANGE | HintManager.UPDATE_BY_SCROLLING, 0, false, pos.getSecond());
  });
}
 
示例3
@Nullable
public static ParameterInfoHandler[] getHandlers(Project project, final Language... languages) {
  Set<ParameterInfoHandler> handlers = new LinkedHashSet<>();
  DumbService dumbService = DumbService.getInstance(project);
  for (final Language language : languages) {
    handlers.addAll(dumbService.filterByDumbAwareness(LanguageParameterInfo.INSTANCE.allForLanguage(language)));
  }
  if (handlers.isEmpty()) return null;
  return handlers.toArray(new ParameterInfoHandler[0]);
}
 
示例4
@TestOnly
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, int currentParameterIndex, @Nullable PsiElement parameterOwner) {
  final ParameterInfoComponent infoComponent = new ParameterInfoComponent(objects, editor, handler);
  infoComponent.setCurrentParameterIndex(currentParameterIndex);
  infoComponent.setParameterOwner(parameterOwner);
  return infoComponent.new MyParameterContext(false);
}
 
示例5
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, boolean requestFocus, boolean allowSwitchLabel) {
  super(new BorderLayout());
  myRequestFocus = requestFocus;

  if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    myWidthLimit = layeredPane.getWidth();
  }

  NORMAL_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.PLAIN) : UIUtil.getLabelFont();
  BOLD_FONT = editor != null && Registry.is("parameter.info.editor.font") ? editor.getColorsScheme().getFont(EditorFontType.BOLD) : NORMAL_FONT.deriveFont(Font.BOLD);

  myObjects = objects;

  setBackground(BACKGROUND);

  myHandler = handler;
  myMainPanel = new JPanel(new GridBagLayout());
  setPanels();

  if (myRequestFocus) {
    AccessibleContextUtil.setName(this, "Parameter Info. Press TAB to navigate through each element. Press ESC to close.");
  }

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myMainPanel, true);
  add(pane, BorderLayout.CENTER);

  myAllowSwitchLabel = allowSwitchLabel && !(editor instanceof EditorWindow);
  setShortcutLabel();
  myCurrentParameterIndex = -1;
}
 
示例6
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {
}
 
示例7
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {}
 
示例8
@Override
public void showHint(PsiElement element, int offset, ParameterInfoHandler handler) {
  final Object[] itemsToShow = getItemsToShow();
  if (itemsToShow == null || itemsToShow.length == 0) return;
  showParameterHint(element, getEditor(), itemsToShow, getProject(), itemsToShow.length > 1 ? getHighlightedElement() : null, offset, handler, myRequestFocus, mySingleParameterInfo);
}
 
示例9
@TestOnly
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, int currentParameterIndex) {
  return createContext(objects, editor, handler, currentParameterIndex, null);
}
 
示例10
ParameterInfoComponent(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler) {
  this(objects, editor, handler, false, false);
}