mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
added Remove call quick fix to the Trying to call a non-callable object inspection
This commit is contained in:
@@ -125,6 +125,8 @@ QFIX.NAME.remove.assignment=Remove assignment
|
||||
|
||||
QFIX.NAME.remove.statement=Remove statement
|
||||
|
||||
QFIX.NAME.remove.call=Remove call
|
||||
|
||||
QFIX.NAME.move.except.up=Move except clause up
|
||||
|
||||
QFIX.NAME.remove.dict.key=Remove this key
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.inspections.quickfix.PyRemoveCallQuickFix;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.types.PyClassType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
@@ -78,13 +79,13 @@ public class PyCallingNonCallableInspection extends PyInspection {
|
||||
if (!callable) {
|
||||
final PyType calleeType = callee != null ? myTypeEvalContext.getType(callee) : type;
|
||||
if (calleeType instanceof PyClassType) {
|
||||
registerProblem(node, String.format("'%s' object is not callable", calleeType.getName()));
|
||||
registerProblem(node, String.format("'%s' object is not callable", calleeType.getName()), new PyRemoveCallQuickFix());
|
||||
}
|
||||
else if (callee != null) {
|
||||
registerProblem(node, String.format("'%s' is not callable", callee.getName()));
|
||||
registerProblem(node, String.format("'%s' is not callable", callee.getName()), new PyRemoveCallQuickFix());
|
||||
}
|
||||
else {
|
||||
registerProblem(node, "Expression is not callable");
|
||||
registerProblem(node, "Expression is not callable", new PyRemoveCallQuickFix());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.inspections.quickfix;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.PyArgumentList;
|
||||
import com.jetbrains.python.psi.PyCallExpression;
|
||||
import com.jetbrains.python.psi.PyDecorator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PyRemoveCallQuickFix implements LocalQuickFix {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return PyBundle.message("QFIX.NAME.remove.call");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement call = descriptor.getPsiElement();
|
||||
assert call instanceof PyCallExpression;
|
||||
if (call instanceof PyDecorator) {
|
||||
call.delete();
|
||||
}
|
||||
else {
|
||||
final PyArgumentList argumentList = ((PyCallExpression)call).getArgumentList();
|
||||
assert argumentList != null;
|
||||
argumentList.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class A():
|
||||
x = ""
|
||||
|
||||
|
||||
b = <warning descr="'str' object is not callable">A().<caret>x()</warning>
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
class A():
|
||||
x = ""
|
||||
|
||||
|
||||
b = A().x
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
a = ""
|
||||
|
||||
def b(c):
|
||||
pass
|
||||
|
||||
|
||||
<warning descr="'str' object is not callable">@<caret>a</warning>
|
||||
@b
|
||||
def foo():
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
a = ""
|
||||
|
||||
def b(c):
|
||||
pass
|
||||
|
||||
|
||||
@b
|
||||
def foo():
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
a = "string"
|
||||
|
||||
b = <warning descr="'str' object is not callable">a<caret>()</warning>
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
a = "string"
|
||||
|
||||
b = a
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.quickFixes;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.PyQuickFixTestCase;
|
||||
import com.jetbrains.python.inspections.PyCallingNonCallableInspection;
|
||||
|
||||
@TestDataPath("$CONTENT_ROOT/../testData/quickFixes/PyRemoveCallQuickFixTest/")
|
||||
public class PyRemoveCallQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testExpression() {
|
||||
doQuickFixTest(PyCallingNonCallableInspection.class, PyBundle.message("QFIX.NAME.remove.call"));
|
||||
}
|
||||
|
||||
public void testDecorator() {
|
||||
doQuickFixTest(PyCallingNonCallableInspection.class, PyBundle.message("QFIX.NAME.remove.call"));
|
||||
}
|
||||
|
||||
public void testClass() {
|
||||
doQuickFixTest(PyCallingNonCallableInspection.class, PyBundle.message("QFIX.NAME.remove.call"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user