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

Method setAttribute

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

Sets an attribute on the given receiver for the specified arguments. The sender is the class that is setting the attribute from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided. The isCallToSuper and fromInsideClass help the Gro

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

Source from the content-addressed store, hash-verified

3200 * @param fromInsideClass Whether the call was invoked from the inside or the outside of the class
3201 */
3202 @Override
3203 public void setAttribute(final Class sender, final Object object, final String attribute, final Object newValue, final boolean useSuper, final boolean fromInsideClass) {
3204 checkInitalised();
3205
3206 boolean isStatic = (theClass != Class.class && object instanceof Class);
3207 if (isStatic && object != theClass) {
3208 MetaClass mc = registry.getMetaClass((Class<?>) object);
3209 mc.setAttribute(sender, object, attribute, newValue, useSuper, fromInsideClass);
3210 return;
3211 }
3212
3213 MetaProperty mp = getMetaProperty(sender, attribute, useSuper, isStatic);
3214 if (mp != null) {
3215 if (mp instanceof MetaBeanProperty mbp) {
3216 mp = mbp.getField();
3217 }
3218 if (mp != null) {
3219 mp.setProperty(object, newValue);
3220 return;
3221 }
3222 }
3223
3224 throw new MissingFieldException(attribute, !useSuper ? theClass : theClass.getSuperclass());
3225 }
3226
3227 /**
3228 * Obtains a reference to the original AST for the MetaClass if it is available at runtime

Callers

nothing calls this directly

Calls 6

checkInitalisedMethod · 0.95
setAttributeMethod · 0.95
getMetaPropertyMethod · 0.95
setPropertyMethod · 0.95
getMetaClassMethod · 0.65
getFieldMethod · 0.45

Tested by

no test coverage detected