private static void highlightIncorrectArguments( ProblemsHolder holder, CallArgumentsMapping result, @NotNull TypeEvalContext context) { for (Map.Entry<PyExpression, EnumSet<CallArgumentsMapping.ArgFlag>> argEntry : result.getArgumentFlags().entrySet()) { EnumSet<CallArgumentsMapping.ArgFlag> flags = argEntry.getValue(); if (!flags.isEmpty()) { // something's wrong PyExpression arg = argEntry.getKey(); if (flags.contains(CallArgumentsMapping.ArgFlag.IS_DUP)) { holder.registerProblem(arg, PyBundle.message("INSP.duplicate.argument")); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_DUP_KWD)) { holder.registerProblem(arg, PyBundle.message("INSP.duplicate.doublestar.arg")); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_DUP_TUPLE)) { holder.registerProblem(arg, PyBundle.message("INSP.duplicate.star.arg")); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_POS_PAST_KWD)) { holder.registerProblem( arg, PyBundle.message("INSP.cannot.appear.past.keyword.arg"), ProblemHighlightType.ERROR); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_UNMAPPED)) { holder.registerProblem(arg, PyBundle.message("INSP.unexpected.arg")); } if (flags.contains(CallArgumentsMapping.ArgFlag.IS_TOO_LONG)) { final PyCallExpression.PyMarkedCallee markedCallee = result.getMarkedCallee(); String parameterName = null; if (markedCallee != null) { final List<PyParameter> parameters = PyUtil.getParameters(markedCallee.getCallable(), context); for (int i = parameters.size() - 1; i >= 0; --i) { final PyParameter param = parameters.get(i); if (param instanceof PyNamedParameter) { final List<PyNamedParameter> unmappedParams = result.getUnmappedParams(); if (!((PyNamedParameter) param).isPositionalContainer() && !((PyNamedParameter) param).isKeywordContainer() && param.getDefaultValue() == null && !unmappedParams.contains(param)) { parameterName = param.getName(); break; } } } holder.registerProblem( arg, parameterName != null ? PyBundle.message( "INSP.multiple.values.resolve.to.positional.$0", parameterName) : PyBundle.message("INSP.more.args.that.pos.params")); } } } } }
@NotNull private static String buildDisplayMethodName(@NotNull final PyFunction pyFunction) { final StringBuilder builder = new StringBuilder(pyFunction.getName()); builder.append('('); final PyParameter[] arguments = pyFunction.getParameterList().getParameters(); for (final PyParameter parameter : arguments) { builder.append(parameter.getName()); if (arguments.length > 1 && parameter != arguments[arguments.length - 1]) { builder.append(", "); } } builder.append(')'); return builder.toString(); }