Java Code Examples for groovy.lang.MetaClass#getClass()
The following examples show how to use
groovy.lang.MetaClass#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCallSite.java From groovy with Apache License 2.0 | 6 votes |
private CallSite createPojoMetaClassGetPropertySite(final Object receiver) { final MetaClass metaClass = InvokerHelper.getMetaClass(receiver); CallSite site; if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) { site = new PojoMetaClassGetPropertySite(this); } else { final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(receiver.getClass(), receiver, name, false); if (effective != null) { if (effective instanceof CachedField) site = new GetEffectivePojoFieldSite(this, (MetaClassImpl) metaClass, (CachedField) effective); else site = new GetEffectivePojoPropertySite(this, (MetaClassImpl) metaClass, effective); } else { site = new PojoMetaClassGetPropertySite(this); } } array.array[index] = site; return site; }
Example 2
Source File: AbstractCallSite.java From groovy with Apache License 2.0 | 6 votes |
private CallSite createPogoMetaClassGetPropertySite(final GroovyObject receiver) { MetaClass metaClass = receiver.getMetaClass(); CallSite site; if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) { site = new PogoMetaClassGetPropertySite(this, metaClass); } else { final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(this.array.owner, receiver, name, false); if (effective != null) { if (effective instanceof CachedField) site = new GetEffectivePogoFieldSite(this, metaClass, (CachedField) effective); else site = new GetEffectivePogoPropertySite(this, metaClass, effective); } else { site = new PogoMetaClassGetPropertySite(this, metaClass); } } array.array[index] = site; return site; }
Example 3
Source File: CachedClass.java From groovy with Apache License 2.0 | 5 votes |
public void setNewMopMethods(List<MetaMethod> arr) { final MetaClass metaClass = classInfo.getStrongMetaClass(); if (metaClass != null) { if (metaClass.getClass() == MetaClassImpl.class) { classInfo.setStrongMetaClass(null); updateSetNewMopMethods(arr); MetaClassImpl mci = new MetaClassImpl(metaClass.getTheClass()); mci.initialize(); classInfo.setStrongMetaClass(mci); return; } if (metaClass.getClass() == ExpandoMetaClass.class) { classInfo.setStrongMetaClass(null); updateSetNewMopMethods(arr); ExpandoMetaClass newEmc = new ExpandoMetaClass(metaClass.getTheClass()); newEmc.initialize(); classInfo.setStrongMetaClass(newEmc); return; } throw new GroovyRuntimeException("Can't add methods to class " + getTheClass().getName() + ". Strong custom meta class already set."); } classInfo.setWeakMetaClass(null); updateSetNewMopMethods(arr); }
Example 4
Source File: CachedClass.java From groovy with Apache License 2.0 | 5 votes |
public void addNewMopMethods(List<MetaMethod> arr) { final MetaClass metaClass = classInfo.getStrongMetaClass(); if (metaClass != null) { if (metaClass.getClass() == MetaClassImpl.class) { classInfo.setStrongMetaClass(null); List<MetaMethod> res = new ArrayList<>(); Collections.addAll(res, classInfo.newMetaMethods); res.addAll(arr); updateSetNewMopMethods(res); MetaClassImpl answer = new MetaClassImpl(((MetaClassImpl)metaClass).getRegistry(),metaClass.getTheClass()); answer.initialize(); classInfo.setStrongMetaClass(answer); return; } if (metaClass.getClass() == ExpandoMetaClass.class) { ExpandoMetaClass emc = (ExpandoMetaClass)metaClass; classInfo.setStrongMetaClass(null); updateAddNewMopMethods(arr); ExpandoMetaClass newEmc = new ExpandoMetaClass(metaClass.getTheClass()); for (MetaMethod mm : emc.getExpandoMethods()) { newEmc.registerInstanceMethod(mm); } newEmc.initialize(); classInfo.setStrongMetaClass(newEmc); return; } throw new GroovyRuntimeException("Can't add methods to class " + getTheClass().getName() + ". Strong custom meta class already set."); } classInfo.setWeakMetaClass(null); updateAddNewMopMethods(arr); }
Example 5
Source File: Selector.java From groovy with Apache License 2.0 | 5 votes |
/** * Returns the MetaClassImpl if the given MetaClass is one of * MetaClassImpl, AdaptingMetaClass or ClosureMetaClass. If * none of these cases matches, this method returns null. */ private static MetaClassImpl getMetaClassImpl(MetaClass mc, boolean includeEMC) { Class<?> mcc = mc.getClass(); boolean valid = mcc == MetaClassImpl.class || mcc == AdaptingMetaClass.class || mcc == ClosureMetaClass.class || (includeEMC && mcc == ExpandoMetaClass.class); if (!valid) { if (LOG_ENABLED) LOG.info("meta class is neither MetaClassImpl, nor AdoptingMetaClass, nor ClosureMetaClass, normal method selection path disabled."); return null; } if (LOG_ENABLED) LOG.info("meta class is a recognized MetaClassImpl"); return (MetaClassImpl) mc; }