mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix implementation of refersFromMethodToClass() (PY-1654)
This commit is contained in:
@@ -189,12 +189,17 @@ public class PyResolveUtil {
|
||||
* @see com.jetbrains.python.psi.PyUtil#getConcealingParent(com.intellij.psi.PsiElement)
|
||||
*/
|
||||
protected static boolean refersFromMethodToClass(final PsiElement inner, final PsiElement outer) {
|
||||
return (
|
||||
inner != null &&
|
||||
PsiTreeUtil.isAncestor(outer, inner, false) &&
|
||||
(PyUtil.getConcealingParent(outer) instanceof PyClass) && // outer is in a class context
|
||||
(PsiTreeUtil.getParentOfType(inner, PyFunction.class, false) != null) // inner is a function or method within the class
|
||||
);
|
||||
if (inner == null) {
|
||||
return false;
|
||||
}
|
||||
PsiElement outerClass = PyUtil.getConcealingParent(outer);
|
||||
if (outerClass instanceof PyClass) { // outer is in a class context
|
||||
PyFunction innerFunction = PsiTreeUtil.getParentOfType(inner, PyFunction.class, false);
|
||||
if (innerFunction != null && innerFunction.getContainingClass() == outerClass) { // inner is a function or method within the class
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo:
|
||||
def eval(self, value):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
eval('foo')
|
||||
# <ref>
|
||||
@@ -361,4 +361,9 @@ public class PyResolveTest extends PyResolveTestCase {
|
||||
public void testStarUnpackingInLoop() { // PY-1525
|
||||
assertResolvesTo(LanguageLevel.PYTHON30, PyTargetExpression.class, "bbb");
|
||||
}
|
||||
|
||||
public void testBuiltinVsClassMember() { // PY-1654
|
||||
final PyFunction pyFunction = assertResolvesTo(PyFunction.class, "eval");
|
||||
assertEquals("__builtin__.py", pyFunction.getContainingFile().getName());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user