/** * Scoped use method * * @param self any Object * @param categoryClass a category class to use * @param closure the closure to invoke with the category in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, Class categoryClass, Closure<T> closure) { return GroovyCategorySupport.use(categoryClass, closure); }
private static MetaMethod getCategoryMethodMissing(Class sender) { List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods("methodMissing"); if (possibleGenericMethods != null) { for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext();) { MetaMethod mmethod = (MetaMethod) iter.next(); if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender)) continue; CachedClass[] paramTypes = mmethod.getParameterTypes(); if (paramTypes.length == 2 && paramTypes[0].getTheClass() == String.class) { return mmethod; } } } return null; }
public CategoryMethodList(String name, int level, CategoryMethodList previous) { this.level = level; this.previous = previous; if (previous != null) { addAll(previous); usage = previous.usage; } else { usage = getCategoryNameUsage (name); } }
private Tuple2<MetaMethod, MetaProperty> createMetaMethodAndMetaProperty(final Class senderForMP, final Class senderForCMG, final String name, final boolean useSuper, final boolean isStatic) { MetaMethod method = null; MetaProperty mp = getMetaProperty(senderForMP, name, useSuper, isStatic); if (mp != null) { if (mp instanceof MetaBeanProperty) { MetaBeanProperty mbp = (MetaBeanProperty) mp; method = mbp.getGetter(); mp = mbp.getField(); } } // check for a category method named like a getter if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { String getterName = GroovyCategorySupport.getPropertyCategoryGetterName(name); if (getterName != null) { MetaMethod categoryMethod = getCategoryMethodGetter(senderForCMG, getterName, false); if (categoryMethod != null) method = categoryMethod; } } return new Tuple2<MetaMethod, MetaProperty>(method, mp); }
protected final boolean checkPojoMetaClass() { return !GroovyCategorySupport.hasCategoryInCurrentThread() && ((MetaClassImpl)metaClass).getVersion() == version; }
/** * Create a scope based on given categoryClass and invoke closure within that scope. * * @param categoryClass the class containing category methods * @param closure the closure during which to make the category class methods available * @return the value returned from the closure */ public static Object use(Class categoryClass, Closure closure) { newScope(); try { use(categoryClass); return closure.call(); } finally { endScope(); } }
if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread() && name.length() > 0) { String getterName = GroovyCategorySupport.getPropertyCategorySetterName(name); if (getterName != null) { MetaMethod categoryMethod = getCategoryMethodSetter(sender, getterName, false); if (method == null && !useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { method = getCategoryMethodSetter(sender, "set", true); if (method != null) arguments = new Object[]{name, newValue};
if (!isCallToSuper && GroovyCategorySupport.hasCategoryInAnyThread()) { List used = GroovyCategorySupport.getCategoryMethods(sender, name); if (used != null) { FastArray arr;
public final CallSite acceptGetProperty(Object receiver) { if (GroovyCategorySupport.hasCategoryInCurrentThread() || !(receiver instanceof GroovyObject) || ((GroovyObject)receiver).getMetaClass() != metaClass) { return createGetPropertySite(receiver); } else { return this; } }
/** * Create a scope based on given categoryClasses and invoke closure within that scope. * * @param categoryClasses the list of classes containing category methods * @param closure the closure during which to make the category class methods available * @return the value returned from the closure */ public static Object use(List categoryClasses, Closure closure) { newScope(); try { for (Iterator i = categoryClasses.iterator(); i.hasNext(); ) { Class clazz = (Class) i.next(); use(clazz); } return closure.call(); } finally { endScope(); } }
if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { String getterName = GroovyCategorySupport.getPropertyCategoryGetterName(name); if (getterName != null) { MetaMethod categoryMethod = getCategoryMethodGetter(sender, getterName, false); if (method == null && !useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { method = getCategoryMethodGetter(sender, "get", true); if (method != null) arguments = new Object[]{name};
if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread() && name.length() > 0) { String getterName = GroovyCategorySupport.getPropertyCategorySetterName(name); if (getterName != null) { MetaMethod categoryMethod = getCategoryMethodSetter(sender, getterName, false); if (method == null && !useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { method = getCategoryMethodSetter(sender, "set", true); if (method != null) arguments = new Object[]{name, newValue};
/** * Scoped use method with list of categories. * * @param self any Object * @param categoryClassList a list of category classes * @param closure the closure to invoke with the categories in place * @return the value returned from the closure * @since 1.0 */ public static <T> T use(Object self, List<Class> categoryClassList, Closure<T> closure) { return GroovyCategorySupport.use(categoryClassList, closure); }
public final CallSite acceptGetProperty(Object receiver) { if (GroovyCategorySupport.hasCategoryInCurrentThread() || !(receiver instanceof GroovyObject) || ((GroovyObject)receiver).getMetaClass() != metaClass) { return createGetPropertySite(receiver); } else { return this; } }
private static MetaMethod getCategoryMethodGetter(Class sender, String name, boolean useLongVersion) { List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name); if (possibleGenericMethods != null) { for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext();) { MetaMethod mmethod = (MetaMethod) iter.next(); if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender)) continue; CachedClass[] paramTypes = mmethod.getParameterTypes(); if (useLongVersion) { if (paramTypes.length == 1 && paramTypes[0].getTheClass() == String.class) { return mmethod; } } else { if (paramTypes.length == 0) return mmethod; } } } return null; }
if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { String getterName = GroovyCategorySupport.getPropertyCategoryGetterName(name); if (getterName != null) { MetaMethod categoryMethod = getCategoryMethodGetter(sender, getterName, false); if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { method = getCategoryMethodGetter(sender, "get", true); if (method != null)
public AbstractCallSite(CallSiteArray array, int index, String name) { this.name = name; this.index = index; this.array = array; this.usage = GroovyCategorySupport.getCategoryNameUsage(name); }
return GroovyCategorySupport.use(list, closure);
public final CallSite acceptGroovyObjectGetProperty(Object receiver) { if (GroovyCategorySupport.hasCategoryInCurrentThread() || !(receiver instanceof GroovyObject) || ((GroovyObject)receiver).getMetaClass() != metaClass) { return createGroovyObjectGetPropertySite(receiver); } else { return this; } }
private static MetaMethod getCategoryMethodSetter(Class sender, String name, boolean useLongVersion) { List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods(name); if (possibleGenericMethods != null) { for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext();) { MetaMethod mmethod = (MetaMethod) iter.next(); if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender)) continue; CachedClass[] paramTypes = mmethod.getParameterTypes(); if (useLongVersion) { if (paramTypes.length == 2 && paramTypes[0].getTheClass() == String.class) { return mmethod; } } else { if (paramTypes.length == 1) return mmethod; } } } return null; }