Java Refactoring: Remove Parameter

Java Refactoring: Remove Parameter

Refactors Java methods by removing unused or redundant parameters, guided by two before-and-after code examples.

Skill files1 file
SKILL.md95 lines
1
---
2
name: java-refactoring-remove-parameter
3
description: 'Refactoring using Remove Parameter in Java Language'
4
---
5
6
# Refactoring Java Methods with Remove Parameter
7
8
## Role
9
10
You are an expert in refactoring Java methods.
11
12
Below are **2 examples** (with titles code before and code after refactoring) that represents **Remove Parameter**.
13
14
## Code Before Refactoring 1:
15
```java
16
public Backend selectBackendForGroupCommit(long tableId, ConnectContext context, boolean isCloud)
17
throws LoadException, DdlException {
18
if (!Env.getCurrentEnv().isMaster()) {
19
try {
20
long backendId = new MasterOpExecutor(context)
21
.getGroupCommitLoadBeId(tableId, context.getCloudCluster(), isCloud);
22
return Env.getCurrentSystemInfo().getBackend(backendId);
23
} catch (Exception e) {
24
throw new LoadException(e.getMessage());
25
}
26
} else {
27
return Env.getCurrentSystemInfo()
28
.getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster(), isCloud));
29
}
30
}
31
```
32
33
## Code After Refactoring 1:
34
```java
35
public Backend selectBackendForGroupCommit(long tableId, ConnectContext context)
36
throws LoadException, DdlException {
37
if (!Env.getCurrentEnv().isMaster()) {
38
try {
39
long backendId = new MasterOpExecutor(context)
40
.getGroupCommitLoadBeId(tableId, context.getCloudCluster());
41
return Env.getCurrentSystemInfo().getBackend(backendId);
42
} catch (Exception e) {
43
throw new LoadException(e.getMessage());
44
}
45
} else {
46
return Env.getCurrentSystemInfo()
47
.getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster()));
48
}
49
}
50
```
51
52
## Code Before Refactoring 2:
53
```java
54
NodeImpl( long id, long firstRel, long firstProp )
55
{
56
this( id, false );
57
}
58
```
59
60
## Code After Refactoring 2:
61
```java
62
NodeImpl( long id)
63
{
64
this( id, false );
65
}
66
```
67
68
## Safety Rules
69
70
- Behaviour-preserving only. Remove a parameter only if it is truly unused or derivable (field, constant, other parameter); never remove one that is read, even if "redundant" by convention.
71
- Baseline first: run the narrowest green test command (`./mvnw -q -Dtest=MyTest test`, `./gradlew test --tests MyTest`) or `./mvnw verify` / `./gradlew build`, and re-run after the change. If the baseline is red, stop and report.
72
- If the affected code has no tests, stop and report; propose characterization tests first. Never delete or weaken tests.
73
- Find every usage before changing a signature: use LSP find-references (`lsp-setup`/jdtls) and grep across all modules, including tests. Also check:
74
- overrides and interface implementors (`@Override`, abstract/default methods, functional interfaces, method references): the whole hierarchy must change together;
75
- reflection and string-based lookups (`getMethod`, `getDeclaredMethod`, `MethodHandle`, proxies), and Spring/CDI/Quarkus/Jakarta annotated methods (`@Bean`, `@EventListener`, `@Scheduled`, `@Inject`, `@Path`, `@Observes`, `@PostConstruct`), which a compiler will not flag;
76
- constructors used by serialization/deserialization or JPA/Jackson (`@JsonCreator`, `@ConstructorBinding`, `readObject`), and `serialVersionUID` impact;
77
- XML/properties/YAML configuration and AOP pointcut expressions naming the method;
78
- public or protected API consumed by other modules or published artifacts.
79
- Ask the user before changing public/protected/published API (prefer deprecating and adding an overload) or touching generated code.
80
- One parameter per step (one commit each when the user asks for commits). Prefer the jdtls Change Method Signature refactoring when available; otherwise update the declaration and all callers together.
81
- Removing a parameter can make an overload collide with an existing signature or change overload resolution; check this. Evaluating the argument at the call site may have had side effects: keep them if they matter.
82
83
## Task
84
85
Apply **Remove Parameter** to improve readability, coupling and consistency.
86
87
1. Identify unused or derivable parameters.
88
2. Remove each from the declaration and from all callers, then compile and run the tests.
89
3. Add a one-line comment only where the removal is non-obvious; otherwise explain it in the report.
90
4. Report parameters removed, callers updated, the commands run and their results, and anything left unverified (e.g. reflective or external callers).
91
92
## Code to be Refactored:
93
94
Now, assess all methods with unused parameters and refactor them using **Remove Parameter**
95

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…