Claude Marketplaces
SkillsMCP serversMarketplacesDigestTools
Submit

This week in Claude

Every Monday: Claude Code, Agent SDK, MCP, and the Anthropic platform moves worth your time.

Skills by category
Frontend DevelopmentBackend & APIsTesting & QASecurityDevOps & CI/CDGit & Pull RequestsDocumentationCode Review & QualityAI & Agent BuildingSkill Development
MCP servers by category
Sales & MarketingWeb & Browser AutomationDatabasesAI & LLM ToolsCloud & InfrastructureCommunication & MessagingDeveloper ToolsDesign & CreativeDocuments & KnowledgeSearch & Web Crawling
Marketplaces by category
AI Agents & OrchestrationLLM IntegrationDevelopment ToolsFrontend & UIBackend & APIsDatabasesTesting & Code QualityDevOps & CloudSecurity & ComplianceGit & Version Control
Claude Marketplaces

An independent directory of skills, plugins and MCP servers for Claude Code. Not affiliated with Anthropic.

Browse

  • Skills
  • MCP servers
  • Marketplaces
  • Weekly digest
  • Skill index
  • MCP index
  • Marketplace index

Site

  • About
  • Tools
  • Submit
  • Feedback
  • Privacy
  • llms.txt
  • Plugins reference

Maker

  • Snug
  • Agent Caffeine
  • knobs
  • Wax
  • Vectoys
  • mertduzgun.com
Crafted at
Skills/Git & Pull Requests
github avatar

Java Refactoring Extract Method

github/awesome-copilotOfficial

Claude Code's java-refactoring-extract-method skill guides developers through applying the Extract Method refactoring pattern to Java code, helping them break down complex or lengthy methods into smaller, more focused ones. It targets Java developers working on code maintenance and improvement, providing concrete before-and-after examples to demonstrate how extraction improves readability, testability, and reusability. The skill solves the problem of bloated methods by identifying candidates that exceed complexity thresholds and systematically extracting cohesive logic into separate, compilable methods.

installs
9.3K
GitHub stars
40.5K
last updated
Aug 21, 2026
View on GitHubSave

Install

$ npx -y skills add github/awesome-copilot --skill java-refactoring-extract-method --agent claude-code

Installs into .claude/skills of the current project.

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);
}

Safety Rules

  • Behaviour-preserving only: no functional change, no removed logic, no changed exceptions, side-effect order or visibility of the original method.
  • Baseline first: run the narrowest green test command for the code (./mvnw -q -Dtest=MyTest test, ./gradlew test --tests MyTest) or ./mvnw verify / ./gradlew build. Re-run it after every extraction. If the baseline is red, stop and report.
  • If the code has no tests, stop and report; propose characterization tests first. Never delete or weaken tests.
  • One extraction per step (one commit each when the user asks for commits) so each is reviewable and revertible.
  • Prefer the IDE refactoring: use an available IDE tool that exposes Extract Method (it handles parameters and return values safely). The Copilot CLI lsp tool offers navigation and rename but no code actions, so configuring jdtls through lsp-setup does not provide it; otherwise extract by hand and validate with the compiler and tests.
  • Extracted methods are private by default. Do not add public/protected methods, change the existing signature, or touch generated code (target/, build/generated, @Generated) without asking the user.
  • Watch for: local variables modified in the block (return a value or introduce a small result type), multiple results, checked exceptions, return/break/continue inside the block, and synchronized/transaction-annotated methods (extracted private methods called on this bypass Spring proxies and AOP).

Task

Apply Extract Method to improve readability, testability, cohesion and consistency.

  1. Identify candidate methods (rough guide: > 15 lines, > 10 statements or cyclomatic complexity > 10) and cohesive blocks inside them.
  2. Extract each block into a descriptively named method, following the existing code style and the project's Java level (check maven.compiler.release / toolchain; do not use newer syntax).
  3. Add a one-line comment above each new method only if its name does not already convey its purpose.
  4. Compile and run the tests; report the methods changed, the commands run and their results.

Output complete, compilable code for each changed method.

Code to be Refactored:

Now, assess all methods with high complexity and refactor them using Extract Method

Sponsors

SnugThe clipboard manager you and your agent can use, safelyAgent CaffeineClose your lid, come back to finished workWaxBlock anything with supervision, without erasing your iPhoneOpen StepsSponsoredFree and open-source skills that make AI coding agents easier to understand, verify, and control.

Details

Repository
github.com/github/awesome-copilot
Categories
Git & Pull Requests, Code Review & Quality, AI & Agent Building, Java & JVM

More from github/awesome-copilot

All 318
  • Breakdown Test9.3K
  • Remember9.3K
  • Add Educational Comments9.2K
  • Breakdown Feature Implementation9.2K
  • Dataverse Python Advanced Patterns9.2K
  • Update Specification9.2K
  • Debian Linux Triage9.2K
  • Rust Mcp Server Generator9.2K
  • Aspnet Minimal Api Openapi9.2K
  • Go Mcp Server Generator9.2K
  • Create Llms9.2K
  • Finnish Humanizer9.2K
  • Power Bi Dax Optimization9.1K
  • Arch Linux Triage9.1K
  • Breakdown Epic Pm9.1K
  • Quasi Coder9.1K
  • Technology Stack Blueprint Generator9K
  • Microsoft Skill Creator9K
  • Snowflake Semanticview9K
  • Vscode Ext Commands9K
  • Fluentui Blazor9K
  • Create Technical Spike9K
  • Aspire9K
  • Finalize Agent Prompt9K

Recommended

More Git & Pull Requests
1github avatarbreakdown-testgithub/awesome-copilotTest Planning and Quality Assurance prompt that generates comprehensive test strategies, task breakdowns, and quality validation plans for GitHub projects.9.3Kinstalls
2github avatarremembergithub/awesome-copilotTransforms lessons learned into domain-organized memory instructions (global or workspace). Syntax: `/remember [>domain [scope]] lesson clue` where scope is `gl9.3Kinstalls
3github avataradd-educational-commentsgithub/awesome-copilotAdd educational comments to the file specified, or prompt asking for file to comment if one is not provided.9.2Kinstalls
4github avatarbreakdown-feature-implementationgithub/awesome-copilotPrompt for creating detailed feature implementation plans, following Epoch monorepo structure.9.2Kinstalls
5github avatardataverse-python-advanced-patternsgithub/awesome-copilotGenerate production code for Dataverse SDK using advanced patterns, error handling, and optimization techniques.9.2Kinstalls
6github avatarupdate-specificationgithub/awesome-copilotUpdate an existing specification file for the solution, optimized for Generative AI consumption based on new requirements or updates to any existing code.9.2Kinstalls