mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Prevents incorrect resolution of unqalified names to qualified. Closes PY-153.
This commit is contained in:
@@ -127,9 +127,13 @@ public interface NameDefiner extends PsiElement {
|
||||
public static PyElement findName(Iterable<PyElement> it, String name) {
|
||||
PyElement ret = null;
|
||||
for (PyElement elt : it) {
|
||||
if ((elt != null) && (name.equals(elt.getName()))) {
|
||||
ret = elt;
|
||||
break;
|
||||
if (elt != null) {
|
||||
// qualified refs don't match by last name, and we're not checking FQNs here
|
||||
if (elt instanceof PyQualifiedExpression && ((PyQualifiedExpression)elt).getQualifier() != null) continue;
|
||||
if (name.equals(elt.getName())) { // plain name matches
|
||||
ret = elt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -320,6 +320,8 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
return ret.toArray(new ResolveResult[ret.size()]);
|
||||
}
|
||||
|
||||
private static boolean USE_CACHE = true; // change to false in debug time to switch off caching
|
||||
|
||||
/**
|
||||
* Resolves reference to possible referred elements.
|
||||
* First element is always what resolve() would return.
|
||||
@@ -332,7 +334,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere
|
||||
@NotNull
|
||||
public ResolveResult[] multiResolve(final boolean incompleteCode) {
|
||||
final PsiManager manager = getElement().getManager();
|
||||
if (manager instanceof PsiManagerImpl) {
|
||||
if (USE_CACHE && manager instanceof PsiManagerImpl) {
|
||||
final ResolveCache cache = ((PsiManagerImpl)manager).getResolveCache();
|
||||
return cache.resolveWithCaching(this, CachingResolver.INSTANCE, false, incompleteCode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Bobobo:
|
||||
zoo = 1
|
||||
|
||||
b = Bobobo()
|
||||
b.zoo = 2
|
||||
|
||||
<ref>zoo # must not resolve
|
||||
@@ -88,6 +88,11 @@ public class PyResolveTest extends ResolveTestCase {
|
||||
assertTrue(targetElement instanceof PyTargetExpression);
|
||||
}
|
||||
|
||||
public void testQualifiedFalseTarget() throws Exception {
|
||||
PsiElement targetElement = resolve();
|
||||
assertNull(targetElement);
|
||||
}
|
||||
|
||||
public void testInnerFuncVar() throws Exception {
|
||||
PsiElement targetElement = resolve();
|
||||
assertTrue(targetElement instanceof PyTargetExpression);
|
||||
|
||||
Reference in New Issue
Block a user