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

Method getProperties

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

Returns the available properties for this type. @return a list of MetaProperty objects

()

Source from the content-addressed store, hash-verified

2445 * @return a list of {@code MetaProperty} objects
2446 */
2447 @Override
2448 public List<MetaProperty> getProperties() {
2449 checkInitalised();
2450 Map<String, MetaProperty> propertyMap = classPropertyIndex.get(theCachedClass);
2451 if (propertyMap == null) {
2452 // GROOVY-6903: May happen in some special environment, like Android, due to class-loading issues
2453 propertyMap = Collections.emptyMap();
2454 }
2455 // simply return the values of the metaproperty map as a List
2456 List<MetaProperty> ret = new ArrayList<>(propertyMap.size());
2457 for (MetaProperty mp : propertyMap.values()) {
2458 if (mp instanceof CachedField cf) {
2459 if (cf.isSynthetic()
2460 || cf.isAnnotationPresent(Internal.class)
2461 // GROOVY-5169, GROOVY-9081, GROOVY-9103, GROOVY-10438, GROOVY-10555, et al.
2462 || (!permissivePropertyAccess && !checkAccessible(getClass(), cf.getDeclaringClass(), cf.getModifiers(), false))) {
2463 continue;
2464 }
2465 } else if (mp instanceof MetaBeanProperty mbp) {
2466 if (isMarkedInternal(mbp)) continue;
2467 // filter out extrinsic properties (DGM, ...)
2468 boolean getter = true, setter = true;
2469 MetaMethod getterMetaMethod = mbp.getGetter();
2470 if (getterMetaMethod == null || getterMetaMethod instanceof GeneratedMetaMethod || getterMetaMethod instanceof NewInstanceMetaMethod) {
2471 getter = false;
2472 }
2473 MetaMethod setterMetaMethod = mbp.getSetter();
2474 if (setterMetaMethod == null || setterMetaMethod instanceof GeneratedMetaMethod || setterMetaMethod instanceof NewInstanceMetaMethod) {
2475 setter = false;
2476 }
2477 if (!getter && !setter) continue;
2478
2479 if (isMap && isSpecialProperty(mp.getName())) continue;
2480
2481 if (!permissivePropertyAccess) { // GROOVY-5169, GROOVY-9081, GROOVY-9103
2482 boolean getterAccessible = canAccessLegally(getterMetaMethod);
2483 boolean setterAccessible = canAccessLegally(setterMetaMethod);
2484 if (!(getterAccessible && setterAccessible)) continue;
2485 }
2486 }
2487
2488 ret.add(mp);
2489 }
2490 return ret;
2491 }
2492
2493 private static boolean canAccessLegally(final MetaMethod method) {
2494 return !(method instanceof CachedMethod)

Callers

nothing calls this directly

Calls 15

checkInitalisedMethod · 0.95
isMarkedInternalMethod · 0.95
isSpecialPropertyMethod · 0.95
canAccessLegallyMethod · 0.95
isAnnotationPresentMethod · 0.80
getClassMethod · 0.80
getMethod · 0.65
sizeMethod · 0.65
valuesMethod · 0.65
isSyntheticMethod · 0.65
checkAccessibleMethod · 0.65
getModifiersMethod · 0.65

Tested by

no test coverage detected