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

Method setProperty

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

Writes a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided. The useSuper and fromInsideClass help the runtime p

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

Source from the content-addressed store, hash-verified

2938 * @param fromInsideClass Whether the call was invoked from the inside or the outside of the class.
2939 */
2940 @Override
2941 public void setProperty(final Class sender, final Object object, final String name, Object newValue, final boolean useSuper, final boolean fromInsideClass) {
2942
2943 //----------------------------------------------------------------------
2944 // handling of static
2945 //----------------------------------------------------------------------
2946 boolean isStatic = (theClass != Class.class && object instanceof Class);
2947 if (isStatic && object != theClass) {
2948 MetaClass mc = registry.getMetaClass((Class<?>) object);
2949 mc.setProperty(sender, object, name, newValue, useSuper, fromInsideClass);
2950 return;
2951 }
2952
2953 checkInitalised();
2954
2955 //----------------------------------------------------------------------
2956 // Unwrap wrapped values for now - the new MOP will handle them properly
2957 //----------------------------------------------------------------------
2958 if (newValue instanceof Wrapper) newValue = ((Wrapper) newValue).unwrap();
2959
2960 MetaMethod method = null;
2961 Object[] arguments = null;
2962
2963 //----------------------------------------------------------------------
2964 // setter
2965 //----------------------------------------------------------------------
2966 MetaProperty mp = getMetaProperty(sender, name, useSuper, isStatic);
2967 MetaProperty field = null;
2968 if (mp != null) {
2969 if (mp instanceof MetaBeanProperty mbp) {
2970 method = mbp.getSetter();
2971 MetaProperty f = mbp.getField();
2972 if (method != null || (f != null && !f.isFinal())) {
2973 arguments = new Object[]{newValue};
2974 field = f;
2975 }
2976 } else {
2977 field = mp;
2978 }
2979 }
2980
2981 // check for a category method named like a setter
2982 if (!useSuper && !isStatic && !name.isEmpty() && GroovyCategorySupport.hasCategoryInCurrentThread()) {
2983 var setterName = GroovyCategorySupport.getPropertyCategorySetterName(name);
2984 if (setterName != null) {
2985 MetaMethod categoryMethod = getCategoryMethodSetter(theClass, setterName, false);
2986 if (categoryMethod != null && (method == null || Boolean.TRUE.equals(getMatchKindForCategory(method, categoryMethod)))) { // GROOVY-11820
2987 method = categoryMethod;
2988 arguments = new Object[]{newValue};
2989 }
2990 }
2991 }
2992
2993 //----------------------------------------------------------------------
2994 // listener method
2995 //----------------------------------------------------------------------
2996 boolean ambiguousListener = false;
2997 if (method == null) {

Callers 2

setPropertiesMethod · 0.95

Calls 15

setPropertyMethod · 0.95
checkInitalisedMethod · 0.95
getMetaPropertyMethod · 0.95
isVisiblePropertyMethod · 0.95
setPropertyMethod · 0.95
isSpecialPropertyMethod · 0.95
castToTypeMethod · 0.95
invokeMissingPropertyMethod · 0.95

Tested by 1