java-refactoring-remove-parameter
它能做什么
这个工具可以帮你清理 Java 代码,删除传入函数但实际没有用到的信息。这能让代码更易理解和使用。
适用场景
- ✓当函数接收了它并不使用的数据时。
- ✓当函数的参数太多,需要简化时。
- ✓当你整理代码,想让它更清晰时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/java-refactoring-remove-parameter/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“从 'selectBackendForGroupCommit' 函数中删除 'isCloud' 参数,因为它没有被使用。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会分析你的 Java 函数,找出没有被使用的参数。然后删除这些参数,并更新代码,使其仍然正常工作,同时结构更简洁。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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
javablock. - 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
常见问题
删除参数为什么能改善代码?
删除不必要的参数后,代码更易阅读、理解和测试,因为需要管理的信息更少了。
修改后代码还能正常运行吗?
可以。目标是只删除未被使用的内容,确保功能保持不变。
这会影响程序的其他部分吗?
如果被修改的函数在其他地方被调用,AI 也会相应调整这些调用,确保所有部分仍能协同工作。
详情
热度
- GitHub 星标
- 40k
- 排名
- #7259
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。