CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-groovy--groovy

Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax.

Pending
Overview
Eval results
Files

core-runtime.mddocs/

Core Language Runtime

Essential classes for the Groovy runtime including dynamic objects, closures, scripts, and the core language features that enable Groovy's dynamic behavior.

Capabilities

GroovyObject Interface

The fundamental interface that all Groovy objects implement, providing the foundation for dynamic method dispatch and property access.

/**
 * Core interface that all Groovy objects implement, providing meta-programming capabilities
 */
interface GroovyObject {
    /** Invoke a method dynamically by name */
    Object invokeMethod(String name, Object args)
    
    /** Get a property value dynamically by name */
    Object getProperty(String propertyName)
    
    /** Set a property value dynamically by name */
    void setProperty(String propertyName, Object newValue)
    
    /** Get the MetaClass for this object */
    MetaClass getMetaClass()
    
    /** Set the MetaClass for this object */
    void setMetaClass(MetaClass metaClass)
}

GroovyObject Support

Base implementation providing default behavior for GroovyObject.

/**
 * Base implementation of GroovyObject providing default behavior
 */
abstract class GroovyObjectSupport implements GroovyObject {
    // Default implementations for GroovyObject methods
}

Script Base Class

Base class for all Groovy scripts, providing execution context and variable binding.

/**
 * Base class for all Groovy scripts
 */
abstract class Script extends GroovyObjectSupport {
    /** Execute the script and return the result */
    abstract Object run()
    
    /** Get a property (variable) from the script binding */
    Object getProperty(String property)
    
    /** Set a property (variable) in the script binding */
    void setProperty(String property, Object newValue)
    
    /** Get the variable binding context */
    Binding getBinding()
    
    /** Set the variable binding context */
    void setBinding(Binding binding)
}

Closure Class

Represents closures - executable code blocks that can capture variables from their surrounding scope.

/**
 * Represents closures in Groovy - executable code blocks
 */
abstract class Closure<V> extends GroovyObjectSupport {
    /** Call the closure with the given arguments */
    V call(Object... args)
    
    /** Call the closure with no arguments */
    V call()
    
    /** Create a curried closure by fixing some arguments */
    Closure<V> curry(Object... args)
    
    /** Create an n-curried closure fixing arguments from position n */
    Closure<V> ncurry(int n, Object... args)
    
    /** Create a right-curried closure fixing arguments from the right */
    Closure<V> rcurry(Object... args)
    
    /** Create a memoized version that caches results */
    Closure<V> memoize()
    
    /** Create a trampolined closure for tail recursion optimization */
    Closure<V> trampoline()
}

Usage Examples:

// Basic closure usage
def multiply = { a, b -> a * b }
println multiply(3, 4) // 12

// Closure with single parameter (implicit 'it')
def square = { it * it }
println square(5) // 25

// Currying
def add = { a, b -> a + b }
def addFive = add.curry(5)
println addFive(3) // 8

// Memoization for expensive operations
def fibonacci
fibonacci = { n ->
    n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2)
}.memoize()

GString (Interpolated Strings)

Groovy's interpolated string implementation allowing embedded expressions.

/**
 * Groovy's interpolated string implementation
 */
abstract class GString extends GroovyObjectSupport {
    /** Convert to regular String */
    String toString()
    
    /** Get the interpolated values */
    Object[] getValues()
    
    /** Get the string parts (between interpolations) */
    String[] getStrings()
}

Usage Examples:

def name = "World"
def count = 42
def message = "Hello $name, count is ${count * 2}"
println message // "Hello World, count is 84"

// Multiline GStrings
def sql = """
    SELECT * FROM users 
    WHERE name = '$name' 
    AND age > ${count}
"""

Range Types

Range implementations for sequences and iterations.

/**
 * Interface for range types (e.g., 1..10)
 */
interface Range<T extends Comparable> {
    /** Check if the range contains the given object */
    boolean contains(Object o)
    
    /** Get the start value of the range */
    T getFrom()
    
    /** Get the end value of the range */
    T getTo()
    
    /** Check if this is a reverse range */
    boolean isReverse()
}

/**
 * Integer range implementation
 */
class IntRange implements Range<Integer> {
    IntRange(int from, int to)
    IntRange(Integer from, Integer to)
}

/**
 * Generic object range implementation
 */
class ObjectRange implements Range<Comparable> {
    ObjectRange(Comparable from, Comparable to)
}

Usage Examples:

// Integer ranges
def range1 = 1..5      // inclusive range: 1, 2, 3, 4, 5
def range2 = 1..<5     // exclusive range: 1, 2, 3, 4
def range3 = 5..1      // reverse range: 5, 4, 3, 2, 1

// Iteration
(1..3).each { println it }  // prints 1, 2, 3

