其他

java-refactoring-extract-method

github/awesome-copilot

Refactoring using Extract Methods in Java Language

  • 9304 次安装
  • 4.1万 星标
  • 收录于

安装命令

npx skills add https://github.com/github/awesome-copilot --skill java-refactoring-extract-method

要点

Java method extraction refactoring for improved readability and maintainability.

  • Identifies methods exceeding complexity thresholds (LOC > 15, statements > 10, cyclomatic complexity > 10) and extracts logical code blocks into focused helper methods
  • Produces fully compilable Java 17 code with descriptive method names and single-line documentation comments
  • Preserves all original functionality while reducing cognitive load and improving testability through smaller, single-responsibility methods

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