Search in sources :

Example 1 with MethodParameterInfoHandler

use of com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler in project intellij-community by JetBrains.

the class ParameterInfoTest method testStopAtAccessibleStaticCorrectCandidate.

public void testStopAtAccessibleStaticCorrectCandidate() {
    myFixture.configureByFile(getTestName(false) + ".java");
    MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
    CreateParameterInfoContext context = new MockCreateParameterInfoContext(getEditor(), getFile());
    PsiExpressionList list = handler.findElementForParameterInfo(context);
    assertNotNull(list);
    Object[] itemsToShow = context.getItemsToShow();
    assertNotNull(itemsToShow);
    assertEquals(1, itemsToShow.length);
    assertEquals(0, ((MethodCandidateInfo) itemsToShow[0]).getElement().getParameterList().getParametersCount());
}
Also used : CreateParameterInfoContext(com.intellij.lang.parameterInfo.CreateParameterInfoContext) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext) MethodParameterInfoHandler(com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext)

Example 2 with MethodParameterInfoHandler

use of com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler in project intellij-community by JetBrains.

the class ParameterInfoTest method doTest2CandidatesWithPreselection.

private void doTest2CandidatesWithPreselection() {
    myFixture.configureByFile(getTestName(false) + ".java");
    MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
    CreateParameterInfoContext context = new MockCreateParameterInfoContext(getEditor(), getFile());
    PsiExpressionList list = handler.findElementForParameterInfo(context);
    assertNotNull(list);
    Object[] itemsToShow = context.getItemsToShow();
    assertNotNull(itemsToShow);
    assertEquals(2, itemsToShow.length);
    assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
    ParameterInfoComponent.createContext(itemsToShow, getEditor(), handler, -1);
    MockUpdateParameterInfoContext updateParameterInfoContext = updateParameterInfo(handler, list, itemsToShow);
    assertTrue(updateParameterInfoContext.isUIComponentEnabled(0) || updateParameterInfoContext.isUIComponentEnabled(1));
}
Also used : MockUpdateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockUpdateParameterInfoContext) CreateParameterInfoContext(com.intellij.lang.parameterInfo.CreateParameterInfoContext) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) MethodParameterInfoHandler(com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext)

Example 3 with MethodParameterInfoHandler

use of com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler in project intellij-community by JetBrains.

the class JavaMethodCallElement method showParameterHints.

public static void showParameterHints(InsertionContext context, PsiMethod method, PsiCallExpression methodCall) {
    PsiParameterList parameterList = method.getParameterList();
    int parametersCount = parameterList.getParametersCount();
    if (methodCall == null || parametersCount == 0 || context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR || Registry.is("java.completion.argument.live.template") || !Registry.is("java.completion.argument.hints")) {
        return;
    }
    Editor editor = context.getEditor();
    CaretModel caretModel = editor.getCaretModel();
    int offset = caretModel.getOffset();
    // avoid caret impact on hints location
    caretModel.moveToOffset(offset - 1);
    editor.getDocument().insertString(offset, StringUtil.repeat(", ", parametersCount - 1));
    List<Inlay> addedHints = new ArrayList<>(parametersCount);
    for (PsiParameter parameter : parameterList.getParameters()) {
        String name = parameter.getName();
        if (name != null) {
            addedHints.add(ParameterHintsPresentationManager.getInstance().addHint(editor, offset, name + ":", false, true));
        }
        offset += 2;
    }
    int braceOffset = caretModel.getOffset();
    caretModel.moveToLogicalPosition(editor.offsetToLogicalPosition(braceOffset + 1).leanForward(true));
    Project project = context.getProject();
    MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
    ShowParameterInfoContext infoContext = new ShowParameterInfoContext(editor, project, context.getFile(), braceOffset, braceOffset);
    handler.findElementForParameterInfo(infoContext);
    Disposer.register(new ParameterInfoController(project, editor, braceOffset, infoContext.getItemsToShow(), null, methodCall.getArgumentList(), handler, false, false), () -> {
        for (Inlay inlay : addedHints) {
            if (inlay != null)
                ParameterHintsPresentationManager.getInstance().unpin(inlay);
        }
    });
}
Also used : CaretModel(com.intellij.openapi.editor.CaretModel) Inlay(com.intellij.openapi.editor.Inlay) ArrayList(java.util.ArrayList) ParameterInfoController(com.intellij.codeInsight.hint.ParameterInfoController) Project(com.intellij.openapi.project.Project) MethodParameterInfoHandler(com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler) Editor(com.intellij.openapi.editor.Editor) ShowParameterInfoContext(com.intellij.codeInsight.hint.ShowParameterInfoContext)

