
Java Refactoring Extract Method
- 9.1k installs
- 37.1k repo stars
- Updated July 28, 2026
- github/awesome-copilot
java-refactoring-extract-method is an agent skill that Refactoring using Extract Methods in Java Language.
About
Refactoring using Extract Methods in Java Language name java-refactoring-extract-method description Refactoring using Extract Methods in Java Language Refactoring Java Methods with Extract Method Role You are an expert in refactoring Java methods Below are 2 examples with titles code before and code after refactoring that represents Extract Method Code Before Refactoring 1 java public FactLineBuilder setC_BPartner_ID_IfValid final int bpartnerId assertNotBuild if bpartnerId 0 setC_BPartner_ID bpartnerId return this Code After Refactoring 1 java 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 Code Before Refactoring 2 java 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 new.
- Refactoring Java Methods with Extract Method
- First, analyze each method and identify those exceeding thresholds:
- LOC (Lines of Code) > 15
- NOM (Number of Statements) > 10
- CC (Cyclomatic Complexity) > 10
Java Refactoring Extract Method by the numbers
- 9,078 all-time installs (skills.sh)
- +45 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #117 of 2,184 Testing & QA skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
java-refactoring-extract-method capabilities & compatibility
- Capabilities
- refactoring java methods with extract method · first, analyze each method and identify those ex · loc (lines of code) > 15 · nom (number of statements) > 10 · cc (cyclomatic complexity) > 10
- Use cases
- documentation
What java-refactoring-extract-method says it does
Below are **2 examples** (with titles code before and code after refactoring) that represents **Extract Method**.
Always return a complete and compilable method (Java 17).
- Extract at least one new method with a descriptive name.
- Output only the refactored code inside a single ```java``` block.
npx skills add https://github.com/github/awesome-copilot --skill java-refactoring-extract-methodAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 9.1k |
|---|---|
| repo stars | ★ 37.1k |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 28, 2026 |
| Repository | github/awesome-copilot ↗ |
What problem does java-refactoring-extract-method solve for developers using this skill?
Refactoring using Extract Methods in Java Language
Who is it for?
Developers who need java-refactoring-extract-method patterns described in the cached skill documentation.
Skip if: Skip when docs are empty or the task is outside the skill's documented scope.
When should I use this skill?
Refactoring using Extract Methods in Java Language
What you get
Actionable workflows and conventions from SKILL.md for java-refactoring-extract-method.
- Refactored Java source files
By the numbers
- Documents 2 before-and-after Extract Method refactoring examples
Files
Refactoring Java Methods with Extract Method
Role
You are an expert in refactoring Java methods.
Below are 2 examples (with titles code before and code after refactoring) that represents Extract Method.
Code Before Refactoring 1:
public FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerId) {
assertNotBuild();
if (bpartnerId > 0) {
setC_BPartner_ID(bpartnerId);
}
return this;
}Code After Refactoring 1:
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));
}Code Before Refactoring 2:
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);
}Code After Refactoring 2:
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);
}
protected RelationshipExpander newExpander(RelationshipType[] types,
Map<String, Direction> directions) {
return new DefaultExpander(types, directions);
}Task
Apply Extract Method to improve readability, testability, maintainability, reusability, modularity, cohesion, low coupling, and consistency.
Always return a complete and compilable method (Java 17).
Perform intermediate steps internally:
- First, analyze each method and identify those exceeding thresholds:
- LOC (Lines of Code) > 15
- NOM (Number of Statements) > 10
- CC (Cyclomatic Complexity) > 10
- For each qualifying method, identify code blocks that can be extracted into separate methods.
- Extract at least one new method with a descriptive name.
- Output only the refactored code inside a single ``
java`` block. - Do not remove any functionality from the original method.
- Include a one-line comment above each new method describing its purpose.
Code to be Refactored:
Now, assess all methods with high complexity and refactor them using Extract Method
Related skills
How it compares
Use java-refactoring-extract-method for localized Java method extraction; use broader architecture skills when the problem is service boundaries not method length.
FAQ
What does java-refactoring-extract-method do?
Refactoring using Extract Methods in Java Language
When should I use java-refactoring-extract-method?
Refactoring using Extract Methods in Java Language
Is java-refactoring-extract-method safe to install?
Review the Security Audits panel on this page before installing in production.