11package com .cleanroommc .groovyscript .helper ;
22
33import com .cleanroommc .groovyscript .api .GroovyLog ;
4- import groovy .lang .MetaClass ;
5- import groovy .lang .MetaMethod ;
6- import groovy .lang .MetaProperty ;
4+ import groovy .lang .*;
75import org .codehaus .groovy .ast .ClassNode ;
86import org .codehaus .groovy .reflection .CachedField ;
97import org .codehaus .groovy .reflection .CachedMethod ;
@@ -22,8 +20,14 @@ public class MetaClassExpansion {
2220 public static void makePublic (MetaClass mc , String memberName ) {
2321 boolean success = false ;
2422 MetaProperty mp = mc .getMetaProperty (memberName );
25- if (mp instanceof CachedField cachedField ) {
26- ReflectionHelper .makeFieldPublic (cachedField .getCachedField ());
23+ CachedField field = null ;
24+ if (mp instanceof MetaBeanProperty beanProperty ) {
25+ field = beanProperty .getField ();
26+ } else if (mp instanceof CachedField cachedField ) {
27+ field = cachedField ;
28+ }
29+ if (field != null ) {
30+ ReflectionHelper .makeFieldPublic (field .getCachedField ());
2731 success = true ;
2832 }
2933 for (MetaMethod mm : mc .getMethods ()) {
@@ -48,9 +52,18 @@ public static void makePublic(MetaClass mc, String memberName) {
4852 * @param fieldName name of field to make non-final
4953 */
5054 public static void makeMutable (MetaClass mc , String fieldName ) {
55+ /*while (mc instanceof DelegatingMetaClass delegatingMetaClass) {
56+ mc = delegatingMetaClass.getAdaptee();
57+ }*/
5158 MetaProperty mp = mc .getMetaProperty (fieldName );
52- if (mp instanceof CachedField cachedField ) {
53- ReflectionHelper .setFinal (cachedField .getCachedField (), false );
59+ CachedField field = null ;
60+ if (mp instanceof MetaBeanProperty beanProperty ) {
61+ field = beanProperty .getField ();
62+ } else if (mp instanceof CachedField cachedField ) {
63+ field = cachedField ;
64+ }
65+ if (field != null ) {
66+ ReflectionHelper .setFinal (field .getCachedField (), false );
5467 return ;
5568 }
5669 GroovyLog .get ().error ("Failed to make member '{}' of class {} mutable, because no field was found!" , fieldName , getName (mc ));
0 commit comments