Skip to content

Commit ca37fc8

Browse files
Upload a new java refactoring, remove parameter (#335)
* Upload a new java refactoring, remove parameter * fixing up from merge --------- Co-authored-by: Aaron Powell <[email protected]>
1 parent 17ef59b commit ca37fc8

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

README.prompts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi
9797
| [Project Workflow Documentation Generator](prompts/project-workflow-analysis-blueprint-generator.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fproject-workflow-analysis-blueprint-generator.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fproject-workflow-analysis-blueprint-generator.prompt.md) | Comprehensive technology-agnostic prompt generator for documenting end-to-end application workflows. Automatically detects project architecture patterns, technology stacks, and data flow patterns to generate detailed implementation blueprints covering entry points, service layers, data access, error handling, and testing approaches across multiple technologies including .NET, Java/Spring, React, and microservices architectures. |
9898
| [README Generator Prompt](prompts/readme-blueprint-generator.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freadme-blueprint-generator.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freadme-blueprint-generator.prompt.md) | Intelligent README.md generation prompt that analyzes project documentation structure and creates comprehensive repository documentation. Scans .github/copilot directory files and copilot-instructions.md to extract project information, technology stack, architecture, development workflow, coding standards, and testing approaches while generating well-structured markdown documentation with proper formatting, cross-references, and developer-focused content. |
9999
| [Refactoring Java Methods with Extract Method](prompts/java-refactoring-extract-method.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-extract-method.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-extract-method.prompt.md) | Refactoring using Extract Methods in Java Language |
100+
| [Refactoring Java Methods with Remove Parameter](prompts/java-refactoring-remove-parameter.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-remove-parameter.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-remove-parameter.prompt.md) | Refactoring using Remove Parameter in Java Language |
100101
| [Repo Story Time](prompts/repo-story-time.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Frepo-story-time.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Frepo-story-time.prompt.md) | Generate a comprehensive repository summary and narrative story from commit history |
101102
| [Review And Refactor](prompts/review-and-refactor.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freview-and-refactor.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freview-and-refactor.prompt.md) | Review and refactor code in your project according to defined instructions |
102103
| [Ruby MCP Server Generator](prompts/ruby-mcp-server-generator.prompt.md)<br />[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fruby-mcp-server-generator.prompt.md)<br />[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fruby-mcp-server-generator.prompt.md) | Generate a complete Model Context Protocol server project in Ruby using the official MCP Ruby SDK gem. |
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: 'Refactoring Java Methods with Remove Parameter'
3+
mode: 'agent'
4+
description: 'Refactoring using Remove Parameter in Java Language'
5+
---
6+
7+
# Refactoring Java Methods with Remove Parameter
8+
9+
## Role
10+
11+
You are an expert in refactoring Java methods.
12+
13+
Below are **2 examples** (with titles code before and code after refactoring) that represents **Remove Parameter**.
14+
15+
## Code Before Refactoring 1:
16+
```java
17+
public Backend selectBackendForGroupCommit(long tableId, ConnectContext context, boolean isCloud)
18+
throws LoadException, DdlException {
19+
if (!Env.getCurrentEnv().isMaster()) {
20+
try {
21+
long backendId = new MasterOpExecutor(context)
22+
.getGroupCommitLoadBeId(tableId, context.getCloudCluster(), isCloud);
23+
return Env.getCurrentSystemInfo().getBackend(backendId);
24+
} catch (Exception e) {
25+
throw new LoadException(e.getMessage());
26+
}
27+
} else {
28+
return Env.getCurrentSystemInfo()
29+
.getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster(), isCloud));
30+
}
31+
}
32+
```
33+
34+
## Code After Refactoring 1:
35+
```java
36+
public Backend selectBackendForGroupCommit(long tableId, ConnectContext context)
37+
throws LoadException, DdlException {
38+
if (!Env.getCurrentEnv().isMaster()) {
39+
try {
40+
long backendId = new MasterOpExecutor(context)
41+
.getGroupCommitLoadBeId(tableId, context.getCloudCluster());
42+
return Env.getCurrentSystemInfo().getBackend(backendId);
43+
} catch (Exception e) {
44+
throw new LoadException(e.getMessage());
45+
}
46+
} else {
47+
return Env.getCurrentSystemInfo()
48+
.getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster()));
49+
}
50+
}
51+
```
52+
53+
## Code Before Refactoring 2:
54+
```java
55+
NodeImpl( long id, long firstRel, long firstProp )
56+
{
57+
this( id, false );
58+
}
59+
```
60+
61+
## Code After Refactoring 2:
62+
```java
63+
NodeImpl( long id)
64+
{
65+
this( id, false );
66+
}
67+
```
68+
69+
## Task
70+
71+
Apply **Remove Parameter** to improve readability, testability, maintainability, reusability, modularity, cohesion, low coupling, and consistency.
72+
73+
Always return a complete and compilable method (Java 17).
74+
75+
Perform intermediate steps internally:
76+
- 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).
77+
- For each qualifying method, remove the unnecessary parameters from its definition and from all its internal calls.
78+
- Ensure that the method continues to function correctly after parameter removal.
79+
- Output only the refactored code inside a single ```java``` block.
80+
- Do not remove any functionality from the original method.
81+
- Include a one-line comment above each modified method indicating which parameter was removed and why.
82+
83+
## Code to be Refactored:
84+
85+
Now, assess all methods with unused parameters and refactor them using **Remove Parameter**

0 commit comments

Comments
 (0)