java-refactorlisted
Install: claude install-skill limited-grisaille833/claude-java-plugins
Refactor the Java code I've selected or provided. Follow these steps:
## Step 1 — Detect Java version
Check `pom.xml` (`<java.version>` or `<maven.compiler.source>`) or `build.gradle` (`sourceCompatibility`). If not found, ask: "What Java version are you targeting? (8, 11, 17, 21, or other)"
## Step 2 — Apply safe refactorings (all Java versions)
These refactorings are safe regardless of Java version:
- **Extract method:** if a method is longer than 20 lines or has a distinct sub-step, extract it with a descriptive name
- **Rename for clarity:** rename variables, methods, or classes with unclear names
- **Remove duplication:** identify repeated logic blocks and extract to a shared method
- **Replace magic literals:** replace inline numbers/strings with named `static final` constants
- **Simplify conditionals:** replace nested if/else chains with early returns or ternary where clearer
- **Remove dead code:** delete unreachable branches, unused variables, unused imports
## Step 3 — Apply version-gated refactorings (only if target version supports it)
State the minimum Java version required for each suggestion:
- **Java 8+ — Replace anonymous classes with lambdas:** e.g., `new Comparator<String>() { ... }` → `(a, b) -> a.compareTo(b)`
- **Java 8+ — Replace imperative loops with streams:** e.g., for-each + list.add → `list.stream().filter(...).collect(Collectors.toList())`
- **Java 8+ — Use Optional instead of null returns:** e.g., `return null` → `return Optional.empty()`
- *