public static boolean hasClosureArguments(@Nullable GrCall call) { if (call == null) return false; for (PsiElement child = call.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof GrClosableBlock) return true; } return false; }
public static void removeParamsFromUnresolvedCall( GrCall callExpression, PsiParameter[] parameters, TIntArrayList parametersToRemove) { final GrExpression[] arguments = callExpression.getExpressionArguments(); final GrClosableBlock[] closureArguments = callExpression.getClosureArguments(); final GrNamedArgument[] namedArguments = callExpression.getNamedArguments(); final boolean hasNamedArgs; if (namedArguments.length > 0) { if (parameters.length > 0) { final PsiType type = parameters[0].getType(); hasNamedArgs = InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP); } else { hasNamedArgs = false; } } else { hasNamedArgs = false; } parametersToRemove.forEachDescending( new TIntProcedure() { public boolean execute(int paramNum) { try { if (paramNum == 0 && hasNamedArgs) { for (GrNamedArgument namedArgument : namedArguments) { namedArgument.delete(); } } else { if (hasNamedArgs) paramNum--; if (paramNum < arguments.length) { arguments[paramNum].delete(); } else if (paramNum < arguments.length + closureArguments.length) { closureArguments[paramNum - arguments.length].delete(); } } } catch (IncorrectOperationException e) { LOG.error(e); } return true; } }); }
private static boolean resolvesToDefaultConstructor(GrCall call) { PsiMethod method = call.resolveMethod(); if (method != null && method.isConstructor() && method.getParameterList().getParametersCount() == 0) return true; if (call instanceof GrConstructorCall) { PsiElement resolved = PsiImplUtil.extractUniqueResult(((GrConstructorCall) call).multiResolveClass()) .getElement(); if (resolved instanceof PsiClass) return true; } return false; }