public void showParameterInfo(@NotNull PsiElement element, CreateParameterInfoContext context) {
   ResolveResult[] variants = ResolveResult.EMPTY_ARRAY;
   if (element instanceof PsiPolyVariantReference) {
     variants = ((PsiPolyVariantReference) element).multiResolve(true);
     if (variants.length != 0) {
       context.setItemsToShow(
           ContainerUtil.map2Array(
               variants,
               CfmlFunctionDescription.class,
               new Function<ResolveResult, CfmlFunctionDescription>() {
                 public CfmlFunctionDescription fun(ResolveResult resolveResult) {
                   final PsiElement element1 = resolveResult.getElement();
                   if (CfmlPsiUtil.isFunctionDefinition(element1)) {
                     CfmlFunction function = CfmlPsiUtil.getFunctionDefinition(element1);
                     if (function != null) {
                       return function.getFunctionInfo();
                     }
                   } else if (element1 instanceof PsiMethod) {
                     PsiMethod function = (PsiMethod) element1;
                     CfmlFunctionDescription javaMethodDescr =
                         new CfmlFunctionDescription(
                             function.getName(), function.getReturnType().getPresentableText());
                     final PsiParameter[] psiParameters =
                         function.getParameterList().getParameters();
                     final int paramsNum = psiParameters.length;
                     for (int i = 0; i < paramsNum; i++) {
                       PsiParameter psiParameter = psiParameters[i];
                       javaMethodDescr.addParameter(
                           new CfmlFunctionDescription.CfmlParameterDescription(
                               psiParameter.getName(),
                               psiParameter.getType().getPresentableText(),
                               true));
                     }
                     return javaMethodDescr;
                   }
                   return null;
                 }
               }));
       context.showHint(element, element.getTextRange().getStartOffset(), this);
       return;
     }
   }
   if (element instanceof CfmlReferenceExpression) {
     String functionName = element.getText().toLowerCase();
     if (ArrayUtil.find(
             CfmlLangInfo.getInstance(element.getProject()).getPredefinedFunctionsLowCase(),
             functionName)
         != -1) {
       context.setItemsToShow(
           new Object[] {
             CfmlLangInfo.getInstance(element.getProject())
                 .getFunctionParameters()
                 .get(functionName)
           });
       context.showHint(element, element.getTextRange().getStartOffset(), this);
     }
   }
 }
 @Override
 public PsiElement findElementForParameterInfo(CreateParameterInfoContext context) {
   final PsiElement at =
       context.getFile().findElementAt(context.getEditor().getCaretModel().getOffset());
   final DartArguments arguments = PsiTreeUtil.getParentOfType(at, DartArguments.class);
   return arguments == null
       ? null
       : PsiTreeUtil.getParentOfType(arguments, DartCallExpression.class, DartNewExpression.class);
 }
  @Override
  public void showParameterInfo(@NotNull PsiElement element, CreateParameterInfoContext context) {
    DartFunctionDescription functionDescription = null;
    if (element instanceof DartCallExpression) {
      functionDescription = DartFunctionDescription.tryGetDescription((DartCallExpression) element);
    } else if (element instanceof DartNewExpression) {
      final DartNewExpression newExpression = (DartNewExpression) element;
      final DartType type = newExpression.getType();
      final DartClassResolveResult classResolveResult = DartResolveUtil.resolveClassByType(type);
      PsiElement psiElement = ((DartNewExpression) element).getReferenceExpression();
      psiElement = psiElement == null && type != null ? type.getReferenceExpression() : psiElement;
      final PsiElement target = psiElement != null ? ((DartReference) psiElement).resolve() : null;
      if (target instanceof DartComponentName) {
        functionDescription =
            DartFunctionDescription.createDescription(
                (DartComponent) target.getParent(), classResolveResult);
      }
    }

    if (functionDescription != null && functionDescription.getParameters().length > 0) {
      context.setItemsToShow(new Object[] {functionDescription});
      context.showHint(element, element.getTextRange().getStartOffset(), this);
    }
  }
  private static JetValueArgumentList findCall(CreateParameterInfoContext context) {
    // todo: calls to this constructors, when we will have auxiliary constructors
    PsiFile file = context.getFile();
    if (!(file instanceof JetFile)) {
      return null;
    }

    JetValueArgumentList argumentList =
        PsiTreeUtil.getParentOfType(
            file.findElementAt(context.getOffset()), JetValueArgumentList.class);
    if (argumentList == null) {
      return null;
    }

    final JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
    if (callNameExpression == null) {
      return null;
    }

    PsiReference[] references = callNameExpression.getReferences();
    if (references.length == 0) {
      return null;
    }

    ResolutionFacade resolutionFacade =
        ResolvePackage.getResolutionFacade(callNameExpression.getContainingJetFile());
    final BindingContext bindingContext =
        resolutionFacade.analyze(callNameExpression, BodyResolveMode.FULL);
    ModuleDescriptor moduleDescriptor = resolutionFacade.findModuleDescriptor(callNameExpression);

    JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression);
    final DeclarationDescriptor placeDescriptor;
    if (scope != null) {
      placeDescriptor = scope.getContainingDeclaration();
    } else {
      placeDescriptor = null;
    }
    Function1<DeclarationDescriptor, Boolean> visibilityFilter =
        new Function1<DeclarationDescriptor, Boolean>() {
          @Override
          public Boolean invoke(DeclarationDescriptor descriptor) {
            if (placeDescriptor == null) return true;
            if (!(descriptor instanceof DeclarationDescriptorWithVisibility)) return true;
            return CorePackage.isVisible(
                (DeclarationDescriptorWithVisibility) descriptor,
                placeDescriptor,
                bindingContext,
                callNameExpression);
          }
        };

    final Name refName = callNameExpression.getReferencedNameAsName();

    Function1<Name, Boolean> nameFilter =
        new Function1<Name, Boolean>() {
          @Override
          public Boolean invoke(Name name) {
            return name.equals(refName);
          }
        };
    Collection<DeclarationDescriptor> variants =
        new ReferenceVariantsHelper(
                bindingContext, moduleDescriptor, file.getProject(), visibilityFilter)
            .getReferenceVariants(
                callNameExpression,
                new DescriptorKindFilter(
                    DescriptorKindFilter.FUNCTIONS_MASK | DescriptorKindFilter.CLASSIFIERS_MASK,
                    Collections.<DescriptorKindExclude>emptyList()),
                nameFilter,
                false,
                false);

    Collection<Pair<? extends DeclarationDescriptor, ResolutionFacade>> itemsToShow =
        new ArrayList<Pair<? extends DeclarationDescriptor, ResolutionFacade>>();
    for (DeclarationDescriptor variant : variants) {
      if (variant instanceof FunctionDescriptor) {
        // todo: renamed functions?
        itemsToShow.add(Pair.create((FunctionDescriptor) variant, resolutionFacade));
      } else if (variant instanceof ClassDescriptor) {
        // todo: renamed classes?
        for (ConstructorDescriptor constructorDescriptor :
            ((ClassDescriptor) variant).getConstructors()) {
          itemsToShow.add(Pair.create(constructorDescriptor, resolutionFacade));
        }
      }
    }

    context.setItemsToShow(ArrayUtil.toObjectArray(itemsToShow));
    return argumentList;
  }
 @Override
 public void showParameterInfo(
     @NotNull JetValueArgumentList element, @NotNull CreateParameterInfoContext context) {
   context.showHint(element, element.getTextRange().getStartOffset(), this);
 }
 private static JetValueArgumentList findCall(CreateParameterInfoContext context) {
   // todo: calls to this constructors, when we will have auxiliary constructors
   PsiFile file = context.getFile();
   if (!(file instanceof JetFile)) return null;
   PsiElement element = file.findElementAt(context.getOffset());
   while (element != null && !(element instanceof JetValueArgumentList)) {
     element = element.getParent();
   }
   if (element == null) return null;
   JetValueArgumentList argumentList = (JetValueArgumentList) element;
   JetCallElement callExpression;
   if (element.getParent() instanceof JetCallElement) {
     callExpression = (JetCallElement) element.getParent();
   } else {
     return null;
   }
   BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile((JetFile) file);
   JetExpression calleeExpression = callExpression.getCalleeExpression();
   if (calleeExpression == null) return null;
   JetSimpleNameExpression refExpression = null;
   if (calleeExpression instanceof JetSimpleNameExpression) {
     refExpression = (JetSimpleNameExpression) calleeExpression;
   } else if (calleeExpression instanceof JetConstructorCalleeExpression) {
     JetConstructorCalleeExpression constructorCalleeExpression =
         (JetConstructorCalleeExpression) calleeExpression;
     if (constructorCalleeExpression.getConstructorReferenceExpression()
         instanceof JetSimpleNameExpression) {
       refExpression =
           (JetSimpleNameExpression)
               constructorCalleeExpression.getConstructorReferenceExpression();
     }
   }
   if (refExpression != null) {
     JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, refExpression);
     DeclarationDescriptor placeDescriptor = null;
     if (scope != null) {
       placeDescriptor = scope.getContainingDeclaration();
     }
     Collection<DeclarationDescriptor> variants =
         TipsManager.getReferenceVariants(refExpression, bindingContext);
     Name refName = refExpression.getReferencedNameAsName();
     PsiReference[] references = refExpression.getReferences();
     if (references.length == 0) return null;
     ArrayList<DeclarationDescriptor> itemsToShow = new ArrayList<DeclarationDescriptor>();
     for (DeclarationDescriptor variant : variants) {
       if (variant instanceof FunctionDescriptor) {
         FunctionDescriptor functionDescriptor = (FunctionDescriptor) variant;
         if (functionDescriptor.getName().equals(refName)) {
           // todo: renamed functions?
           if (placeDescriptor != null
               && !JetVisibilityChecker.isVisible(placeDescriptor, functionDescriptor)) continue;
           itemsToShow.add(functionDescriptor);
         }
       } else if (variant instanceof ClassDescriptor) {
         ClassDescriptor classDescriptor = (ClassDescriptor) variant;
         if (classDescriptor.getName().equals(refName)) {
           // todo: renamed classes?
           for (ConstructorDescriptor constructorDescriptor : classDescriptor.getConstructors()) {
             if (placeDescriptor != null
                 && !JetVisibilityChecker.isVisible(placeDescriptor, constructorDescriptor))
               continue;
             itemsToShow.add(constructorDescriptor);
           }
         }
       }
     }
     context.setItemsToShow(ArrayUtil.toObjectArray(itemsToShow));
     return argumentList;
   }
   return null;
 }
  private static JetValueArgumentList findCall(CreateParameterInfoContext context) {
    // todo: calls to this constructors, when we will have auxiliary constructors
    PsiFile file = context.getFile();
    if (!(file instanceof JetFile)) {
      return null;
    }

    JetValueArgumentList argumentList =
        PsiTreeUtil.getParentOfType(
            file.findElementAt(context.getOffset()), JetValueArgumentList.class);
    if (argumentList == null) {
      return null;
    }

    JetSimpleNameExpression callNameExpression = getCallSimpleNameExpression(argumentList);
    if (callNameExpression == null) {
      return null;
    }

    PsiReference[] references = callNameExpression.getReferences();
    if (references.length == 0) {
      return null;
    }

    CancelableResolveSession resolveSession =
        WholeProjectAnalyzerFacade.getLazyResolveResultForFile(
            (JetFile) callNameExpression.getContainingFile());
    BindingContext bindingContext = resolveSession.resolveToElement(callNameExpression);

    JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression);
    DeclarationDescriptor placeDescriptor = null;
    if (scope != null) {
      placeDescriptor = scope.getContainingDeclaration();
    }

    Collection<DeclarationDescriptor> variants =
        TipsManager.getReferenceVariants(callNameExpression, bindingContext);

    Name refName = callNameExpression.getReferencedNameAsName();

    Collection<Pair<? extends DeclarationDescriptor, CancelableResolveSession>> itemsToShow =
        new ArrayList<Pair<? extends DeclarationDescriptor, CancelableResolveSession>>();
    for (DeclarationDescriptor variant : variants) {
      if (variant instanceof FunctionDescriptor) {
        FunctionDescriptor functionDescriptor = (FunctionDescriptor) variant;
        if (functionDescriptor.getName().equals(refName)) {
          // todo: renamed functions?
          if (placeDescriptor != null
              && !JetVisibilityChecker.isVisible(placeDescriptor, functionDescriptor)) {
            continue;
          }
          itemsToShow.add(Pair.create(functionDescriptor, resolveSession));
        }
      } else if (variant instanceof ClassDescriptor) {
        ClassDescriptor classDescriptor = (ClassDescriptor) variant;
        if (classDescriptor.getName().equals(refName)) {
          // todo: renamed classes?
          for (ConstructorDescriptor constructorDescriptor : classDescriptor.getConstructors()) {
            if (placeDescriptor != null
                && !JetVisibilityChecker.isVisible(placeDescriptor, constructorDescriptor)) {
              continue;
            }
            itemsToShow.add(Pair.create(constructorDescriptor, resolveSession));
          }
        }
      }
    }

    context.setItemsToShow(ArrayUtil.toObjectArray(itemsToShow));
    return argumentList;
  }
 public PsiElement findElementForParameterInfo(CreateParameterInfoContext context) {
   return findAnchorElement(context.getEditor().getCaretModel().getOffset(), context.getFile());
 }