1
1
package com .cleanroommc .groovyscript .helper ;
2
2
3
3
import com .cleanroommc .groovyscript .api .GroovyLog ;
4
- import groovy .lang .MetaClass ;
5
- import groovy .lang .MetaMethod ;
6
- import groovy .lang .MetaProperty ;
4
+ import groovy .lang .*;
7
5
import org .codehaus .groovy .ast .ClassNode ;
8
6
import org .codehaus .groovy .reflection .CachedField ;
9
7
import org .codehaus .groovy .reflection .CachedMethod ;
@@ -22,8 +20,14 @@ public class MetaClassExpansion {
22
20
public static void makePublic (MetaClass mc , String memberName ) {
23
21
boolean success = false ;
24
22
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 ());
27
31
success = true ;
28
32
}
29
33
for (MetaMethod mm : mc .getMethods ()) {
@@ -48,9 +52,18 @@ public static void makePublic(MetaClass mc, String memberName) {
48
52
* @param fieldName name of field to make non-final
49
53
*/
50
54
public static void makeMutable (MetaClass mc , String fieldName ) {
55
+ /*while (mc instanceof DelegatingMetaClass delegatingMetaClass) {
56
+ mc = delegatingMetaClass.getAdaptee();
57
+ }*/
51
58
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 );
54
67
return ;
55
68
}
56
69
GroovyLog .get ().error ("Failed to make member '{}' of class {} mutable, because no field was found!" , fieldName , getName (mc ));
0 commit comments