Java 类com.intellij.lang.parameterInfo.CreateParameterInfoContext 实例源码

项目:intellij-ce-playground    文件:ParameterInfoTest.java   
private static String invokeParameterInfo() {
  final MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
  final PsiExpressionList list = handler.findElementForParameterInfo(context);
  assertNotNull(list);
  assertNotNull(context.getItemsToShow());
  assertTrue(context.getItemsToShow().length > 0);
  Object[] params = handler.getParametersForDocumentation(context.getItemsToShow()[0], context);
  assertNotNull(params);
  return StringUtil.join(params, new Function<Object, String>() {
    @Override
    public String fun(Object o) {
      return ((PsiParameter)o).getName();
    }
  }, ",");
}
项目:intellij-ce-playground    文件:ParameterInfoTest.java   
public void testSelectionWithGenerics() throws Exception {
  configureByFile(BASE_PATH + getTestName(false) + ".java");

  final MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
  final PsiExpressionList list = handler.findElementForParameterInfo(context);
  assertNotNull(list);
  final Object[] itemsToShow = context.getItemsToShow();
  assertNotNull(itemsToShow);
  assertEquals(2, itemsToShow.length);
  assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
  final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1);
  final MockUpdateParameterInfoContext updateParameterInfoContext = new MockUpdateParameterInfoContext(myEditor, myFile, itemsToShow);
  updateParameterInfoContext.setParameterOwner(list);
  handler.updateParameterInfo(list, updateParameterInfoContext);
  assertTrue(updateParameterInfoContext.isUIComponentEnabled(0) || updateParameterInfoContext.isUIComponentEnabled(1));
}
项目:intellij-ce-playground    文件:ParameterInfoTest.java   
public void testAfterGenericsInsideCall() throws Exception {
  configureByFile(BASE_PATH + getTestName(false) + ".java");

  final MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
  final PsiExpressionList list = handler.findElementForParameterInfo(context);
  assertNotNull(list);
  final Object[] itemsToShow = context.getItemsToShow();
  assertNotNull(itemsToShow);
  assertEquals(2, itemsToShow.length);
  assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
  final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement();
  final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, 1);
  parameterContext.setUIComponentEnabled(true);
  Assert.assertEquals("<html>Class&lt;T&gt; type, <b>boolean tags</b></html>",
                      MethodParameterInfoHandler
                        .updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext));
}
项目:intellij-ce-playground    文件:ParameterInfoTest.java   
private void doTestPresentation(String expectedString, int currentParameterIndex) {
  configureByFile(BASE_PATH + getTestName(false) + ".java");

  final MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
  final PsiExpressionList list = handler.findElementForParameterInfo(context);
  assertNotNull(list);
  final Object[] itemsToShow = context.getItemsToShow();
  assertNotNull(itemsToShow);
  assertEquals(1, itemsToShow.length);
  assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
  final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement();
  final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler,
                                                                                         currentParameterIndex);
  Assert.assertEquals(expectedString,
                      MethodParameterInfoHandler
                        .updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext));
}
项目:intellij-xquery    文件:XQueryParameterInfoHandlerTest.java   
private void doTest(String text, int highlightedParameterIndex, int shownItems) {
    myFixture.configureByText("a.xq", text);
    final XQueryParameterInfoHandler parameterInfoHandler = new XQueryParameterInfoHandler();
    final CreateParameterInfoContext createContext = new FakeCreateParameterInfoContext(myFixture.getEditor(), myFixture.getFile());
    final XQueryArgumentList list = parameterInfoHandler.findElementForParameterInfo(createContext);

    if (highlightedParameterIndex >= 0) {
        assertNotNull(list);
        parameterInfoHandler.showParameterInfo(list, createContext);
        Object[] itemsToShow = createContext.getItemsToShow();
        assertNotNull(itemsToShow);
        assertEquals(shownItems, itemsToShow.length);
    }
    FakeUpdateParameterInfoContext updateContext = new FakeUpdateParameterInfoContext(myFixture.getEditor(), myFixture.getFile());
    final XQueryArgumentList element = parameterInfoHandler.findElementForUpdatingParameterInfo(updateContext);
    if (element == null) {
        assertEquals(-1, highlightedParameterIndex);
    } else {
        assertNotNull(element);
        parameterInfoHandler.updateParameterInfo(element, updateContext);
        assertEquals(highlightedParameterIndex, updateContext.getCurrentParameter());
    }
}
项目:consulo-apache-velocity    文件:VtlParameterInfoTest.java   
private CreateParameterInfoContext doParamsTest(final int paramIndex, final ParamInfo... expected) throws Throwable
{
    if(myFixture.getFile() == null)
    {
        myFixture.configureByFile(Util.getInputDataFileName(getTestName(true)));
    }
    final VtlParameterInfoHandler handler = new VtlParameterInfoHandler();
    final CreateParameterInfoContext createContext = createCreateParameterInfoContext(myFixture);

    final VtlArgumentList argumentList = assertInstanceOf(handler.findElementForParameterInfo(createContext), VtlArgumentList.class);
    handler.showParameterInfo(argumentList, createContext);

    checkParameterIndex(argumentList, createContext, paramIndex, handler);

    final Object[] items = createContext.getItemsToShow();
    assertNotNull(items);
    assertEquals(expected.length, items.length);
    for(int i = paramIndex; 0 <= i && i < items.length; i++)
    {
        checkParamInfo(argumentList, paramIndex, (VtlCallable) items[i], expected[i], handler);
    }
    return createContext;
}
项目:consulo-apache-velocity    文件:VtlParameterInfoTest.java   
private static void checkParameterIndex(@NotNull final VtlArgumentList argumentList, final CreateParameterInfoContext createContext, final int paramIndex, VtlParameterInfoHandler handler)
{
    throw new UnsupportedOperationException();
    /*TODO

    final UpdateParameterInfoContext updateContext = createMock(UpdateParameterInfoContext.class);

       expect(updateContext.getOffset()).andReturn(createContext.getOffset());
       expect(updateContext.getFile()).andReturn(createContext.getFile());
       expect(updateContext.getEditor()).andReturn(createContext.getEditor());

       expect(updateContext.getParameterOwner()).andReturn(createContext.getHighlightedElement());
       expect(updateContext.getEditor()).andReturn(createContext.getEditor());
       expect(updateContext.getObjectsToView()).andStubReturn(createContext.getItemsToShow());
       updateContext.setParameterOwner(argumentList);
       updateContext.setCurrentParameter(paramIndex);
       replay(updateContext);

       VtlArgumentList foundForUpdating = handler.findElementForUpdatingParameterInfo(updateContext);
       assertSame(argumentList, foundForUpdating);
       handler.updateParameterInfo(foundForUpdating, updateContext);
       verify(updateContext); */
}
项目:intellij-ce-playground    文件:ParameterInfoTest.java   
private static String invokeParameterInfoForAnnotations() {
  final AnnotationParameterInfoHandler handler = new AnnotationParameterInfoHandler();
  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
  final PsiAnnotationParameterList list = handler.findElementForParameterInfo(context);
  assertNotNull(list);
  final Object[] itemsToShow = context.getItemsToShow();
  assertNotNull(itemsToShow);
  assertEquals(1, itemsToShow.length);
  assertTrue(itemsToShow[0] instanceof PsiAnnotationMethod);
  final PsiAnnotationMethod method = (PsiAnnotationMethod)itemsToShow[0];
  final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1);
  return AnnotationParameterInfoHandler.updateUIText(method, parameterContext);
}
项目:consulo-csharp    文件:CSharpParameterInfoHandler.java   
@Nullable
@Override
@RequiredReadAction
public PsiElement findElementForParameterInfo(CreateParameterInfoContext context)
{
    final PsiElement at = context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset());
    return resolveCallArgumentListOwner(at);
}
项目:consulo-csharp    文件:CSharpParameterInfoHandler.java   
@Override
@RequiredReadAction
public void showParameterInfo(@NotNull PsiElement element, CreateParameterInfoContext context)
{
    ItemToShow[] itemsToShow = resolveToCallables(element, context);

    if(itemsToShow.length > 0)
    {
        context.setItemsToShow(itemsToShow);
        context.showHint(element, element.getTextRange().getStartOffset(), this);
    }
}
项目:consulo-csharp    文件:CSharpParameterInfoHandler.java   
@NotNull
@RequiredReadAction
private static ItemToShow[] resolveToCallables(PsiElement element, CreateParameterInfoContext context)
{
    List<ItemToShow> list = new SmartList<>();
    if(element instanceof CSharpCallArgumentListOwner)
    {
        ResolveResult[] resolveResults = ((CSharpCallArgumentListOwner) element).multiResolve(false);

        for(ResolveResult resolveResult : resolveResults)
        {
            CSharpSimpleLikeMethod likeMethod = resolveSimpleMethod(resolveResult, element);
            if(likeMethod != null)
            {
                ItemToShow item = new ItemToShow(likeMethod, element);
                list.add(item);
                if(resolveResult.isValidResult() && context.getHighlightedElement() == null)
                {
                    context.setHighlightedElement(item.valid());
                }
            }
        }
    }

    ContainerUtil.sort(list, (o1, o2) ->
    {
        if(o1.isValid())
        {
            return -1;
        }
        if(o2.isValid())
        {
            return 1;
        }
        return o1.myLikeMethod.getParameterInfos().length - o2.myLikeMethod.getParameterInfos().length;
    });
    return ContainerUtil.toArray(list, ItemToShow.ARRAY_FACTORY);
}
项目:consulo-csharp    文件:CSharpGenericParameterInfoHandler.java   
@Nullable
@Override
public PsiElement findElementForParameterInfo(CreateParameterInfoContext context)
{
    final PsiElement at = context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset());
    return PsiTreeUtil.getParentOfType(at, CSharpReferenceExpression.class);
}
项目:consulo-csharp    文件:CSharpGenericParameterInfoHandler.java   
@Override
public void showParameterInfo(@NotNull PsiElement place, CreateParameterInfoContext context)
{
    DotNetGenericParameterListOwner genericParameterOwner = findGenericParameterOwner(context);
    if(genericParameterOwner == null)
    {
        return;
    }
    context.setItemsToShow(new Object[]{genericParameterOwner});
    context.showHint(place, place.getTextRange().getStartOffset(), this);
}
项目:intellij-xquery    文件:XQueryParameterInfoHandler.java   
@Override
public void showParameterInfo(@NotNull XQueryArgumentList args, CreateParameterInfoContext context) {
    XQueryFunctionCall functionCall = PsiTreeUtil.getParentOfType(args, XQueryFunctionCall.class);
    if (functionCall != null) {
        addItemsToShow(context, functionCall);
        context.showHint(args, args.getTextRange().getStartOffset(), this);
    }
}
项目:intellij-xquery    文件:XQueryParameterInfoHandler.java   
private void addItemsToShow(CreateParameterInfoContext context, XQueryFunctionCall functionCall) {
    ResolveResult[] resolveResults = getFunctionWithAllArities(functionCall);
    List<XQueryFunctionDecl> functionDeclarations = extractFunctionDeclarations(resolveResults);
    if (functionDeclarations.size() > 0) {
        Collections.sort(functionDeclarations, getParameterListSizeComparator());
        context.setItemsToShow(ArrayUtil.toObjectArray(functionDeclarations));
    } else {
        XQueryFile file = (XQueryFile) functionCall.getContainingFile();
        String name = functionCall.getFunctionName().getLocalNameText();
        String prefix = functionCall.getFunctionName().getPrefixText();
        String namespace = file.mapFunctionPrefixToNamespace(prefix);
        context.setItemsToShow(ArrayUtil.toObjectArray(getFunctionsSignatures(file, name, namespace)));
    }
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
@Override
public JSArgumentList findElementForParameterInfo(final CreateParameterInfoContext context)
{
    JSArgumentList argList = findArgumentList(context.getFile(), context.getOffset());

    if(argList != null)
    {
        return fillSignaturesForArgumentList(context, argList);
    }
    return argList;
}
项目:consulo-apache-velocity    文件:VtlParameterInfoHandler.java   
public void showParameterInfo(@NotNull final VtlArgumentList element, final CreateParameterInfoContext context) {
    final PsiElement parent = element.getParent();
    if (!(parent instanceof VtlCallExpression)) {
        return;
    }
    final VtlCallable[] candidates = ((VtlCallExpression) parent).getCallableCandidates();
    if (candidates.length == 0) {
        return;
    }
    context.setItemsToShow(candidates);
    context.showHint(element, element.getTextRange().getStartOffset(), this);
}
项目:consulo-apache-velocity    文件:VtlParameterInfoTest.java   
private static CreateParameterInfoContext createCreateParameterInfoContext(CodeInsightTestFixture fixture)
{
    return new ShowParameterInfoContext(fixture.getEditor(), fixture.getProject(), fixture.getFile(), fixture.getEditor().getCaretModel().getOffset(), 0)
    {
        @Override
        public void showHint(final PsiElement element, final int offset, final ParameterInfoHandler handler)
        {
        }
    };
}
项目:consulo-java    文件:MethodParameterInfoHandler.java   
@Override
@Nullable
public PsiExpressionList findElementForParameterInfo(@NotNull final CreateParameterInfoContext context)
{
    PsiExpressionList argumentList = findArgumentList(context.getFile(), context.getOffset(), context.getParameterListStart());

    if(argumentList != null)
    {
        return findMethodsForArgumentList(context, argumentList);
    }
    return null;
}
项目:consulo-java    文件:MethodParameterInfoHandler.java   
private static PsiExpressionList findMethodsForArgumentList(final CreateParameterInfoContext context, @NotNull final PsiExpressionList argumentList)
{

    CandidateInfo[] candidates = getMethods(argumentList);
    if(candidates.length == 0)
    {
        DaemonCodeAnalyzer.getInstance(context.getProject()).updateVisibleHighlighters(context.getEditor());
        return null;
    }
    context.setItemsToShow(candidates);
    return argumentList;
}
项目:intellij-xquery    文件:XQueryParameterInfoHandler.java   
@Nullable
@Override
public XQueryArgumentList findElementForParameterInfo(CreateParameterInfoContext context) {
    return getArgumentList(context);
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
@Nullable
private static JSArgumentList fillSignaturesForArgumentList(final CreateParameterInfoContext context, final @NotNull JSArgumentList argList)
{
    final PsiElement psiElement = argList.getParent();
    if(!(psiElement instanceof JSCallExpression))
    {
        return null;
    }

    final JSCallExpression parent = (JSCallExpression) psiElement;
    final JSExpression methodExpression = parent.getMethodExpression();

    if(methodExpression instanceof JSReferenceExpression)
    {
        final ResolveResult[] resolveResults = ((JSReferenceExpression) methodExpression).multiResolve(true);

        if(resolveResults.length > 0)
        {
            List<JSFunction> items = new ArrayList<JSFunction>(resolveResults.length);
            Set<String> availableSignatures = new HashSet<String>();

            for(ResolveResult r : resolveResults)
            {
                PsiElement element = r.getElement();
                if(element instanceof JSProperty)
                {
                    element = ((JSProperty) element).getValue();
                }

                doAddSignature(items, availableSignatures, element);
            }

            context.setItemsToShow(ArrayUtil.toObjectArray(items));
            return argList;
        }
    }
    else if(methodExpression instanceof JSSuperExpression)
    {
        final PsiElement clazz = methodExpression.getReference().resolve();
        if(clazz instanceof JSFunction)
        {
            context.setItemsToShow(new Object[]{clazz});
            return argList;
        }
    }
    return null;
}
项目:consulo-javascript    文件:JSParameterInfoHandler.java   
@Override
public void showParameterInfo(@NotNull final JSArgumentList element, final CreateParameterInfoContext context)
{
    context.showHint(element, element.getTextOffset(), this);
}
项目:consulo-apache-velocity    文件:VtlParameterInfoHandler.java   
public VtlArgumentList findElementForParameterInfo(final CreateParameterInfoContext context) {
    return findArgumentList(context);
}
项目:consulo-java    文件:MethodParameterInfoHandler.java   
@Override
public void showParameterInfo(@NotNull final PsiExpressionList element, @NotNull final CreateParameterInfoContext context)
{
    context.showHint(element, element.getTextRange().getStartOffset(), this);
}
项目:intellij-ce-playground    文件:ParameterInfoTest.java   
public void testParameterInfoDoesNotShowInternalJetbrainsAnnotations() throws IOException {
  configureFromFileText("x.java", "class X { void f(@org.intellij.lang.annotations.Flow int i) { f(<caret>0); }}");

  final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);

  PsiMethod method = PsiTreeUtil.getParentOfType(myFile.findElementAt(context.getOffset()), PsiMethod.class);
  final String list = MethodParameterInfoHandler.updateMethodPresentation(method, PsiSubstitutor.EMPTY, new MockParameterInfoUIContext<PsiMethod>(method));

  assertEquals("int i", list);

  PsiAnnotation[] annotations = AnnotationUtil.getAllAnnotations(method.getParameterList().getParameters()[0], false, null);
  assertEquals(1, annotations.length);
}