/java-kotlin-development:java-refactoring-extract-methodfrom java-kotlin-development
Refactors Java 17 methods using Extract Method technique to improve readability and testability. Identifies long or complex methods and extracts focused helper methods while preserving behavior.
Ships in java-kotlin-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze Java 17 methods for extractable responsibilities, then return behavior-preserving code that introduces focused helper methods with descriptive names while keeping the refactored method complete and compilable.
Refactor only methods that exceed at least one threshold, unless the user explicitly requests extraction for a smaller method.
| Metric | Threshold | What to inspect |
|---|---|---|
| LOC | > 15 | Executable method lines, excluding blank lines and comments. |
| NOM | > 10 | Number of statements, including assignments, returns, calls, and control statements. |
| CC | > 10 | Branching from if, else if, loops, catch, case, ternaries, and boolean operators. |
Prefer extraction candidates that are cohesive and nameable: validation, conversion, lookup, branch-specific construction, collection copying, error handling, or object creation.
| Rule | Apply it | Avoid |
|---|---|---|
| Preserve behavior | Keep return values, exceptions, side effects, ordering, null semantics, and visibility constraints. | Changing a guard clause from > to >= or swallowing an exception. |
| Use descriptive helper names | Name helpers after intent, such as bpartnerIdIfNotNull or newExpander. | handleStuff, processData, or names that reveal implementation only. |
| Keep helpers focused | One helper should perform one coherent operation and accept only needed parameters. | Extracting a helper that still contains unrelated branches. |
| Control coupling | Pass values explicitly; use instance state only when the original method already depends on it. | Introducing mutable fields to share temporary state. |
Return complete java code | Include the refactored original method and every new helper needed to compile. | Returning only a diff fragment. |
| Comment new helpers | Add a one-line comment above each new method describing its purpose. | Commenting obvious statements inside the method body. |
Before
public FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerId) {
assertNotBuild();
if (bpartnerId > 0) {
setC_BPartner_ID(bpartnerId);
}
return this;
}
After
// Applies the partner id when a valid domain id is available.
public FactLineBuilder bpartnerIdIfNotNull(final BPartnerId bpartnerId) {
if (bpartnerId != null) {
return bpartnerId(bpartnerId);
} else {
return this;
}
}
public FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerRepoId) {
return bpartnerIdIfNotNull(BPartnerId.ofRepoIdOrNull(bpartnerRepoId));
}
Before
public DefaultExpander add(RelationshipType type, Direction direction) {
Direction existingDirection = directions.get(type.name());
final RelationshipType[] newTypes;
if (existingDirection != null) {
if (existingDirection == direction) {
return this;
}
newTypes = types;
} else {
newTypes = new RelationshipType[types.length + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
newTypes[types.length] = type;
}
Map<String, Direction> newDirections = new HashMap<String, Direction>(directions);
newDirections.put(type.name(), direction);
return new DefaultExpander(newTypes, newDirections);
}
After
public DefaultExpander add(RelationshipType type, Direction direction) {
Direction existingDirection = directions.get(type.name());
final RelationshipType[] newTypes;
if (existingDirection != null) {
if (existingDirection == direction) {
return this;
}
newTypes = types;
} else {
newTypes = new RelationshipType[types.length + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
newTypes[types.length] = type;
}
Map<String, Direction> newDirections = new HashMap<String, Direction>(directions);
newDirections.put(type.name(), direction);
return (DefaultExpander) newExpander(newTypes, newDirections);
}
// Creates the expander instance for the updated type and direction state.
protected RelationshipExpander newExpander(RelationshipType[] types,
Map<String, Direction> directions) {
return new DefaultExpander(types, directions);
}
## Java extract-method result
**Status:** refactored | no qualifying method | blocked
**Thresholds checked:** LOC > 15, NOM > 10, CC > 10
**Methods changed:** <method names>
```java
<complete compilable refactored method and helper methods>
```
### Notes
- <behavior preservation or validation note>
## Output template exactly.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin java-kotlin-development8 skills in this plugin
/create-spring-boot-kotlin-projectCreate a Spring Boot Kotlin project skeleton from Spring Initializr with Gradle Kotlin DSL, Java 21, WebFlux, reactive data dependencies, SpringDoc, ArchUnit, and local Redis/PostgreSQL/MongoDB Docker services. Use when asked to create or scaffold a Spring Boot Kotlin project./java-add-graalvm-native-image-supportGraalVM Native Image expert that adds native image support to Java applications, builds the project, analyzes build errors, applies fixes, and iterates until successful compilation using Oracle best practices. Use this skill when the user asks for graalvm native image agent./java-helidonOther plugins' skills for the same job