Class GroovyCategorySupport

java.lang.Object
org.codehaus.groovy.runtime.GroovyCategorySupport

public class GroovyCategorySupport extends Object
Support methods for Groovy category usage
  • Constructor Details

    • GroovyCategorySupport

      public GroovyCategorySupport()
  • Method Details

    • getCategoryNameUsage

      public static AtomicInteger getCategoryNameUsage(String name)
      Returns the shared counter of category methods named name that are currently installed. The same counter is incremented as methods are added and adjusted as a scope ends.
      Parameters:
      name - category method name
      Returns:
      the counter for name, created at zero on first use
    • use

      public static <T> T use(Class categoryClass, Closure<T> closure)
      Create a scope based on given categoryClass and invoke closure within that scope.
      Type Parameters:
      T - return type of closure
      Parameters:
      categoryClass - the class containing category methods
      closure - the closure during which to make the category class methods available
      Returns:
      the value returned from the closure
    • use

      public static <T> T use(List<Class> categoryClasses, Closure<T> closure)
      Create a scope based on given categoryClasses and invoke closure within that scope.
      Type Parameters:
      T - return type of closure
      Parameters:
      categoryClasses - the list of classes containing category methods
      closure - the closure during which to make the category class methods available
      Returns:
      the value returned from the closure
    • hasCategoryInCurrentThread

      public static boolean hasCategoryInCurrentThread()
      Reports whether the current thread is inside a use block. Returns false at once when no thread has an active category scope.
      Returns:
      true when this thread's category scope depth is non-zero
    • hasCategoryInAnyThread

      @Deprecated public static boolean hasCategoryInAnyThread()
      Reports whether a use scope is open on any thread.
      Returns:
      true when at least one category scope is still active
    • getCategoryMethods

      public static GroovyCategorySupport.CategoryMethodList getCategoryMethods(String name)
      This method is used to pull all the new methods out of the local thread context with a particular name.
      Parameters:
      name - the method name of interest
      Returns:
      the list of methods
    • getPropertyCategoryGetterName

      public static String getPropertyCategoryGetterName(String propertyName)
      Returns the category getter installed for propertyName on the current thread. Both getX and boolean isX methods are eligible. When propertyName is not a key, its decapitalized spelling is tried.
      Parameters:
      propertyName - property whose getter is required
      Returns:
      the getter's method name, or null when this thread has no matching category getter
    • getPropertyCategorySetterName

      public static String getPropertyCategorySetterName(String propertyName)
      Returns the category setter installed for propertyName on the current thread. When propertyName is not a key, its decapitalized spelling is tried.
      Parameters:
      propertyName - property whose setter is required
      Returns:
      the setter's method name, or null when this thread has no matching category setter