MCPcopy Index your code
hub / github.com/apache/groovy / getProperty

Method getProperty

src/main/java/groovy/lang/MetaClassImpl.java:2017–2127  ·  view source on GitHub ↗

{@inheritDoc}

(final Class sender, final Object object, final String name, final boolean useSuper, final boolean fromInsideClass)

Source from the content-addressed store, hash-verified

2015
2016 /** {@inheritDoc} */
2017 @Override
2018 public Object getProperty(final Class sender, final Object object, final String name, final boolean useSuper, final boolean fromInsideClass) {
2019
2020 //----------------------------------------------------------------------
2021 // handling of static
2022 //----------------------------------------------------------------------
2023 boolean isStatic = (theClass != Class.class && object instanceof Class);
2024 if (isStatic && object != theClass) {
2025 MetaClass mc = registry.getMetaClass((Class<?>) object);
2026 return mc.getProperty(sender, object, name, useSuper, false);
2027 }
2028
2029 checkInitalised();
2030
2031 //----------------------------------------------------------------------
2032 // getter
2033 //----------------------------------------------------------------------
2034 Tuple2<MetaMethod, MetaProperty> methodAndProperty = createMetaMethodAndMetaProperty(sender, name, useSuper, isStatic);
2035 MetaMethod method = methodAndProperty.getV1();
2036 MetaProperty prop = methodAndProperty.getV2();
2037
2038 if (method == null || isSpecialProperty(name) || isVisibleProperty(prop, method, sender)) {
2039 //------------------------------------------------------------------
2040 // public field
2041 //------------------------------------------------------------------
2042 if (prop != null && prop.isPublic()) {
2043 try {
2044 return prop.getProperty(object);
2045 } catch (GroovyRuntimeException e) {
2046 // can't access the field directly but there may be a getter
2047 prop = null;
2048 }
2049 }
2050
2051 //------------------------------------------------------------------
2052 // java.util.Map get method
2053 //------------------------------------------------------------------
2054 if (isMap && !isStatic) {
2055 return ((Map<?,?>) object).get(name);
2056 }
2057
2058 //------------------------------------------------------------------
2059 // non-public field
2060 //------------------------------------------------------------------
2061 if (prop != null) {
2062 try {
2063 return prop.getProperty(object);
2064 } catch (GroovyRuntimeException e) {
2065 }
2066 }
2067 }
2068
2069 //----------------------------------------------------------------------
2070 // java.util.Map get method before non-public getter -- see GROOVY-11367
2071 //----------------------------------------------------------------------
2072 if (isMap && !isStatic && !method.isPublic()) {
2073 return ((Map<?,?>) object).get(name);
2074 }

Callers 1

invokeStaticMethodMethod · 0.95

Calls 15

getPropertyMethod · 0.95
checkInitalisedMethod · 0.95
isSpecialPropertyMethod · 0.95
isVisiblePropertyMethod · 0.95
getPropertyMethod · 0.95
doMethodInvokeMethod · 0.95
getClassPropertyMethod · 0.95
getAtMethod · 0.95
invokeMissingPropertyMethod · 0.95

Tested by

no test coverage detected