Source profileQuality 66/100

github/awesome-copilot/skills/java-refactoring-extract-method/SKILL.md

java-refactoring-extract-method

Refactoring using Extract Methods in Java Language

Source repository stars
37,126
Declared platforms
0
Static risk flags
0
Last source update
2026-07-28
Source checked
2026-07-28

Decision brief

What it does—and where it fits

Refactoring using Extract Methods in Java Language

Best for

    Not for

    • Tasks that require unconfirmed production actions or broad system permissions.
    • Environments where the pinned source and install steps cannot be inspected.

    Compatibility matrix

    Platform support, with evidence labels

    PlatformStatusEvidenceWhat to check
    CodexNot declaredNo explicit evidencePortability before use
    Claude CodeNot declaredNo explicit evidencePortability before use
    CursorNot declaredNo explicit evidencePortability before use
    Gemini CLINot declaredNo explicit evidencePortability before use
    Open the compatibility checker

    Installation

    Inspect first. Install second.

    The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

    Source-detected install commandSource
    npx skills add https://github.com/github/awesome-copilot --skill "skills/java-refactoring-extract-method"
    Safe inspection promptEditorial

    Inspect the Agent Skill "java-refactoring-extract-method" from https://github.com/github/awesome-copilot/blob/9933dcad5be5caeb288cebcd370eeeb2fc2f1685/skills/java-refactoring-extract-method/SKILL.md at commit 9933dcad5be5caeb288cebcd370eeeb2fc2f1685. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

    Workflow

    What the source asks the agent to do

    1. 01

      Role

      You are an expert in refactoring Java methods.

      You are an expert in refactoring Java methods.Below are 2 examples (with titles code before and code after refactoring) that represents Extract Method.
    2. 02

      Code Before Refactoring 1:

      Review the “Code Before Refactoring 1:” section in the pinned source before continuing.

      Review and apply the “Code Before Refactoring 1:” source section.
    3. 03

      Code After Refactoring 1:

      Review the “Code After Refactoring 1:” section in the pinned source before continuing.

      Review and apply the “Code After Refactoring 1:” source section.
    4. 04

      Code Before Refactoring 2:

      Review the “Code Before Refactoring 2:” section in the pinned source before continuing.

      Review and apply the “Code Before Refactoring 2:” source section.

    Permission review

    Static risk signals and limitations

    No configured static risk pattern was detected

    This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.

    Evidence record

    Why each signal appears

    EvidenceSourceComputedTestedEditorial
    SignalValueEvidence typeMeaning
    Quality score66/100ComputedDocumentation, specificity, maintenance, and trust rules
    Repository stars37,126SourceRepository attention, not individual Skill quality
    Compatibility0 platformsSourceDeclared in the catalog source record
    Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

    Pinned source

    Provenance and original SKILL.md

    Repository
    github/awesome-copilot
    Skill path
    skills/java-refactoring-extract-method/SKILL.md
    Commit
    9933dcad5be5caeb288cebcd370eeeb2fc2f1685
    License
    MIT
    Collected
    2026-07-28
    Default branch
    main
    View the original SKILL.md

    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

    Alternatives

    Compare before choosing