コード例 #1
0
 private static boolean newExpressionsAreEquivalent(
     @NotNull GrNewExpression newExp1, @NotNull GrNewExpression newExp2) {
   final PsiMethod constructor1 = newExp1.resolveMethod();
   final PsiMethod constructor2 = newExp2.resolveMethod();
   if (constructor1 == null || constructor2 == null || constructor1.equals(constructor2)) {
     return false;
   }
   final GrArgumentList argumentList1 = newExp1.getArgumentList();
   if (argumentList1 == null) {
     return false;
   }
   final GrExpression[] args1 = argumentList1.getExpressionArguments();
   final GrArgumentList argumentList2 = newExp2.getArgumentList();
   if (argumentList2 == null) {
     return false;
   }
   final GrExpression[] args2 = argumentList2.getExpressionArguments();
   return expressionListsAreEquivalent(args1, args2);
 }
  @Override
  public void getNamedArguments(
      @NotNull GrCall call,
      @Nullable PsiElement resolve,
      @Nullable String argumentName,
      boolean forCompletion,
      Map<String, ArgumentDescriptor> result) {
    if (!(call instanceof GrNewExpression)) return;

    if (resolve != null) {
      if (!(resolve instanceof PsiMethod)) return;
      PsiMethod method = (PsiMethod) resolve;
      if (!method.isConstructor()) return;
    }

    GrNewExpression newCall = (GrNewExpression) call;

    GrArgumentList argumentList = newCall.getArgumentList();
    if (argumentList == null) return;

    GrExpression[] expressionArguments = argumentList.getExpressionArguments();
    if (expressionArguments.length > 1
        || (expressionArguments.length == 1
            && !(expressionArguments[0] instanceof GrReferenceExpression))) {
      return;
    }

    for (GroovyResolveResult resolveResult : newCall.multiResolveClass()) {
      PsiElement element = resolveResult.getElement();
      if (!(element instanceof PsiClass)) continue;

      PsiClass aClass = (PsiClass) element;

      if (!isClassHasConstructorWithMap(aClass)) continue;

      PsiClassType classType =
          JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass);

      processClass(call, classType, argumentName, result);
    }
  }