Serena Pattern Editor
Automated pattern-based editing for bulk code transformations and migrations.
When to Apply
- •Migrating APIs or libraries
- •Updating deprecated patterns
- •Enforcing coding standards
- •Bulk refactoring operations
Workflow
Phase 1: Pattern Discovery
- •Use
serena_search_for_patternto find all occurrences - •Analyze pattern variations
- •Identify edge cases
Phase 2: Pattern Definition
- •Define precise regex pattern
- •Test on subset of matches
- •Refine pattern as needed
Phase 3: Transformation
- •Use
serena_replace_contentwith regex mode - •Apply wildcards for large replacements
- •Verify each change
Phase 4: Validation
- •Run tests
- •Check for compilation errors
- •Review changes in context
Best Practices
- •Use regex mode with wildcards for efficiency
- •Test pattern on single file first
- •Use
allow_multiple_occurrencescarefully - •Always verify after bulk changes
Pattern Examples
Migration Pattern
regex
// Old API
oldFunction\((.*?)\)
// New API
newFunction($1, { option: true })
Deprecation Pattern
regex
// Find deprecated usage @deprecated.*\n.*function // Replace with warning // TODO: Migrate to new API\n$0
Safety Guidelines
- •Always preview changes before applying
- •Use version control for rollback
- •Run full test suite after changes
- •Document pattern changes
Example Usage
typescript
// Migrate from old API to new API
const workflow = [
'serena_search_for_pattern("oldApi\\.call")',
'serena_replace_content("oldApi\\.call\\((.*?)\\)", "newApi.call($1)", "regex")',
];
Context
- •Learned from repeated migration patterns
- •Optimized for large-scale transformations
- •Confidence: High (based on 5+ observed usages)