// Collection operations
def squares = (1..5).collect { it * it }  // [1, 4, 9, 16, 25]

// Character ranges
('a'..'d').each { print it }  // prints abcd

System Utilities

System-level Groovy operations and information.

/**
 * System-level Groovy operations and information
 */
class GroovySystem {
    /** Get the Groovy version */
    static String getVersion()
    
    /** Get the global MetaClass registry */
    static MetaClassRegistry getMetaClassRegistry()
}

Exception Types

Core exception classes for Groovy runtime errors.

/**
 * Base runtime exception for Groovy
 */
class GroovyRuntimeException extends RuntimeException {
    GroovyRuntimeException(String message)
    GroovyRuntimeException(String message, Throwable cause)
}

/**
 * Thrown when a method cannot be found
 */
class MissingMethodException extends GroovyRuntimeException {
    MissingMethodException(String method, Class type, Object[] arguments)
}

/**
 * Thrown when a property cannot be found
 */
class MissingPropertyException extends GroovyRuntimeException {
    MissingPropertyException(String property, Class type)
}

/**
 * Thrown when attempting to modify a read-only property
 */
class ReadOnlyPropertyException extends GroovyRuntimeException {
    ReadOnlyPropertyException(String property, Class clazz)
}

Tuple Classes

Immutable tuple implementations for structured data.

/**
 * Base class for tuples
 */
class Tuple {
    // Base functionality for all tuple types
}

/**
 * Tuple with two elements
 */
class Tuple2<T1, T2> extends Tuple {
    T1 getV1()
    T2 getV2()
}

/**
 * Tuple with three elements  
 */
class Tuple3<T1, T2, T3> extends Tuple {
    T1 getV1()
    T2 getV2()
    T3 getV3()
}

// Additional tuple classes: Tuple0 through Tuple16

Usage Examples:

def pair = new Tuple2("hello", 42)
println pair.v1  // "hello"
println pair.v2  // 42

def triple = new Tuple3("name", 25, true)
println "${triple.v1} is ${triple.v2} years old, active: ${triple.v3}"

Writable Interface

Interface for objects that can efficiently write themselves to text streams, particularly useful for templates and large content generation.

/**
 * Interface for objects that can write themselves to a text stream
 */
interface Writable {
    /** 
     * Write this object to the given writer 
     * @param out the Writer to output data to
     * @return the Writer that was passed
     */
    Writer writeTo(Writer out) throws IOException
}

Usage Examples:

// Creating a custom Writable
class MyContent implements Writable {
    String data
    
    Writer writeTo(Writer out) {
        out.write("Content: ${data}")
        return out
    }
}

def content = new MyContent(data: "Hello World")
def writer = new StringWriter()
content.writeTo(writer)
println writer.toString() // "Content: Hello World"

Interceptor Interface

Interface for intercepting method calls on objects managed by ProxyMetaClass, enabling AOP-style programming.

/**
 * Interface for intercepting method calls
 */
interface Interceptor {
    /** 
     * Called before method execution
     * @param object receiver object
     * @param methodName name of method to call
     * @param arguments method arguments
     * @return arbitrary result that may replace original method result
     */
    Object beforeInvoke(Object object, String methodName, Object[] arguments)
    
    /** 
     * Called after method execution
     * @param object receiver object
     * @param methodName name of called method
     * @param arguments method arguments
     * @param result result of method call or beforeInvoke
     * @return arbitrary result that can replace original method result
     */
    Object afterInvoke(Object object, String methodName, Object[] arguments, Object result)
    
    /** 
     * @return whether the target method should be invoked at all
     */
    boolean doInvoke()
}

Usage Examples:

// Logging interceptor
class LoggingInterceptor implements Interceptor {
    Object beforeInvoke(Object object, String methodName, Object[] arguments) {
        println "Before calling ${methodName} on ${object.class.name}"
        return null
    }
    
    Object afterInvoke(Object object, String methodName, Object[] arguments, Object result) {
        println "After calling ${methodName}, result: ${result}"
        return result
    }
    
    boolean doInvoke() { return true }
}

Property Access Interceptor

Specialized interceptor for property access operations.

/**
 * Interface for intercepting property access
 */
interface PropertyAccessInterceptor extends Interceptor {
    /** 
     * Called before getting a property
     * @param object the receiver object
     * @param property the property name
     */
    Object beforeGet(Object object, String property)
    
    /** 
     * Called before setting a property
     * @param object the receiver object
     * @param property the property name
     * @param newValue the new property value
     */
    Object beforeSet(Object object, String property, Object newValue)
}

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-groovy--groovy

docs

cli-interface.md

collections-utilities.md

core-runtime.md

index.md

json-processing.md

meta-programming.md

script-execution.md

sql-database.md

template-processing.md

xml-processing.md

tile.json