mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-18 14:53:05 +08:00
docs: add native Japanese translation of ECC documentation (ja-JP)
Translate everything-claude-code repository to Japanese including: - 17 root documentation files - 60 agent documentation files - 80 command documentation files - 99 rule files across 18 language directories (common, angular, arkts, cpp, csharp, dart, fsharp, golang, java, kotlin, perl, php, python, ruby, rust, swift, typescript, web) - 199 skill documentation files Total: 455 files translated to Japanese with: - Consistent terminology glossary applied throughout - YAML field names preserved in English (name, description, etc.) - Code blocks and examples untouched (comments translated) - Markdown structure and relative links preserved - Professional translation maintaining technical accuracy This translation expands ECC accessibility to Japanese-speaking developers and teams. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
114
docs/ja-JP/rules/java/coding-style.md
Normal file
114
docs/ja-JP/rules/java/coding-style.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
paths:
|
||||
- "**/*.java"
|
||||
---
|
||||
# Java コーディングスタイル
|
||||
|
||||
> このファイルは [common/coding-style.md](../common/coding-style.md) を Java 固有のコンテンツで拡張します。
|
||||
|
||||
## フォーマット
|
||||
|
||||
- **google-java-format** または **Checkstyle**(Google または Sun スタイル)で強制
|
||||
- ファイルごとに1つの public トップレベル型
|
||||
- 一貫したインデント: 2 または 4 スペース(プロジェクト標準に合わせる)
|
||||
- メンバー順序: 定数、フィールド、コンストラクタ、public メソッド、protected、private
|
||||
|
||||
## 不変性
|
||||
|
||||
- 値型には `record` を優先(Java 16+)
|
||||
- フィールドはデフォルトで `final` にする — 可変状態は必要な場合のみ使用
|
||||
- public API からは防御的コピーを返す: `List.copyOf()`、`Map.copyOf()`、`Set.copyOf()`
|
||||
- コピーオンライト: 既存のインスタンスを変更するのではなく、新しいインスタンスを返す
|
||||
|
||||
```java
|
||||
// GOOD — 不変の値型
|
||||
public record OrderSummary(Long id, String customerName, BigDecimal total) {}
|
||||
|
||||
// GOOD — final フィールド、setter なし
|
||||
public class Order {
|
||||
private final Long id;
|
||||
private final List<LineItem> items;
|
||||
|
||||
public List<LineItem> getItems() {
|
||||
return List.copyOf(items);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 命名
|
||||
|
||||
標準的な Java の慣例に従う:
|
||||
- `PascalCase` — クラス、インターフェース、レコード、列挙型
|
||||
- `camelCase` — メソッド、フィールド、パラメータ、ローカル変数
|
||||
- `SCREAMING_SNAKE_CASE` — `static final` 定数
|
||||
- パッケージ: すべて小文字、逆ドメイン(`com.example.app.service`)
|
||||
|
||||
## モダン Java 機能
|
||||
|
||||
明確さを向上させるモダンな言語機能を使用する:
|
||||
- **レコード** — DTO と値型(Java 16+)
|
||||
- **シールドクラス** — 閉じた型階層(Java 17+)
|
||||
- **パターンマッチング** — `instanceof` で明示的キャスト不要(Java 16+)
|
||||
- **テキストブロック** — 複数行文字列(SQL、JSON テンプレート)(Java 15+)
|
||||
- **Switch 式** — アロー構文(Java 14+)
|
||||
- **switch でのパターンマッチング** — 網羅的なシールド型処理(Java 21+)
|
||||
|
||||
```java
|
||||
// パターンマッチング instanceof
|
||||
if (shape instanceof Circle c) {
|
||||
return Math.PI * c.radius() * c.radius();
|
||||
}
|
||||
|
||||
// シールド型階層
|
||||
public sealed interface PaymentMethod permits CreditCard, BankTransfer, Wallet {}
|
||||
|
||||
// Switch 式
|
||||
String label = switch (status) {
|
||||
case ACTIVE -> "Active";
|
||||
case SUSPENDED -> "Suspended";
|
||||
case CLOSED -> "Closed";
|
||||
};
|
||||
```
|
||||
|
||||
## Optional の使い方
|
||||
|
||||
- 結果がない可能性がある検索メソッドから `Optional<T>` を返す
|
||||
- `map()`、`flatMap()`、`orElseThrow()` を使用する — `isPresent()` なしで `get()` を呼ばない
|
||||
- `Optional` をフィールド型やメソッドパラメータとして使用しない
|
||||
|
||||
```java
|
||||
// GOOD
|
||||
return repository.findById(id)
|
||||
.map(ResponseDto::from)
|
||||
.orElseThrow(() -> new OrderNotFoundException(id));
|
||||
|
||||
// BAD — パラメータとしての Optional
|
||||
public void process(Optional<String> name) {}
|
||||
```
|
||||
|
||||
## エラーハンドリング
|
||||
|
||||
- ドメインエラーには非チェック例外を優先
|
||||
- `RuntimeException` を継承するドメイン固有の例外を作成
|
||||
- トップレベルハンドラ以外では広範な `catch (Exception e)` を避ける
|
||||
- 例外メッセージにコンテキストを含める
|
||||
|
||||
```java
|
||||
public class OrderNotFoundException extends RuntimeException {
|
||||
public OrderNotFoundException(Long id) {
|
||||
super("Order not found: id=" + id);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## ストリーム
|
||||
|
||||
- 変換にはストリームを使用する; パイプラインは短く保つ(最大3〜4操作)
|
||||
- 可読性がある場合はメソッド参照を優先: `.map(Order::getTotal)`
|
||||
- ストリーム操作での副作用を避ける
|
||||
- 複雑なロジックの場合、入り組んだストリームパイプラインよりもループを優先
|
||||
|
||||
## リファレンス
|
||||
|
||||
スキル: `java-coding-standards` で完全なコーディング規約と例を参照してください。
|
||||
スキル: `jpa-patterns` で JPA/Hibernate エンティティ設計パターンを参照してください。
|
||||
18
docs/ja-JP/rules/java/hooks.md
Normal file
18
docs/ja-JP/rules/java/hooks.md
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
paths:
|
||||
- "**/*.java"
|
||||
- "**/pom.xml"
|
||||
- "**/build.gradle"
|
||||
- "**/build.gradle.kts"
|
||||
---
|
||||
# Java フック
|
||||
|
||||
> このファイルは [common/hooks.md](../common/hooks.md) を Java 固有のコンテンツで拡張します。
|
||||
|
||||
## PostToolUse フック
|
||||
|
||||
`~/.claude/settings.json` で設定:
|
||||
|
||||
- **google-java-format**: 編集後に `.java` ファイルを自動フォーマット
|
||||
- **checkstyle**: Java ファイル編集後にスタイルチェックを実行
|
||||
- **./mvnw compile** または **./gradlew compileJava**: 変更後にコンパイルを検証
|
||||
147
docs/ja-JP/rules/java/patterns.md
Normal file
147
docs/ja-JP/rules/java/patterns.md
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
paths:
|
||||
- "**/*.java"
|
||||
---
|
||||
# Java パターン
|
||||
|
||||
> このファイルは [common/patterns.md](../common/patterns.md) を Java 固有のコンテンツで拡張します。
|
||||
|
||||
## リポジトリパターン
|
||||
|
||||
データアクセスをインターフェースの背後にカプセル化する:
|
||||
|
||||
```java
|
||||
public interface OrderRepository {
|
||||
Optional<Order> findById(Long id);
|
||||
List<Order> findAll();
|
||||
Order save(Order order);
|
||||
void deleteById(Long id);
|
||||
}
|
||||
```
|
||||
|
||||
具象実装がストレージの詳細を処理する(JPA、JDBC、テスト用インメモリ)。
|
||||
|
||||
## サービス層
|
||||
|
||||
ビジネスロジックはサービスクラスに配置する; コントローラとリポジトリは薄く保つ:
|
||||
|
||||
```java
|
||||
public class OrderService {
|
||||
private final OrderRepository orderRepository;
|
||||
private final PaymentGateway paymentGateway;
|
||||
|
||||
public OrderService(OrderRepository orderRepository, PaymentGateway paymentGateway) {
|
||||
this.orderRepository = orderRepository;
|
||||
this.paymentGateway = paymentGateway;
|
||||
}
|
||||
|
||||
public OrderSummary placeOrder(CreateOrderRequest request) {
|
||||
var order = Order.from(request);
|
||||
paymentGateway.charge(order.total());
|
||||
var saved = orderRepository.save(order);
|
||||
return OrderSummary.from(saved);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## コンストラクタインジェクション
|
||||
|
||||
常にコンストラクタインジェクションを使用する — フィールドインジェクションは使用しない:
|
||||
|
||||
```java
|
||||
// GOOD — コンストラクタインジェクション(テスト可能、不変)
|
||||
public class NotificationService {
|
||||
private final EmailSender emailSender;
|
||||
|
||||
public NotificationService(EmailSender emailSender) {
|
||||
this.emailSender = emailSender;
|
||||
}
|
||||
}
|
||||
|
||||
// BAD — フィールドインジェクション(リフレクションなしではテスト不可、フレームワークの魔法が必要)
|
||||
public class NotificationService {
|
||||
@Inject // or @Autowired
|
||||
private EmailSender emailSender;
|
||||
}
|
||||
```
|
||||
|
||||
## DTO マッピング
|
||||
|
||||
DTO にはレコードを使用する。サービス/コントローラの境界でマッピングする:
|
||||
|
||||
```java
|
||||
public record OrderResponse(Long id, String customer, BigDecimal total) {
|
||||
public static OrderResponse from(Order order) {
|
||||
return new OrderResponse(order.getId(), order.getCustomerName(), order.getTotal());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Builder パターン
|
||||
|
||||
オプションパラメータが多いオブジェクトに使用する:
|
||||
|
||||
```java
|
||||
public class SearchCriteria {
|
||||
private final String query;
|
||||
private final int page;
|
||||
private final int size;
|
||||
private final String sortBy;
|
||||
|
||||
private SearchCriteria(Builder builder) {
|
||||
this.query = builder.query;
|
||||
this.page = builder.page;
|
||||
this.size = builder.size;
|
||||
this.sortBy = builder.sortBy;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String query = "";
|
||||
private int page = 0;
|
||||
private int size = 20;
|
||||
private String sortBy = "id";
|
||||
|
||||
public Builder query(String query) { this.query = query; return this; }
|
||||
public Builder page(int page) { this.page = page; return this; }
|
||||
public Builder size(int size) { this.size = size; return this; }
|
||||
public Builder sortBy(String sortBy) { this.sortBy = sortBy; return this; }
|
||||
public SearchCriteria build() { return new SearchCriteria(this); }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## ドメインモデルのシールド型
|
||||
|
||||
```java
|
||||
public sealed interface PaymentResult permits PaymentSuccess, PaymentFailure {
|
||||
record PaymentSuccess(String transactionId, BigDecimal amount) implements PaymentResult {}
|
||||
record PaymentFailure(String errorCode, String message) implements PaymentResult {}
|
||||
}
|
||||
|
||||
// 網羅的な処理(Java 21+)
|
||||
String message = switch (result) {
|
||||
case PaymentSuccess s -> "Paid: " + s.transactionId();
|
||||
case PaymentFailure f -> "Failed: " + f.errorCode();
|
||||
};
|
||||
```
|
||||
|
||||
## API レスポンスエンベロープ
|
||||
|
||||
一貫した API レスポンス:
|
||||
|
||||
```java
|
||||
public record ApiResponse<T>(boolean success, T data, String error) {
|
||||
public static <T> ApiResponse<T> ok(T data) {
|
||||
return new ApiResponse<>(true, data, null);
|
||||
}
|
||||
public static <T> ApiResponse<T> error(String message) {
|
||||
return new ApiResponse<>(false, null, message);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## リファレンス
|
||||
|
||||
スキル: `springboot-patterns` で Spring Boot アーキテクチャパターンを参照してください。
|
||||
スキル: `quarkus-patterns` で REST、Panache、メッセージングを含む Quarkus アーキテクチャパターンを参照してください。
|
||||
スキル: `jpa-patterns` でエンティティ設計とクエリ最適化を参照してください。
|
||||
101
docs/ja-JP/rules/java/security.md
Normal file
101
docs/ja-JP/rules/java/security.md
Normal file
@@ -0,0 +1,101 @@
|
||||
---
|
||||
paths:
|
||||
- "**/*.java"
|
||||
---
|
||||
# Java セキュリティ
|
||||
|
||||
> このファイルは [common/security.md](../common/security.md) を Java 固有のコンテンツで拡張します。
|
||||
|
||||
## シークレット管理
|
||||
|
||||
- API キー、トークン、認証情報をソースコードにハードコードしない
|
||||
- 環境変数を使用する: `System.getenv("API_KEY")`
|
||||
- 本番環境のシークレットにはシークレットマネージャ(Vault、AWS Secrets Manager)を使用する
|
||||
- シークレットを含むローカル設定ファイルは `.gitignore` に追加する
|
||||
|
||||
```java
|
||||
// BAD
|
||||
private static final String API_KEY = "sk-abc123...";
|
||||
|
||||
// GOOD — 環境変数
|
||||
String apiKey = System.getenv("PAYMENT_API_KEY");
|
||||
Objects.requireNonNull(apiKey, "PAYMENT_API_KEY must be set");
|
||||
```
|
||||
|
||||
## SQL インジェクション防止
|
||||
|
||||
- 常にパラメータ化クエリを使用する — ユーザー入力を SQL に連結しない
|
||||
- `PreparedStatement` またはフレームワークのパラメータ化クエリ API を使用する
|
||||
- ネイティブクエリで使用される入力はすべて検証・サニタイズする
|
||||
|
||||
```java
|
||||
// BAD — 文字列連結による SQL インジェクション
|
||||
Statement stmt = conn.createStatement();
|
||||
String sql = "SELECT * FROM orders WHERE name = '" + name + "'";
|
||||
stmt.executeQuery(sql);
|
||||
|
||||
// GOOD — パラメータ化クエリの PreparedStatement
|
||||
PreparedStatement ps = conn.prepareStatement("SELECT * FROM orders WHERE name = ?");
|
||||
ps.setString(1, name);
|
||||
|
||||
// GOOD — JDBC テンプレート
|
||||
jdbcTemplate.query("SELECT * FROM orders WHERE name = ?", mapper, name);
|
||||
```
|
||||
|
||||
## 入力検証
|
||||
|
||||
- 処理前にシステム境界ですべてのユーザー入力を検証する
|
||||
- バリデーションフレームワーク使用時は DTO に Bean Validation(`@NotNull`、`@NotBlank`、`@Size`)を使用する
|
||||
- ファイルパスとユーザー提供文字列は使用前にサニタイズする
|
||||
- 検証に失敗した入力は明確なエラーメッセージで拒否する
|
||||
|
||||
```java
|
||||
// プレーン Java での手動検証
|
||||
public Order createOrder(String customerName, BigDecimal amount) {
|
||||
if (customerName == null || customerName.isBlank()) {
|
||||
throw new IllegalArgumentException("Customer name is required");
|
||||
}
|
||||
if (amount == null || amount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new IllegalArgumentException("Amount must be positive");
|
||||
}
|
||||
return new Order(customerName, amount);
|
||||
}
|
||||
```
|
||||
|
||||
## 認証と認可
|
||||
|
||||
- 独自の暗号化を実装しない — 確立されたライブラリを使用する
|
||||
- パスワードは bcrypt または Argon2 で保存する、MD5/SHA1 は使用しない
|
||||
- サービス境界で認可チェックを強制する
|
||||
- ログから機密データを消去する — パスワード、トークン、PII をログに記録しない
|
||||
|
||||
## 依存関係のセキュリティ
|
||||
|
||||
- `mvn dependency:tree` または `./gradlew dependencies` で推移的依存関係を監査する
|
||||
- OWASP Dependency-Check または Snyk を使用して既知の CVE をスキャンする
|
||||
- 依存関係を最新に保つ — Dependabot または Renovate を設定する
|
||||
|
||||
## エラーメッセージ
|
||||
|
||||
- API レスポンスにスタックトレース、内部パス、SQL エラーを公開しない
|
||||
- ハンドラ境界で例外を安全な汎用クライアントメッセージにマッピングする
|
||||
- 詳細なエラーはサーバー側でログに記録する; クライアントには汎用メッセージを返す
|
||||
|
||||
```java
|
||||
// 詳細をログに記録し、汎用メッセージを返す
|
||||
try {
|
||||
return orderService.findById(id);
|
||||
} catch (OrderNotFoundException ex) {
|
||||
log.warn("Order not found: id={}", id);
|
||||
return ApiResponse.error("Resource not found"); // 汎用、内部情報なし
|
||||
} catch (Exception ex) {
|
||||
log.error("Unexpected error processing order id={}", id, ex);
|
||||
return ApiResponse.error("Internal server error"); // ex.getMessage() を公開しない
|
||||
}
|
||||
```
|
||||
|
||||
## リファレンス
|
||||
|
||||
スキル: `springboot-security` で Spring Security の認証・認可パターンを参照してください。
|
||||
スキル: `quarkus-security` で JWT/OIDC、RBAC、CDI を含む Quarkus セキュリティを参照してください。
|
||||
スキル: `security-review` で一般的なセキュリティチェックリストを参照してください。
|
||||
133
docs/ja-JP/rules/java/testing.md
Normal file
133
docs/ja-JP/rules/java/testing.md
Normal file
@@ -0,0 +1,133 @@
|
||||
---
|
||||
paths:
|
||||
- "**/*.java"
|
||||
---
|
||||
# Java テスト
|
||||
|
||||
> このファイルは [common/testing.md](../common/testing.md) を Java 固有のコンテンツで拡張します。
|
||||
|
||||
## テストフレームワーク
|
||||
|
||||
- **JUnit 5**(`@Test`、`@ParameterizedTest`、`@Nested`、`@DisplayName`)
|
||||
- **AssertJ** — 流暢なアサーション(`assertThat(result).isEqualTo(expected)`)
|
||||
- **Mockito** — 依存関係のモック
|
||||
- **Testcontainers** — データベースやサービスを必要とする統合テスト
|
||||
|
||||
## テストの構成
|
||||
|
||||
```
|
||||
src/test/java/com/example/app/
|
||||
service/ # サービス層のユニットテスト
|
||||
controller/ # Web 層 / API テスト
|
||||
repository/ # データアクセステスト
|
||||
integration/ # クロスレイヤー統合テスト
|
||||
```
|
||||
|
||||
`src/main/java` のパッケージ構造を `src/test/java` にミラーリングする。
|
||||
|
||||
## ユニットテストパターン
|
||||
|
||||
```java
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OrderServiceTest {
|
||||
|
||||
@Mock
|
||||
private OrderRepository orderRepository;
|
||||
|
||||
private OrderService orderService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
orderService = new OrderService(orderRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("findById returns order when exists")
|
||||
void findById_existingOrder_returnsOrder() {
|
||||
var order = new Order(1L, "Alice", BigDecimal.TEN);
|
||||
when(orderRepository.findById(1L)).thenReturn(Optional.of(order));
|
||||
|
||||
var result = orderService.findById(1L);
|
||||
|
||||
assertThat(result.customerName()).isEqualTo("Alice");
|
||||
verify(orderRepository).findById(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("findById throws when order not found")
|
||||
void findById_missingOrder_throws() {
|
||||
when(orderRepository.findById(99L)).thenReturn(Optional.empty());
|
||||
|
||||
assertThatThrownBy(() -> orderService.findById(99L))
|
||||
.isInstanceOf(OrderNotFoundException.class)
|
||||
.hasMessageContaining("99");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## パラメータ化テスト
|
||||
|
||||
```java
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"100.00, 10, 90.00",
|
||||
"50.00, 0, 50.00",
|
||||
"200.00, 25, 150.00"
|
||||
})
|
||||
@DisplayName("discount applied correctly")
|
||||
void applyDiscount(BigDecimal price, int pct, BigDecimal expected) {
|
||||
assertThat(PricingUtils.discount(price, pct)).isEqualByComparingTo(expected);
|
||||
}
|
||||
```
|
||||
|
||||
## 統合テスト
|
||||
|
||||
Testcontainers を使用した実データベース統合:
|
||||
|
||||
```java
|
||||
@Testcontainers
|
||||
class OrderRepositoryIT {
|
||||
|
||||
@Container
|
||||
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16");
|
||||
|
||||
private OrderRepository repository;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
var dataSource = new PGSimpleDataSource();
|
||||
dataSource.setUrl(postgres.getJdbcUrl());
|
||||
dataSource.setUser(postgres.getUsername());
|
||||
dataSource.setPassword(postgres.getPassword());
|
||||
repository = new JdbcOrderRepository(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
void save_and_findById() {
|
||||
var saved = repository.save(new Order(null, "Bob", BigDecimal.ONE));
|
||||
var found = repository.findById(saved.getId());
|
||||
assertThat(found).isPresent();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Spring Boot 統合テストについては、スキル: `springboot-tdd` を参照してください。
|
||||
Quarkus 統合テストについては、スキル: `quarkus-tdd` を参照してください。
|
||||
|
||||
## テスト命名
|
||||
|
||||
`@DisplayName` を使った説明的な名前:
|
||||
- メソッド名には `methodName_scenario_expectedBehavior()`
|
||||
- レポート用に `@DisplayName("人間が読める説明")`
|
||||
|
||||
## カバレッジ
|
||||
|
||||
- 行カバレッジ 80% 以上を目標
|
||||
- カバレッジレポートには JaCoCo を使用
|
||||
- サービスとドメインロジックに集中する — 自明な getter/設定クラスはスキップ
|
||||
|
||||
## リファレンス
|
||||
|
||||
スキル: `springboot-tdd` で MockMvc と Testcontainers を使った Spring Boot TDD パターンを参照してください。
|
||||
スキル: `quarkus-tdd` で REST Assured と Dev Services を使った Quarkus TDD パターンを参照してください。
|
||||
スキル: `java-coding-standards` でテスト要件を参照してください。
|
||||
Reference in New Issue
Block a user