mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
added rename quick fix to the protected member inspection
This commit is contained in:
@@ -96,10 +96,8 @@ public class PyProtectedMemberInspection extends PyInspection {
|
||||
}
|
||||
}
|
||||
final PyType type = myTypeEvalContext.getType(qualifier);
|
||||
if (type instanceof PyModuleType)
|
||||
registerProblem(node, PyBundle.message("INSP.protected.member.$0.access.module", name));
|
||||
else
|
||||
registerProblem(node, PyBundle.message("INSP.protected.member.$0.access", name));
|
||||
final String bundle_key = type instanceof PyModuleType ? "INSP.protected.member.$0.access.module" : "INSP.protected.member.$0.access";
|
||||
registerProblem(node, PyBundle.message(bundle_key, name), new PyRenameElementQuickFix());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.PsiSearchHelper;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
@@ -35,6 +36,7 @@ import com.intellij.refactoring.rename.RenamePsiElementProcessor;
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
|
||||
import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
|
||||
import com.jetbrains.python.psi.PyNamedParameter;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyTargetExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -57,7 +59,12 @@ public class PyRenameElementQuickFix implements LocalQuickFix {
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
if (element instanceof PyReferenceExpression) {
|
||||
final PsiReference reference = element.getReference();
|
||||
if (reference == null) return;
|
||||
element = reference.resolve();
|
||||
}
|
||||
final PsiNameIdentifierOwner nameOwner = element instanceof PsiNameIdentifierOwner ?
|
||||
(PsiNameIdentifierOwner)element :
|
||||
PsiTreeUtil.getParentOfType(element, PsiNameIdentifierOwner.class, true);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
A<caret>BC = "test"
|
||||
@@ -0,0 +1,2 @@
|
||||
class a_<caret>b:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
class a:
|
||||
pass
|
||||
@@ -0,0 +1 @@
|
||||
def Fo<caret>o(): pass
|
||||
@@ -0,0 +1 @@
|
||||
def a(): pass
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
a = "test"
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
class A:
|
||||
def __init__(self):
|
||||
self._x = 1
|
||||
|
||||
def _foo(self):
|
||||
pass
|
||||
|
||||
|
||||
a_class = A()
|
||||
a_class._foo()
|
||||
print(a_class._<caret>x)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
class A:
|
||||
def __init__(self):
|
||||
self.a = 1
|
||||
|
||||
def _foo(self):
|
||||
pass
|
||||
|
||||
|
||||
a_class = A()
|
||||
a_class._foo()
|
||||
print(a_class.a)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
l<caret>en = 10
|
||||
@@ -0,0 +1,2 @@
|
||||
def foo():
|
||||
a = 10
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.PyQuickFixTestCase;
|
||||
import com.jetbrains.python.inspections.PyPep8NamingInspection;
|
||||
import com.jetbrains.python.inspections.PyProtectedMemberInspection;
|
||||
import com.jetbrains.python.inspections.PyShadowingBuiltinsInspection;
|
||||
|
||||
/**
|
||||
* User: ktisha
|
||||
*/
|
||||
@TestDataPath("$CONTENT_ROOT/../testData//quickFixes/RenameElementQuickFixTest/")
|
||||
public class RenameElementQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
public void testProtectedMember() {
|
||||
doQuickFixTest(PyProtectedMemberInspection.class, "Rename element");
|
||||
}
|
||||
|
||||
public void testPep8() {
|
||||
doQuickFixTest(PyPep8NamingInspection.class, "Rename element");
|
||||
}
|
||||
|
||||
public void testPep8Class() {
|
||||
doQuickFixTest(PyPep8NamingInspection.class, "Rename element");
|
||||
}
|
||||
|
||||
public void testPep8Function() {
|
||||
doQuickFixTest(PyPep8NamingInspection.class, "Rename element");
|
||||
}
|
||||
|
||||
public void testShadowingBuiltins() {
|
||||
doQuickFixTest(PyShadowingBuiltinsInspection.class, "Rename element");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user