public Object[] getSelectedElements() { ParameterInfoContext context = new ParameterInfoContext() { @Override public Project getProject() { return myProject; } @Override public PsiFile getFile() { return myComponent.getParameterOwner().getContainingFile(); } @Override public int getOffset() { return myEditor.getCaretModel().getOffset(); } @Override @NotNull public Editor getEditor() { return myEditor; } }; if (!myHandler.tracksParameterIndex()) { return myHandler.getParametersForDocumentation(myComponent.getObjects()[0], context); } final Object[] objects = myComponent.getObjects(); int selectedParameterIndex = myComponent.getCurrentParameterIndex(); List<Object> params = new ArrayList<>(objects.length); final Object highlighted = myComponent.getHighlighted(); for (Object o : objects) { if (highlighted != null && !o.equals(highlighted)) continue; collectParams(context, selectedParameterIndex, params, o); } // choose anything when highlighted is not applicable if (highlighted != null && params.isEmpty()) { for (Object o : objects) { collectParams(context, selectedParameterIndex, params, o); } } return ArrayUtil.toObjectArray(params); }
private void updateComponent() { if (!myHint.isVisible()) { Disposer.dispose(this); return; } final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); CharSequence chars = myEditor.getDocument().getCharsSequence(); boolean noDelimiter = myHandler instanceof ParameterInfoHandlerWithTabActionSupport && ((ParameterInfoHandlerWithTabActionSupport) myHandler) .getActualParameterDelimiterType() == TokenType.WHITE_SPACE; int caretOffset = myEditor.getCaretModel().getOffset(); final int offset = noDelimiter ? caretOffset : CharArrayUtil.shiftBackward(chars, caretOffset - 1, " \t") + 1; final UpdateParameterInfoContext context = new MyUpdateParameterInfoContext(offset, file); final Object elementForUpdating = myHandler.findElementForUpdatingParameterInfo(context); if (elementForUpdating != null) { myHandler.updateParameterInfo(elementForUpdating, context); if (!myDisposed && myHint.isVisible() && !myEditor.isDisposed() && myEditor.getComponent().getRootPane() != null) { myComponent.update(); IdeTooltip tooltip = myHint.getCurrentIdeTooltip(); short position = tooltip != null ? toShort(tooltip.getPreferredPosition()) : HintManager.UNDER; Pair<Point, Short> pos = myProvider.getBestPointPosition( myHint, elementForUpdating instanceof PsiElement ? (PsiElement) elementForUpdating : null, caretOffset, true, position); HintManagerImpl.adjustEditorHintPosition(myHint, myEditor, pos.getFirst(), pos.getSecond()); } } else { context.removeHint(); } }
private void moveToParameterAtOffset(int offset) { PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument()); PsiElement argsList = findArgumentList(file, offset, -1); if (argsList == null) return; myEditor.getCaretModel().moveToOffset(offset); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); myEditor.getSelectionModel().removeSelection(); myHandler.updateParameterInfo(argsList, new MyUpdateParameterInfoContext(offset, file)); }
private void collectParams( ParameterInfoContext context, int selectedParameterIndex, List<Object> params, Object o) { final Object[] availableParams = myHandler.getParametersForDocumentation(o, context); if (availableParams != null && selectedParameterIndex < availableParams.length && selectedParameterIndex >= 0) { params.add(availableParams[selectedParameterIndex]); } }