Design Smell Refactoring in JavacTokens
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 30/100
Piste de recherche
Commencez par JavacTokens.java dans com.google.googlejavaformat.java et examinez comment JavacTokens, RawTok et CommentWithTextAndPosition gèrent pos et endPos. Examinez les responsabilités proposées de TokenPosition et les tests existants avant de modifier la conception. Le travail est considéré comme terminé lorsque la gestion des positions est centralisée et encapsulée, que la validation est cohérente et que tous les tests existants passent toujours sans modification de l’API publique.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Overview
Several design smells were identified in the JavacTokens class of google-java-format project. The goal focused on improving code organization, maintainability, and encapsulation while preserving all functionality.
Location
- Package: com.google.googlejavaformat.java
- Class: JavacTokens
- File: JavacTokens.java
Design Smells Identified
1. Position Management Issues
Smells:
- Unnecessary Abstraction
- Multifaceted Abstraction
Symptoms:
- Position fields (pos, endPos) scattered across classes
- Position-related logic mixed with other concerns
- Duplicate position handling in RawTok and CommentWithTextAndPosition
2. Position Validation Logic Issues
Smells:
- Multifaceted Abstraction
- Feature Envy
Symptoms:
- Position validation separated from position data
- Validation logic duplicated or inconsistent
- High coupling between classes for position validation
3. Field Organization Issues
Smells:
- Leaky Encapsulation
- Duplicate Abstraction
Symptoms:
- Position fields not properly encapsulated
- Same fields appearing in multiple classes
- Inconsistent position field management
Possible Refactoring Solutions
1. Extract Class
- Created new TokenPosition class to handle position management
- Centralized all position-related functionality
- Improved code organization and maintainability
- Clear separation of responsibilities
2. Move Method
- Moved position validation logic to TokenPosition class
- Placed validation near the data it validates
- Improved cohesion and reduced coupling
- Ensured consistent validation across usage
3. Move Field
- Consolidated position fields into TokenPosition class
- Eliminated field duplication across classes
- Enforced consistent position handling
- Enhanced encapsulation of position data
Implementation Impact
Code Quality Improvements
- Organization
- Clear separation of concerns
- Logical grouping of related functionality
- Reduced duplication
- Maintainability
- Centralized position management
- Single point for position-related changes
- Better error handling
- Reliability
- Consistent position validation
- Reduced chance of position-related bugs
- Better type safety
Verification
- ✅ All existing tests pass
- ✅ No public API changes
- ✅ Original functionality preserved
- ✅ Backward compatible
- ✅ Follows project coding standards
Conclusion
The implemented refactorings address the identified design smells while maintaining functionality and compatibility. The code is now more maintainable, better organized, and less prone to position-related errors.
Labels
- design-smells
- refactoring
- code-quality
- java
- google-java-format
- Langage dominant
- Java
- Étoiles
- 6.2k
- Forks
- 936
- Merge moyen
- 6 min
- PR mergées (30 j)
- 3
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de google/google-java-format
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
google/google-java-format#1094 · 1 commentaire ·
-
Complementary Teamups Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
google/google-java-format#1450 · 1 réaction ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
google/google-java-format#1439 · 1 commentaire ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 62/100
google/google-java-format#1436 · 2 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 48/100
google/google-java-format#1428 · 4 commentaires ·
Toutes les issues de google/google-java-format
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
HL7/fhir-ig-publisher#1375 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
-
Flaky: a relaunched catch-up replay can still report catching up right after its marker is written Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
johanhaleby/occurrent#1134 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
objectionary/jeo-maven-plugin#1811 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100