diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml index 78b5b57513f9..6cf38846926c 100644 --- a/python/src/META-INF/python-plugin-common.xml +++ b/python/src/META-INF/python-plugin-common.xml @@ -221,6 +221,8 @@ + + diff --git a/python/src/com/jetbrains/python/codeInsight/PyDunderAllReference.java b/python/src/com/jetbrains/python/codeInsight/PyDunderAllReference.java new file mode 100644 index 000000000000..76b59b4ade92 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/PyDunderAllReference.java @@ -0,0 +1,38 @@ +package com.jetbrains.python.codeInsight; + +import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReferenceBase; +import com.intellij.util.ArrayUtil; +import com.jetbrains.python.psi.PyFile; +import com.jetbrains.python.psi.PyStringLiteralExpression; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author yole + */ +public class PyDunderAllReference extends PsiReferenceBase { + public PyDunderAllReference(@NotNull PyStringLiteralExpression element) { + super(element); + final List ranges = element.getStringValueTextRanges(); + if (ranges.size() > 0) { + setRangeInElement(ranges.get(0)); + } + } + + @Override + public PsiElement resolve() { + final PyStringLiteralExpression element = getElement(); + final String name = element.getStringValue(); + PyFile containingFile = (PyFile) element.getContainingFile(); + return containingFile.getElementNamed(name); + } + + @NotNull + @Override + public Object[] getVariants() { + return ArrayUtil.EMPTY_OBJECT_ARRAY; + } +} diff --git a/python/src/com/jetbrains/python/codeInsight/PyDunderAllReferenceProvider.java b/python/src/com/jetbrains/python/codeInsight/PyDunderAllReferenceProvider.java new file mode 100644 index 000000000000..e6394e22e3d8 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/PyDunderAllReferenceProvider.java @@ -0,0 +1,19 @@ +package com.jetbrains.python.codeInsight; + +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import com.intellij.psi.PsiReferenceProvider; +import com.intellij.util.ProcessingContext; +import com.jetbrains.python.psi.PyStringLiteralExpression; +import org.jetbrains.annotations.NotNull; + +/** + * @author yole + */ +public class PyDunderAllReferenceProvider extends PsiReferenceProvider { + @NotNull + @Override + public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { + return new PsiReference[] { new PyDunderAllReference((PyStringLiteralExpression) element) }; + } +} diff --git a/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java new file mode 100644 index 000000000000..8693b4721187 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java @@ -0,0 +1,23 @@ +package com.jetbrains.python.codeInsight; + +import com.intellij.psi.PsiReferenceContributor; +import com.intellij.psi.PsiReferenceRegistrar; +import com.jetbrains.python.PyNames; +import com.jetbrains.python.psi.PyAssignmentStatement; +import com.jetbrains.python.psi.PyStringLiteralExpression; +import com.jetbrains.python.psi.PyTargetExpression; + +import static com.intellij.patterns.PlatformPatterns.psiElement; + +/** + * @author yole + */ +public class PyStdReferenceContributor extends PsiReferenceContributor { + @Override + public void registerReferenceProviders(PsiReferenceRegistrar registrar) { + registrar.registerReferenceProvider(psiElement(PyStringLiteralExpression.class).inside( + psiElement(PyAssignmentStatement.class).withFirstChild( + psiElement(PyTargetExpression.class).withName(PyNames.ALL))), + new PyDunderAllReferenceProvider()); + } +} diff --git a/python/src/com/jetbrains/python/psi/resolve/VariantsProcessor.java b/python/src/com/jetbrains/python/psi/resolve/VariantsProcessor.java index 14f0822f9eab..d99bff72fc8c 100644 --- a/python/src/com/jetbrains/python/psi/resolve/VariantsProcessor.java +++ b/python/src/com/jetbrains/python/psi/resolve/VariantsProcessor.java @@ -36,7 +36,7 @@ public class VariantsProcessor implements PsiScopeProcessor { myContext = context; } - public VariantsProcessor(PsiElement context, final Condition nodeFilter, final Condition nameFilter) { + public VariantsProcessor(PsiElement context, @Nullable final Condition nodeFilter, @Nullable final Condition nameFilter) { myContext = context; myNodeFilter = nodeFilter; myNameFilter = nameFilter; diff --git a/python/testData/refactoring/rename/updateAll.py b/python/testData/refactoring/rename/updateAll.py new file mode 100644 index 000000000000..b22ade997a6c --- /dev/null +++ b/python/testData/refactoring/rename/updateAll.py @@ -0,0 +1,3 @@ +__all__ = ['foo'] + +def foo(): pass diff --git a/python/testData/refactoring/rename/updateAll_after.py b/python/testData/refactoring/rename/updateAll_after.py new file mode 100644 index 000000000000..a908dfc746d8 --- /dev/null +++ b/python/testData/refactoring/rename/updateAll_after.py @@ -0,0 +1,3 @@ +__all__ = ['bar'] + +def bar(): pass diff --git a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java index c1b0e2b2c656..c26cbb5fd134 100644 --- a/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java +++ b/python/testSrc/com/jetbrains/python/refactoring/PyRenameTest.java @@ -49,6 +49,10 @@ public class PyRenameTest extends PyLightFixtureTestCase { doTest("bar"); } + public void testUpdateAll() { // PY-986 + doTest("bar"); + } + private void doTest(final String newName) { myFixture.configureByFile("refactoring/rename/" + getTestName(true) + ".py"); myFixture.renameElementAtCaret(newName);