Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Design Smell Refactoring in JavacTokens

オープン
#1,201 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
30/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
tooling

調査の方向性

com.google.googlejavaformat.java の JavacTokens.java から始め、JavacTokens、RawTok、CommentWithTextAndPosition が pos と endPos をどのように管理しているかを調査します。設計を変更する前に、TokenPosition に提案されている責務と既存のテストを確認します。位置情報の処理が一元化されてカプセル化され、検証が一貫しており、公開 API を変更せずに既存のすべてのテストが引き続き通過すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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
  1. Organization
  • Clear separation of concerns
  • Logical grouping of related functionality
  • Reduced duplication
  1. Maintainability
  • Centralized position management
  • Single point for position-related changes
  • Better error handling
  1. 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
主要言語
Java
スター
6.2k
フォーク
936
平均マージ
6分
マージ済み PR(30日)
3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/google-java-format のほかの issue

google/google-java-format の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。