getter/setter/deleter icons in structure view also for classic style properties (PY-5949)

This commit is contained in:
Dmitry Jemerov
2012-03-05 19:48:54 +01:00
parent 67488be11e
commit de7f22cfbf
5 changed files with 41 additions and 4 deletions
@@ -130,6 +130,15 @@ public interface PyClass extends PsiNameIdentifierOwner, PyStatement, NameDefine
@Nullable
Property scanProperties(Processor<Property> processor, boolean inherited);
/**
* Non-recursively searches for a property for which the given function is a getter, setter or deleter.
*
* @param function the function which may be an accessor
* @return the property, or null
*/
@Nullable
Property findPropertyByFunction(PyFunction function);
/**
* @param parent
* @return True iff this and parent are the same or parent is one of our superclasses.
@@ -633,6 +633,21 @@ public class PyClassImpl extends PyPresentableElementImpl<PyClassStub> implement
return null;
}
@Override
public Property findPropertyByFunction(PyFunction function) {
if (myPropertyCache == null) {
myPropertyCache = initializePropertyCache();
}
for (Property property : myPropertyCache.values()) {
if (property.getGetter().value() == function ||
property.getSetter().value() == function ||
property.getDeleter().value() == function) {
return property;
}
}
return null;
}
private Property findLocalProperty(String name) {
if (myPropertyCache == null) {
myPropertyCache = initializePropertyCache();
@@ -450,10 +450,8 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
public Property getProperty() {
final PyClass containingClass = getContainingClass();
final String name = getName();
if (containingClass != null && name != null) {
// TODO find property which uses property call, rather than annotation (function name will be different in that case)
return containingClass.findProperty(name);
if (containingClass != null) {
return containingClass.findPropertyByFunction(this);
}
return null;
}
+7
View File
@@ -11,7 +11,14 @@ class A(object):
def deleter(self):
pass
def v5getter(self):
return self._v
def v5setter(self, v):
self._v = v
v1 = property(getter, setter)
v2 = property(fset=setter, fdel=deleter, fget=getter, doc="doc of v2")
v3 = property(lambda self: self._v, None, (deleter))
v4 = otherworldly # NOTE: not supported yet
v5 = property(v5getter, v5setter)
@@ -108,4 +108,12 @@ public class PyClassicPropertyTest extends PyTestCase {
}
*/
public void testGetProperty() {
final PyFunction getter = myClass.findMethodByName("v5getter", false);
assertNotNull(getter.getProperty());
final PyFunction setter = myClass.findMethodByName("v5setter", false);
assertNotNull(setter.getProperty());
}
}