首页/后端开发/java-refactoring-remove-parameter
J

java-refactoring-remove-parameter

by @githubv1.0.0
4.0(0)

在Java语言中使用“移除参数”进行重构,以简化方法签名和代码结构。

Java RefactoringRemove ParameterCode SmellsIDE ToolsGitHub
安装方式
npx skills add github/awesome-copilot --skill java-refactoring-remove-parameter
compare_arrows

Before / After 效果对比

1
使用前

Java方法签名参数过多,导致代码难以阅读和维护,增加调用复杂性。代码结构臃肿,可读性差。

使用后

运用“移除参数”重构技巧,简化Java方法签名和代码结构。显著提升代码可读性和可维护性,降低理解成本。

description SKILL.md


name: java-refactoring-remove-parameter description: 'Refactoring using Remove Parameter in Java Language'

Refactoring Java Methods with Remove Parameter

Role

You are an expert in refactoring Java methods.

Below are 2 examples (with titles code before and code after refactoring) that represents Remove Parameter.

Code Before Refactoring 1:

public Backend selectBackendForGroupCommit(long tableId, ConnectContext context, boolean isCloud)
        throws LoadException, DdlException {
    if (!Env.getCurrentEnv().isMaster()) {
        try {
            long backendId = new MasterOpExecutor(context)
                    .getGroupCommitLoadBeId(tableId, context.getCloudCluster(), isCloud);
            return Env.getCurrentSystemInfo().getBackend(backendId);
        } catch (Exception e) {
            throw new LoadException(e.getMessage());
        }
    } else {
        return Env.getCurrentSystemInfo()
                .getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster(), isCloud));
    }
}

Code After Refactoring 1:

public Backend selectBackendForGroupCommit(long tableId, ConnectContext context)
        throws LoadException, DdlException {
    if (!Env.getCurrentEnv().isMaster()) {
        try {
            long backendId = new MasterOpExecutor(context)
                    .getGroupCommitLoadBeId(tableId, context.getCloudCluster());
            return Env.getCurrentSystemInfo().getBackend(backendId);
        } catch (Exception e) {
            throw new LoadException(e.getMessage());
        }
    } else {
        return Env.getCurrentSystemInfo()
                .getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster()));
    }
}

Code Before Refactoring 2:

NodeImpl( long id, long firstRel, long firstProp )
{
     this( id, false );
}

Code After Refactoring 2:

NodeImpl( long id)
{
     this( id, false );
}

Task

Apply Remove Parameter 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 parameters that are unused or redundant (i.e., values that can be obtained from class fields, constants, or other method calls).
  • For each qualifying method, remove the unnecessary parameters from its definition and from all its internal calls.
  • Ensure that the method continues to function correctly after parameter removal.
  • 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 modified method indicating which parameter was removed and why.

Code to be Refactored:

Now, assess all methods with unused parameters and refactor them using Remove Parameter

forum用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价,来写第一条吧

统计数据

安装量7.0K
评分4.0 / 5.0
版本1.0.0
更新日期2026年3月16日
对比案例1 组

用户评分

4.0(0)
5
0%
4
0%
3
0%
2
0%
1
0%

为此 Skill 评分

0.0

兼容平台

🔧Claude Code
🔧OpenClaw
🔧OpenCode
🔧Codex
🔧Gemini CLI
🔧GitHub Copilot
🔧Amp
🔧Kimi CLI

时间线

创建2026年3月16日
最后更新2026年3月16日