MetaClass implementation that forwards all operations to another meta class.
| 28 | * {@link MetaClass} implementation that forwards all operations to another meta class. |
| 29 | */ |
| 30 | public class DelegatingMetaClass implements MetaClass, MutableMetaClass, GroovyObject { |
| 31 | /** |
| 32 | * Wrapped meta class that receives delegated operations. |
| 33 | */ |
| 34 | protected MetaClass delegate; |
| 35 | |
| 36 | /** |
| 37 | * Creates a delegating meta class for the supplied adaptee. |
| 38 | * |
| 39 | * @param delegate the meta class to delegate to |
| 40 | */ |
| 41 | public DelegatingMetaClass(final MetaClass delegate) { |
| 42 | this.delegate = delegate; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a delegating meta class for the current meta class of the supplied type. |
| 47 | * |
| 48 | * @param theClass the Groovy type whose meta class should be wrapped |
| 49 | */ |
| 50 | public DelegatingMetaClass(final Class theClass) { |
| 51 | this(GroovySystem.getMetaClassRegistry().getMetaClass(theClass)); |
| 52 | } |
| 53 | |
| 54 | /** {@inheritDoc} */ |
| 55 | @Override |
| 56 | public boolean isModified() { |
| 57 | return this.delegate instanceof MutableMetaClass && ((MutableMetaClass) this.delegate).isModified(); |
| 58 | } |
| 59 | |
| 60 | /** {@inheritDoc} */ |
| 61 | @Override |
| 62 | public void addNewInstanceMethod(Method method) { |
| 63 | if (delegate instanceof MutableMetaClass) |
| 64 | ((MutableMetaClass) delegate).addNewInstanceMethod(method); |
| 65 | } |
| 66 | |
| 67 | /** {@inheritDoc} */ |
| 68 | @Override |
| 69 | public void addNewStaticMethod(Method method) { |
| 70 | if (delegate instanceof MutableMetaClass) |
| 71 | ((MutableMetaClass) delegate).addNewStaticMethod(method); |
| 72 | } |
| 73 | |
| 74 | /** {@inheritDoc} */ |
| 75 | @Override |
| 76 | public void addMetaMethod(MetaMethod metaMethod) { |
| 77 | if (delegate instanceof MutableMetaClass) |
| 78 | ((MutableMetaClass) delegate).addMetaMethod(metaMethod); |
| 79 | } |
| 80 | |
| 81 | /** {@inheritDoc} */ |
| 82 | @Override |
| 83 | public void addMetaBeanProperty(MetaBeanProperty metaBeanProperty) { |
| 84 | if (delegate instanceof MutableMetaClass) |
| 85 | ((MutableMetaClass) delegate).addMetaBeanProperty(metaBeanProperty); |
| 86 | } |
| 87 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…