MCPcopy
hub / github.com/apache/groovy / getOuterReference

Method getOuterReference

src/main/java/groovy/lang/MetaClassImpl.java:1362–1382  ·  view source on GitHub ↗
(final Class<?> innerClass, final Object object)

Source from the content-addressed store, hash-verified

1360 }
1361
1362 private Object getOuterReference(final Class<?> innerClass, final Object object) {
1363 Object outer = null;
1364 // non-static inner class may have outer class reference available in this$0 field
1365 if (!(object instanceof Class) && (innerClass.getModifiers() & Opcodes.ACC_STATIC) == 0) {
1366 try {
1367 innerClass.getDeclaredField("this$0");
1368 outer = getAttribute(object,"this$0");
1369 if (outer instanceof GeneratedClosure) {
1370 outer = ((Closure<?>) outer).getThisObject(); // skip closure(s)
1371 }
1372 } catch (NoSuchFieldException ignored) {
1373 // an AIC is non-static but may not have this$0
1374 } catch (Throwable t) {
1375 throw new GroovyRuntimeException(t);
1376 }
1377 }
1378 if (outer == null) {
1379 outer = getNonClosureOuter(innerClass);
1380 }
1381 return outer;
1382 }
1383
1384 /**
1385 * @since 6.0.0

Callers 3

invokeOuterMethodMethod · 0.95
getOuterPropertyMethod · 0.95
setOuterPropertyMethod · 0.95

Calls 5

getAttributeMethod · 0.95
getNonClosureOuterMethod · 0.95
getThisObjectMethod · 0.80
getModifiersMethod · 0.65
getDeclaredFieldMethod · 0.45

Tested by

no test coverage detected