Example 4 with MethodParameterInfoHandler

use of com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler in project intellij-community by JetBrains.

the class ParameterInfoTest method checkHighlighted.

private void checkHighlighted(int lineIndex) {
    MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
    CreateParameterInfoContext context = createContext();
    PsiExpressionList list = handler.findElementForParameterInfo(context);
    Object[] itemsToShow = context.getItemsToShow();
    assertEquals(itemsToShow[lineIndex], updateParameterInfo(handler, list, itemsToShow).getHighlightedParameter());
}
Also used : CreateParameterInfoContext(com.intellij.lang.parameterInfo.CreateParameterInfoContext) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext) MethodParameterInfoHandler(com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler)

Example 5 with MethodParameterInfoHandler

use of com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler in project intellij-community by JetBrains.

the class ParameterInfoTest method testAfterGenericsInsideCall.

public void testAfterGenericsInsideCall() {
    myFixture.configureByFile(getTestName(false) + ".java");
    MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
    CreateParameterInfoContext context = new MockCreateParameterInfoContext(getEditor(), getFile());
    PsiExpressionList list = handler.findElementForParameterInfo(context);
    assertNotNull(list);
    Object[] itemsToShow = context.getItemsToShow();
    assertNotNull(itemsToShow);
    assertEquals(2, itemsToShow.length);
    assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
    PsiMethod method = ((MethodCandidateInfo) itemsToShow[0]).getElement();
    ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, getEditor(), handler, 1);
    parameterContext.setUIComponentEnabled(true);
    PsiSubstitutor substitutor = ((MethodCandidateInfo) itemsToShow[0]).getSubstitutor();
    String presentation = MethodParameterInfoHandler.updateMethodPresentation(method, substitutor, parameterContext);
    assertEquals("<html>Class&lt;T&gt; type, <b>boolean tags</b></html>", presentation);
}
Also used : CreateParameterInfoContext(com.intellij.lang.parameterInfo.CreateParameterInfoContext) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext) MethodCandidateInfo(com.intellij.psi.infos.MethodCandidateInfo) MethodParameterInfoHandler(com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler) ParameterInfoUIContextEx(com.intellij.lang.parameterInfo.ParameterInfoUIContextEx) MockCreateParameterInfoContext(com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext)

Aggregations

MethodParameterInfoHandler (com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler)7 CreateParameterInfoContext (com.intellij.lang.parameterInfo.CreateParameterInfoContext)6 MockCreateParameterInfoContext (com.intellij.testFramework.utils.parameterInfo.MockCreateParameterInfoContext)6 MethodCandidateInfo (com.intellij.psi.infos.MethodCandidateInfo)3 ParameterInfoUIContextEx (com.intellij.lang.parameterInfo.ParameterInfoUIContextEx)2 ParameterInfoController (com.intellij.codeInsight.hint.ParameterInfoController)1 ShowParameterInfoContext (com.intellij.codeInsight.hint.ShowParameterInfoContext)1 CaretModel (com.intellij.openapi.editor.CaretModel)1 Editor (com.intellij.openapi.editor.Editor)1 Inlay (com.intellij.openapi.editor.Inlay)1 Project (com.intellij.openapi.project.Project)1 MockUpdateParameterInfoContext (com.intellij.testFramework.utils.parameterInfo.MockUpdateParameterInfoContext)1 ArrayList (java.util.ArrayList)1