apply_cleanup
Apply a JDT code clean-up to a Java file and get the rewritten source. Supports converting loops, lambdas, switch expressions, and more.
Instructions
Apply a JDT code clean-up to a file and return the rewritten source.
USAGE: apply_cleanup(filePath="path/to/File.java", cleanupId="convert_loops") OUTPUT: changed flag, a label, and the full rewritten source (the file is NOT written — apply the returned source yourself).
Supported cleanupId values: - convert_loops: rewrite index- and iterator-based for loops as enhanced for loops - convert_to_lambda: convert anonymous classes implementing a functional interface to lambdas - pattern_matching_instanceof: use pattern matching for instanceof checks followed by a cast - convert_to_switch_expression: convert assignment/return switch statements to switch expressions - string_concat_to_text_block: convert multi-line string concatenations to text blocks - do_while_rather_than_while: replace while loops that always run once with do-while loops - invert_equals: invert equals() calls so the constant is the receiver (avoids NPEs) - boolean_value_rather_than_comparison: simplify comparisons with boolean literals (x == true -> x) - else_if: collapse else blocks containing a lone if into else-if chains - overridden_assignment: remove initializers that are overwritten before being read
Requires load_project to be called first.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to source file | |
| cleanupId | Yes | Clean-up to apply (e.g. 'convert_loops') |