Search in sources :

Example 1 with PyRenameArgumentQuickFix

use of com.jetbrains.python.inspections.quickfix.PyRenameArgumentQuickFix in project intellij-community by JetBrains.

the class PyArgumentListInspection method highlightUnexpectedArguments.

private static void highlightUnexpectedArguments(@NotNull PyArgumentList node, @NotNull ProblemsHolder holder, @NotNull List<PyCallExpression.PyArgumentsMapping> mappings, @NotNull TypeEvalContext context) {
    if (mappings.isEmpty() || mappings.stream().anyMatch(mapping -> mapping.getUnmappedArguments().isEmpty()))
        return;
    if (mappings.size() == 1) {
        // if there is only one mapping, we could suggest quick fixes
        final Set<String> duplicateKeywords = getDuplicateKeywordArguments(node);
        for (PyExpression argument : mappings.get(0).getUnmappedArguments()) {
            final List<LocalQuickFix> quickFixes = Lists.newArrayList(new PyRemoveArgumentQuickFix());
            if (argument instanceof PyKeywordArgument) {
                if (duplicateKeywords.contains(((PyKeywordArgument) argument).getKeyword())) {
                    continue;
                }
                quickFixes.add(new PyRenameArgumentQuickFix());
            }
            holder.registerProblem(argument, PyBundle.message("INSP.unexpected.arg"), quickFixes.toArray(new LocalQuickFix[quickFixes.size() - 1]));
        }
    } else {
        // all mappings have unmapped arguments so we couldn't determine desired argument list and suggest appropriate quick fixes
        holder.registerProblem(node, addPossibleCalleesRepresentationAndWrapInHtml(PyBundle.message("INSP.unexpected.arg(s)"), mappings, context));
    }
}
Also used : TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext) PyNames(com.jetbrains.python.PyNames) java.util(java.util) LocalInspectionToolSession(com.intellij.codeInspection.LocalInspectionToolSession) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Lists(com.google.common.collect.Lists) Nls(org.jetbrains.annotations.Nls) com.jetbrains.python.psi(com.jetbrains.python.psi) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) PyBundle(com.jetbrains.python.PyBundle) PyTypeChecker(com.jetbrains.python.psi.types.PyTypeChecker) PyType(com.jetbrains.python.psi.types.PyType) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) PyTokenTypes(com.jetbrains.python.PyTokenTypes) PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PyRemoveArgumentQuickFix(com.jetbrains.python.inspections.quickfix.PyRemoveArgumentQuickFix) Collectors(java.util.stream.Collectors) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ResolveResult(com.intellij.psi.ResolveResult) PyRenameArgumentQuickFix(com.jetbrains.python.inspections.quickfix.PyRenameArgumentQuickFix) PyABCUtil(com.jetbrains.python.psi.types.PyABCUtil) StreamEx(one.util.streamex.StreamEx) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) NotNull(org.jetbrains.annotations.NotNull) PyRenameArgumentQuickFix(com.jetbrains.python.inspections.quickfix.PyRenameArgumentQuickFix) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PyRemoveArgumentQuickFix(com.jetbrains.python.inspections.quickfix.PyRemoveArgumentQuickFix)

Aggregations

Lists (com.google.common.collect.Lists)1 LocalInspectionToolSession (com.intellij.codeInspection.LocalInspectionToolSession)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 ASTNode (com.intellij.lang.ASTNode)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)1 ResolveResult (com.intellij.psi.ResolveResult)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 XmlStringUtil (com.intellij.xml.util.XmlStringUtil)1 PyBundle (com.jetbrains.python.PyBundle)1 PyNames (com.jetbrains.python.PyNames)1 PyTokenTypes (com.jetbrains.python.PyTokenTypes)1 PyRemoveArgumentQuickFix (com.jetbrains.python.inspections.quickfix.PyRemoveArgumentQuickFix)1 PyRenameArgumentQuickFix (com.jetbrains.python.inspections.quickfix.PyRenameArgumentQuickFix)1 com.jetbrains.python.psi (com.jetbrains.python.psi)1 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)1 PyABCUtil (com.jetbrains.python.psi.types.PyABCUtil)1 PyType (com.jetbrains.python.psi.types.PyType)1 PyTypeChecker (com.jetbrains.python.psi.types.PyTypeChecker)1