mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
getter/setter/deleter icons in structure view also for classic style properties (PY-5949)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user