This file provides context for AI agents (like Claude) working with the CodeCocoon plugin codebase.
For comprehensive project documentation, see CLAUDE.md.
CodeCocoon is an IntelliJ Platform plugin for metamorphic testing of Java projects. It applies semantic-preserving transformations (renaming, moving files) to verify software behavior and test suite robustness.
-
Multi-module project:
core/(abstractions),java/(Java markers),src/main/(IntelliJ implementation) -
Transformation system:
- Base:
Transformationinterface - IntelliJ:
IntelliJAwareTransformation(PSI-aware) - Self-managed:
SelfManagedTransformation(uses refactoring processors)
- Base:
-
Built-in transformations:
rename-method-transformation- Rename methods via LLM suggestions (supports annotation whitelist/blacklist)rename-class-transformation- Rename classes via LLM suggestions (supports annotation whitelist/blacklist)rename-variable-transformation- Rename fields/parameters/locals via LLM suggestions (supports annotation blacklist only)move-file-into-suggested-directory-transformation/ai- Move files (LLM suggests destination)move-file-into-suggested-directory-transformation/config- Move files (config specifies destination)add-comment-transformation- Example transformation (adds comment to file start)
-
LLM Integration: Uses Grazie/Koog to generate semantically similar names
-
Memory System:
- Persistent cache storing LLM suggestions in
.codecocoon-memory/<project-name>.json - Signature-based: Each element (class/method/variable/file) gets unique signature
- Controlled via
useMemoryandgenerateWhenNotInMemoryconfig options - Auto-saves on transformation completion via
PersistentMemory.use {}
- Persistent cache storing LLM suggestions in
-
Annotation Filtering:
- Methods/Classes: Support both whitelist and blacklist modes
- Whitelist mode: Only rename elements WITH specified annotations
- Blacklist mode (recommended): Rename all EXCEPT those with specified annotations
- Variables: Support blacklist mode only (no whitelist)
"_default"keyword: Merges 35-40+ framework annotations with custom ones- Methods: 40+ annotations (Spring, JPA, JAX-RS, JUnit, etc.)
- Classes: 25+ annotations (JPA, Spring, JAX-RS, JAXB, etc.)
- Variables: 35+ annotations (JPA, Jackson, JAXB, Spring, validation, CDI, etc.)
- Warning logged if blacklist used without
"_default"
- Methods/Classes: Support both whitelist and blacklist modes
-
Configuration:
codecocoon.ymlin project root defines transformations and target files -
Important Threading Rules:
- PSI reads require
readAction { }orIntelliJAwareTransformation.withReadAction { } - PSI writes require
writeCommandAction { }or use self-managed refactoring processors
- PSI reads require
-
Import Optimization Prevention: Code style settings configured to prevent wildcard imports and minimize automatic import modifications
- ✅ Prevents wildcard imports (
import package.*) - ✅ Forces single class imports
- ❌ Cannot prevent unused import removal (IntelliJ limitation)
- ✅ Prevents wildcard imports (
- Adding a transformation: Implement
IntelliJAwareTransformation, register inTransformationRegistry.kt - Running the plugin:
./gradlew runIde -PcodecoonConfig=/path/to/codecocoon.yml - Finding transformation logic: Check
src/main/kotlin/.../components/transformations/ - Understanding execution flow: Start at
HeadlessModeStarter.kt→TransformationService.kt→IntelliJTransformationExecutor.kt
Refer to CLAUDE.md for:
- Import optimization prevention - Detailed explanation of settings and limitations
- Detailed architecture explanations
- PSI utilities and helper functions
- Configuration schema and examples
- Transformation implementation details
- Memory system internals (
PsiSignatureGenerator, signature format) - Annotation filtering implementation (whitelist/blacklist logic)
- Error handling patterns
- File structure overview
- Dependencies and testing
This plugin is designed for research purposes to apply controlled metamorphic transformations to Java codebases, enabling:
- Detection of flaky tests
- Verification of test suite effectiveness
- Identification of semantic bugs
- Automated refactoring validation