google-java-format
google-java-format copied to clipboard
fix-#1201/refactor-design-smells
Refactor JavacTokens to Address Design Smells
Description
This PR implements three refactorings in JavacTokens.java to address several identified design smells. The changes improve code organization and maintainability while maintaining all existing functionality.
Changes Made
1. Extract Class - TokenPosition
- Created dedicated class for position management
- Handles pos/endPos fields and related operations
- Addresses "Unnecessary Abstraction" and "Multifaceted Abstraction" smells
- Main affected classes: RawTok, CommentWithTextAndPosition
2. Move Method - Position Validation
- Relocated validation logic to TokenPosition class
- Validates position indices where position data lives
- Addresses "Multifaceted Abstraction" smell
- Improves cohesion of position-related operations
3. Move Field - Position Fields
- Consolidated pos/endPos fields into TokenPosition
- Removed duplicate fields from multiple classes
- Addresses "Leaky Encapsulation" and "Duplicate Abstraction" smells
- Ensures consistent position handling
Testing
- All existing tests pass successfully
- No changes to public APIs
- Original functionality preserved
- Verified backward compatibility
Implementation Notes
- No behavioral changes made
- Only internal refactoring for better organization
- Maintains existing interfaces and contracts
- Follows project coding standards
Related Issues
Resolves #1201 - Design smells in JavacTokens class
Documentation
- Maintained existing documentation style
Change Impact
- Risk Level: Low
- Affected Components:
- JavacTokens.java
Checklist
- [x] Code follows project style guidelines
- [x] All tests pass
- [x] No new warnings introduced
Additional Notes
These refactorings improve code quality while carefully preserving all existing behavior. The changes make the codebase more maintainable and reduce the likelihood of position-related errors.
/cc @reviewer1 @reviewer2