/** * Obtains a MetaClass for an object either from the registry or in the case of * a GroovyObject from the object itself. * * @param obj The object in question * @return The MetaClass * @since 1.6.0 */ public static MetaClass getMetaClass(GroovyObject obj) { // we need this method as trick to guarantee correct method selection return getMetaClass((Object)obj); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class[] categoryClass) { mixin(getMetaClass(self), Arrays.asList(categoryClass)); }
/** * Extend class globally with category methods. * All methods for given class and all super classes will be added to the class. * * @param self any Class * @param categoryClasses a category classes to use * @since 1.6.0 */ public static void mixin(Class self, List<Class> categoryClasses) { mixin(getMetaClass(self), categoryClasses); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class categoryClass) { mixin(getMetaClass(self), Collections.singletonList(categoryClass)); }
/** * This method is invoked by Groovy when a method that's not defined in Java is invoked. * We use that as a syntax for bean definition. */ public Object methodMissing(String name, Object arg) { Object[] args = (Object[])arg; if(args.length == 0) throw new MissingMethodException(name,getClass(),args); if(args[0] instanceof Closure) { // abstract bean definition return invokeBeanDefiningMethod(name, args); } else if(args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) { return invokeBeanDefiningMethod(name, args); } else if (args.length > 1 && args[args.length -1] instanceof Closure) { return invokeBeanDefiningMethod(name, args); } WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext(); MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx); if(!mc.respondsTo(ctx, name, args).isEmpty()){ return mc.invokeMethod(ctx,name, args); } return this; }
return invokeBeanDefiningMethod(name, args); MetaClass mc = DefaultGroovyMethods.getMetaClass(getRegistry()); if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
return invokeBeanDefiningMethod(name, args); MetaClass mc = DefaultGroovyMethods.getMetaClass(getRegistry()); if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
public void apply(Project project) { final LenskitExtension lenskit = project.getExtensions().create("lenskit", LenskitExtension.class, project); for (MetaProperty prop : DefaultGroovyMethods.getMetaClass(lenskit).getProperties()) { String prjProp = "lenskit." + prop.getName(); if (project.hasProperty(prjProp)) {
/** * Obtains a MetaClass for an object either from the registry or in the case of * a GroovyObject from the object itself. * * @param obj The object in question * @return The MetaClass * @since 1.6.0 */ public static MetaClass getMetaClass(GroovyObject obj) { // we need this method as trick to guarantee correct method selection return getMetaClass((Object)obj); }
/** * Obtains a MetaClass for an object either from the registry or in the case of * a GroovyObject from the object itself. * * @param obj The object in question * @return The MetaClass * @since 1.6.0 */ public static MetaClass getMetaClass(GroovyObject obj) { // we need this method as trick to guarantee correct method selection return getMetaClass((Object)obj); }
/** * Extend class globally with category methods. * All methods for given class and all super classes will be added to the class. * * @param self any Class * @param categoryClasses a category classes to use * @since 1.6.0 */ public static void mixin(Class self, List<Class> categoryClasses) { mixin(getMetaClass(self), categoryClasses); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class categoryClass) { mixin(getMetaClass(self), Collections.singletonList(categoryClass)); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class categoryClass) { mixin(getMetaClass(self), Collections.singletonList(categoryClass)); }
/** * Extend class globally with category methods. * All methods for given class and all super classes will be added to the class. * * @param self any Class * @param categoryClasses a category classes to use * @since 1.6.0 */ public static void mixin(Class self, List categoryClasses) { mixin(getMetaClass(self),categoryClasses); }
/** * Extend class globally with category methods. * All methods for given class and all super classes will be added to the class. * * @param self any Class * @param categoryClasses a category classes to use * @since 1.6.0 */ public static void mixin(Class self, List<Class> categoryClasses) { mixin(getMetaClass(self), categoryClasses); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class[] categoryClass) { mixin(getMetaClass(self), Arrays.asList(categoryClass)); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class[] categoryClass) { mixin(getMetaClass(self), Arrays.asList(categoryClass)); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class categoryClass) { mixin(getMetaClass(self), Collections.singletonList(categoryClass)); }
/** * Extend class globally with category methods. * * @param self any Class * @param categoryClass a category class to use * @since 1.6.0 */ public static void mixin(Class self, Class [] categoryClass) { mixin(getMetaClass(self), Arrays.asList(categoryClass)); }
/** * Return true only if the specified object responds to the named method * @param object - the object to check * @param methodName - the name of the method * @return true if the object responds to the named method */ public static boolean respondsTo(Object object, String methodName) { MetaClass metaClass = DefaultGroovyMethods.getMetaClass(object); if (!metaClass.respondsTo(object, methodName).isEmpty()) { return true; } Map properties = DefaultGroovyMethods.getProperties(object); return properties.containsKey(methodName); }