mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
reference inside __all__ (PY-986)
This commit is contained in:
@@ -221,6 +221,8 @@
|
||||
|
||||
<editorSmartKeysConfigurable implementation="com.jetbrains.python.codeInsight.PySmartKeysOptions"/>
|
||||
|
||||
<psi.referenceContributor implementation="com.jetbrains.python.codeInsight.PyStdReferenceContributor"/>
|
||||
|
||||
<!-- Django -->
|
||||
<codeInsight.lineMarkerProvider language="Python" implementationClass="com.jetbrains.django.annotator.ViewMethodLineMarkerProvider"/>
|
||||
<configurationType implementation="com.jetbrains.django.run.DjangoServerRunConfigurationType"/>
|
||||
|
||||
@@ -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<PyStringLiteralExpression> {
|
||||
public PyDunderAllReference(@NotNull PyStringLiteralExpression element) {
|
||||
super(element);
|
||||
final List<TextRange> 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;
|
||||
}
|
||||
}
|
||||
@@ -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) };
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class VariantsProcessor implements PsiScopeProcessor {
|
||||
myContext = context;
|
||||
}
|
||||
|
||||
public VariantsProcessor(PsiElement context, final Condition<PsiElement> nodeFilter, final Condition<String> nameFilter) {
|
||||
public VariantsProcessor(PsiElement context, @Nullable final Condition<PsiElement> nodeFilter, @Nullable final Condition<String> nameFilter) {
|
||||
myContext = context;
|
||||
myNodeFilter = nodeFilter;
|
||||
myNameFilter = nameFilter;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
__all__ = ['foo']
|
||||
|
||||
def f<caret>oo(): pass
|
||||
@@ -0,0 +1,3 @@
|
||||
__all__ = ['bar']
|
||||
|
||||
def bar(): pass
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user