Groovy — 130 Operations for AI Agents

This page is the canonical reference an AI coding agent uses to refactor, query, and analyze Groovy code through the act MCP server. 130 operations available: 56 refactor, 18 query, 42 analysis, 14 verification. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.

18Query
56Refactor
42Analysis
14Verify

Worked Groovy examples

act101 edits Groovy source using the class and expression structure the tree-sitter grammar exposes, so an edit targets a specific null check, closure, or class body rather than a raw text position. It can collapse a null-check guard around a method call into the ?. safe navigation operator, extract an inline closure argument into a named variable, and generate equals()/hashCode() overrides from a class's declared fields. The generated equals()/hashCode() pair reads the class's own field list to build its comparisons and hash terms, rather than emitting a fixed template. Each example below is the verbatim output of the command shown, run against the file shown.

Convert a null check to safe navigation

Service.groovy guards user.getName() with an explicit if (user != null) check before calling it.

$ act refactor-lang convert_to_safe_navigation --file Service.groovy --params '{"line":3,"column":9}'

Before

class Service {
    def process(User user) {
        if (user != null) {
            return user.getName()
        }
        return null
    }
}

After

class Service {
    def process(User user) {
        return user?.getName()
    }
}

The if guard and its body collapse into a single return user?.getName(), so the null check happens inline through the ?. operator instead of a separate branch.

Extract an inline closure into a named variable

Processor.groovy passes the closure { it.toUpperCase() } directly into items.collect.

$ act refactor-lang extract_closure --file Processor.groovy --params '{"name":"toUpper","line":3,"column":30}'

Before

class Processor {
    def process(List items) {
        return items.collect { it.toUpperCase() }
    }
}

After

class Processor {
    def process(List items) {
        def toUpper = { it.toUpperCase() }
        return items.collect(toUpper)
    }
}

The closure is bound to a new toUpper variable declared just above the collect call, which now passes toUpper instead of the inline closure literal.

Generate equals() and hashCode() for a class

Point.groovy declares x and y as plain int fields with no equals() or hashCode() override.

$ act refactor-lang generate_equals_and_hash_code_groovy --file Point.groovy --params '{"line":1,"column":1}'

Before

class Point {
    int x
    int y
}

After

class Point {
    int x
    int y

    @Override
    boolean equals(Object obj) {
        if (this.is(obj)) return true
        if (obj == null || getClass() != obj.getClass()) return false
        Point other = (Point) obj
        return x == other.x && y == other.y
    }

    @Override
    int hashCode() {
        final int prime = 31
        int result = 1
        result = prime * result + x
        result = prime * result + y
        return result
    }
}

Both methods are appended to the class: equals() compares x and y field-by-field after a class and null check, and hashCode() combines them using the standard prime-multiplier pattern.

Query

18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.

callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch

Refactor

