mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-33802 Support create a class quick fix for capitalized undefined references
GitOrigin-RevId: 975454ad1a7013a19f04be6121a500e80fb71075
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fce543ac60
commit
19b0affab5
+3
-3
@@ -42,8 +42,8 @@ public class CreateClassQuickFix implements LocalQuickFix {
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
if (myAnchor instanceof PyFile) {
|
||||
return PyPsiBundle.message("QFIX.create.class.in.module", myClassName, ((PyFile)myAnchor).getName());
|
||||
if (myAnchor.getElement() instanceof PyFile) {
|
||||
return PyPsiBundle.message("QFIX.create.class.in.module", myClassName, ((PyFile)myAnchor.getElement()).getName());
|
||||
}
|
||||
return PyPsiBundle.message("QFIX.create.class.0", myClassName);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class CreateClassQuickFix implements LocalQuickFix {
|
||||
builder.replaceElement(pyClass.getSuperClassExpressions() [0], "object");
|
||||
builder.replaceElement(pyClass.getStatementList(), PyNames.PASS);
|
||||
|
||||
PythonTemplateRunner.runTemplateInSelectedEditor(project, anchor, builder);
|
||||
PythonTemplateRunner.runTemplate(pyClass.getContainingFile(), builder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
-7
@@ -972,8 +972,13 @@ public abstract class PyUnresolvedReferencesVisitor extends PyInspectionVisitor
|
||||
}
|
||||
else if (type instanceof PyModuleType) {
|
||||
PyFile file = ((PyModuleType)type).getModule();
|
||||
result.add(new AddFunctionQuickFix(refText, file.getName()));
|
||||
getCreateClassFix(refText, element);
|
||||
LocalQuickFix createClassQuickFix = getCreateClassFix(refText, element);
|
||||
if (createClassQuickFix != null) {
|
||||
result.add(createClassQuickFix);
|
||||
}
|
||||
else {
|
||||
result.add(new AddFunctionQuickFix(refText, file.getName()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1032,13 +1037,16 @@ public abstract class PyUnresolvedReferencesVisitor extends PyInspectionVisitor
|
||||
}
|
||||
|
||||
LocalQuickFix getCreateClassFix(@NonNls String refText, PsiElement element) {
|
||||
if (refText.length() > 2 && Character.isUpperCase(refText.charAt(0)) && !StringUtil.toUpperCase(refText).equals(refText) &&
|
||||
PsiTreeUtil.getParentOfType(element, PyImportStatementBase.class) == null) {
|
||||
if (refText.length() > 2 && Character.isUpperCase(refText.charAt(0)) && !StringUtil.toUpperCase(refText).equals(refText)) {
|
||||
PsiElement anchor = element;
|
||||
if (element instanceof PyQualifiedExpression) {
|
||||
final PyExpression expr = ((PyQualifiedExpression)element).getQualifier();
|
||||
if (expr != null) {
|
||||
final PyType type = myTypeEvalContext.getType(expr);
|
||||
PyExpression qualifier = ((PyQualifiedExpression)element).getQualifier();
|
||||
if (qualifier == null) {
|
||||
final PyFromImportStatement fromImport = PsiTreeUtil.getParentOfType(element, PyFromImportStatement.class);
|
||||
if (fromImport != null) qualifier = fromImport.getImportSource();
|
||||
}
|
||||
if (qualifier != null) {
|
||||
final PyType type = myTypeEvalContext.getType(qualifier);
|
||||
if (type instanceof PyModuleType) {
|
||||
anchor = ((PyModuleType)type).getModule();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import mod
|
||||
|
||||
clzz = mod.<caret><warning descr="Cannot find reference 'Clzz' in 'mod.py'">Clzz</warning>()
|
||||
@@ -0,0 +1,2 @@
|
||||
class Clzz(object):
|
||||
pass
|
||||
@@ -0,0 +1,3 @@
|
||||
import pkg
|
||||
|
||||
clzz = pkg.<caret><warning descr="Cannot find reference 'Clzz' in '__init__.py'">Clzz</warning>()
|
||||
@@ -0,0 +1,2 @@
|
||||
class Clzz(object):
|
||||
pass
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
from mod import <error descr="Cannot find reference 'Clzz' in 'mod.py'"><caret>Clzz</error>
|
||||
|
||||
|
||||
clzz = Clzz()
|
||||
@@ -0,0 +1,2 @@
|
||||
class Clzz(object):
|
||||
pass
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
from mypack import <error descr="Cannot find reference 'Clzz' in '__init__.py'"><caret>Clzz</error>
|
||||
|
||||
clzz = Clzz()
|
||||
@@ -0,0 +1,2 @@
|
||||
class Clzz(object):
|
||||
pass
|
||||
@@ -222,6 +222,31 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
() -> doInspectionTest(PyUnresolvedReferencesInspection.class, "Create class 'MyClass'", true, true));
|
||||
}
|
||||
|
||||
// PY-33802
|
||||
public void testAddClassToImportedModule() {
|
||||
doMultiFilesInspectionTest(PyUnresolvedReferencesInspection.class,
|
||||
PyPsiBundle.message("QFIX.create.class.in.module", "Clzz", "mod.py"), "mod.py");
|
||||
}
|
||||
|
||||
// PY-33802
|
||||
public void testAddClassToImportedPackage() {
|
||||
doMultiFilesInspectionTest(PyUnresolvedReferencesInspection.class,
|
||||
PyPsiBundle.message("QFIX.create.class.in.module", "Clzz", "__init__.py"), "pkg/__init__.py");
|
||||
}
|
||||
|
||||
// PY-33802
|
||||
public void testAddClassToModuleInFromImport() {
|
||||
doMultiFilesInspectionTest(PyUnresolvedReferencesInspection.class,
|
||||
PyPsiBundle.message("QFIX.create.class.in.module", "Clzz", "mod.py"), "mod.py");
|
||||
}
|
||||
|
||||
// PY-33802
|
||||
public void testAddClassToPackageInFromImport() {
|
||||
doMultiFilesInspectionTest(PyUnresolvedReferencesInspection.class,
|
||||
PyPsiBundle.message("QFIX.create.class.in.module", "Clzz", "__init__.py"),
|
||||
"mypack/__init__.py");
|
||||
}
|
||||
|
||||
// PY-21204
|
||||
public void testAddFunctionFromFString() {
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON36,
|
||||
|
||||
Reference in New Issue
Block a user