skills/java-refactoring/SKILL.md
Analyze and refactor Java/Spring Boot code for quality, maintainability, and design patterns. Use this skill whenever the user shares Java code and asks to improve it, clean it up, apply design patterns, reduce complexity, fix code smells, or says things like "refactor this", "clean up this class", "this method is too long", "apply SOLID principles", "improve this service", "simplify this code". Always use this skill before suggesting any Java code improvements — it defines the standards and patterns to apply.
npx skillsauth add jyjeanne/ai-setup-forge java-refactoringInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Systematically analyze Java/Spring Boot code and apply targeted refactoring following SOLID principles, clean code practices, and Java idioms.
When given code to refactor, evaluate in this order:
| Smell | Signal | Refactoring |
|-------|--------|-------------|
| Long Method | >20 lines | Extract Method |
| God Class | >300 lines, >10 responsibilities | Extract Class |
| Feature Envy | Method uses another class's data more than its own | Move Method |
| Data Clumps | Same 3+ params repeated | Introduce Parameter Object |
| Primitive Obsession | String for email/phone/status | Value Object / Enum |
| Switch Statements | switch on type field | Strategy or Polymorphism |
| Duplicate Code | Copy-paste blocks | Extract Method / Template Method |
| Long Parameter List | >3-4 params | Builder or Parameter Object |
| Null Checks Everywhere | if (x != null) chains | Optional<T> |
| Mutable State | public setters everywhere | Immutable objects / Builder |
S - Single Responsibility
O - Open/Closed
if/else or switch on type that requires editing when adding new typesL - Liskov Substitution
UnsupportedOperationExceptionI - Interface Segregation
UnsupportedOperationExceptionD - Dependency Inversion
new ConcreteService() inside a class, no constructor injection@Autowired constructor injectionUse Modern Java (11–21)
// Before
List<String> names = new ArrayList<>();
for (User user : users) {
if (user.isActive()) names.add(user.getName());
}
// After
List<String> names = users.stream()
.filter(User::isActive)
.map(User::getName)
.toList(); // Java 16+
Prefer Optional over null
// Before
User user = userRepository.findById(id);
if (user == null) throw new NotFoundException(...);
// After
User user = userRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("User", id));
Replace magic strings/numbers with constants or enums
// Before
if (user.getRole().equals("ADMIN")) { ... }
// After
if (user.getRole() == Role.ADMIN) { ... }
Constructor injection over field injection
// Before (avoid)
@Autowired
private UserService userService;
// After (prefer)
private final UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
For each refactoring, provide:
When multiple issues exist, fix in this order:
development
Generate breadboard circuit mockups and visual diagrams using HTML5 Canvas drawing techniques. Use when asked to create circuit layouts, visualize electronic component placements, draw breadboard diagrams, mockup 6502 builds, generate retro computer schematics, or design vintage electronics projects. Supports 555 timers, W65C02S microprocessors, 28C256 EEPROMs, W65C22 VIA chips, 7400-series logic gates, LEDs, resistors, capacitors, switches, buttons, crystals, and wires.
development
Apply lean thinking to UX: hypothesis-driven design, collaborative sketching, and rapid experiments instead of heavy deliverables. Use when the user mentions "Lean UX", "design hypothesis", "UX experiment", "collaborative design", or "outcome over output". Covers hypothesis statements, MVPs for UX, and cross-functional collaboration. For Build-Measure-Learn, see lean-startup. For usability audits, see ux-heuristics.
development
Design MVPs, validated learning experiments, and pivot-or-persevere decisions using Build-Measure-Learn. Use when the user mentions "MVP scope", "validated learning", "pivot or persevere", "vanity metrics", or "test assumptions". Covers innovation accounting and actionable metrics. For 5-day prototype testing, see design-sprint. For customer motivation analysis, see jobs-to-be-done.
tools
Instrument, trace, evaluate, and monitor LLM applications and AI agents with LangSmith. Use when setting up observability for LLM pipelines, running offline or online evaluations, managing prompts in the Prompt Hub, creating datasets for regression testing, or deploying agent servers. Triggers on: langsmith, langchain tracing, llm tracing, llm observability, llm evaluation, trace llm calls, @traceable, wrap_openai, langsmith evaluate, langsmith dataset, langsmith feedback, langsmith prompt hub, langsmith project, llm monitoring, llm debugging, llm quality, openevals, langsmith cli, langsmith experiment, annotate llm, llm judge.