Operation Description
add-closure-parameter Add explicit closure parameter to replace implicit 'it'
add-groovydoc Add Groovy documentation comment
add-type-annotation Add explicit type annotation to variable or method
convert-each-to-for-loop Convert .each() closure back to for-in loop
convert-for-loop-to-collect Convert for loop collecting values to .collect() closure
convert-for-to-each Convert traditional for loop to .each() closure
convert-for-to-find Convert for loop with conditional break to .find()
convert-for-to-find-all Convert for loop collecting items to .findAll()
convert-from-gstring Convert GString interpolation back to string concatenation
convert-method-to-property Remove redundant getter method, relying on Groovy automatic property support
convert-static-import Replace import pkg.Class with import static lines and every Class.method() call with method()
convert-string-to-gstring Convert string concatenation to GString interpolation
convert-to-closure Convert Java-style SAM interface to closure
convert-to-elvis Replace ternary with elvis operator
convert-to-groovy-bean Add @Canonical to make class a Groovy bean, consolidating transform annotations
convert-to-safe-navigation Replace null-check if statement and trailing return null with return obj?.method()
encapsulate Make field private, generate getter/setter
extract-closure Extract closure expression
extract-constant Extract literal or expression into class-level constant
extract-constant Extract value to named constant
extract-function Extract selected code block into a new method
extract-interface Create interface from class
extract-variable Extract expression into a named local variable
extract_function Extract a code selection into a new function — automatically infers parameters, return types, and inserts the call site. Use instead of manually cutting/pasting code. Works without LSP; LSP improves type inference. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool), receipt (bool)]
extract_variable Extract an expression into a named variable — inserts the declaration and replaces the expression with the variable name. Works without LSP. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool)]
generate-accessors Generate Groovy getters/setters for fields
generate-builder Generate a fluent builder for a Groovy class
generate-canonical-constructor Generate @Canonical annotation
generate-constructor Generate a constructor from Groovy fields
generate-constructor-from-super Generate constructor that calls super()
generate-equals Generate an equals method from fields
generate-equals-and-hash-code Generate equals() and hashCode() method overrides
generate-from-json Generate JSON deserialization
generate-getters-setters-all Generate getters and setters for all class fields
generate-hash Generate a hashCode method from fields
generate-hash-code-method Generate hashCode() method override
generate-override-method Generate @Override method stub
generate-to-json Generate JSON serialization from fields
generate-to-string Generate a toString method from fields
import-add Add import statement for a symbol
import-organize Sort and organize import statements
import-remove Remove unused import statement
infer-variable-type Replace def with inferred type from initializer
inline Inline a variable, function, or method — replace every usage with its definition body, then remove the original. The inverse of extract. Works without LSP (single-file); LSP enables cross-file inlining. Params: file (string), symbol (string) [, line (u32), preview (bool), receipt (bool)]
inline Inline variable, function, or type alias
insert_body Replace a function's implementation body with new code. AST-validated — rejects if the result has parse errors, so you can't accidentally break syntax. Use instead of manual text editing for function rewrites. Params: file (string), symbol (string), code (string) [, commit (bool)]
introduce-parameter Convert local variable to method parameter
invert-if-statement Invert if-else statement with condition negation
move Move symbol to new location, update imports
move_symbol Move a function, class, or type to a different file and automatically update all imports across the codebase. Use instead of manually cut/paste + fixing imports. Works without LSP (single-file); LSP enables cross-file import updates. Params: file (string), symbol (string), destination (string) [, preview (bool), receipt (bool)]
recipe_run Run a codemod recipe: declarative match → transform → optional verify across modeled grammars. Preview lists matches; apply writes with optional E7 receipts and all-or-nothing rollback. Returns a per-site report.
remove-type-annotation Remove explicit type annotation, use def
rename Rename a symbol and automatically update ALL references across the codebase. Safer and faster than find-and-replace — AST-aware, won't rename strings or comments. Works without LSP (single-file); LSP enables cross-file renames. Params: file (string), old_name (string), new_name (string) [, line (u32), column (u32), preview (bool), receipt (bool)]
rename Rename variable, function, class, or field across all references
simplify-boolean-expression Simplify redundant boolean operations
wrap-null-check Wrap expression in null-check guard or safe navigation

Analysis

42 analysis tools, the same on every supported language. Descriptions live in the shared reference: /docs/analysis-tools.

analyze_api_diff analyze_chokepoints analyze_clones analyze_clusters analyze_cohesion analyze_conformance analyze_coupling analyze_cycle_risk analyze_cycles analyze_dead_code analyze_depth analyze_entry_points analyze_export analyze_extraction analyze_fan_balance analyze_features analyze_hotspots analyze_impact analyze_inconsistencies analyze_inheritance analyze_interface_bloat analyze_interfaces analyze_layers analyze_orphan_types analyze_patterns analyze_platform_deps analyze_readiness analyze_roles analyze_seams analyze_stability analyze_surface analyze_test_gaps analyze_thickness analyze_type_completeness churn_hotspots co_change_clusters coverage_overlay ownership_map profile_overlay simulate split_module trace_overlay

Verify

14 verify tools, the same on every supported language. Descriptions live in the shared reference: /docs/verification.

bisect_regression gate generate_test_harness scan secret_surface summarize_pr taint_flow unsafe_surface verify_behavioral_equivalence verify_contract_preserved verify_diff_semantics verify_port_parity verify_side_effects verify_test_impact

← GraphQLHack →