$npx -y skills add github/awesome-copilot --skill java-refactoring-remove-parameterRefactoring using Remove Parameter in Java Language
| 1 | # Refactoring Java Methods with Remove Parameter |
| 2 | |
| 3 | ## Role |
| 4 | |
| 5 | You are an expert in refactoring Java methods. |
| 6 | |
| 7 | Below are **2 examples** (with titles code before and code after refactoring) that represents **Remove Parameter**. |
| 8 | |
| 9 | ## Code Before Refactoring 1: |
| 10 | ```java |
| 11 | public Backend selectBackendForGroupCommit(long tableId, ConnectContext context, boolean isCloud) |
| 12 | throws LoadException, DdlException { |
| 13 | if (!Env.getCurrentEnv().isMaster()) { |
| 14 | try { |
| 15 | long backendId = new MasterOpExecutor(context) |
| 16 | .getGroupCommitLoadBeId(tableId, context.getCloudCluster(), isCloud); |
| 17 | return Env.getCurrentSystemInfo().getBackend(backendId); |
| 18 | } catch (Exception e) { |
| 19 | throw new LoadException(e.getMessage()); |
| 20 | } |
| 21 | } else { |
| 22 | return Env.getCurrentSystemInfo() |
| 23 | .getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster(), isCloud)); |
| 24 | } |
| 25 | } |
| 26 | ``` |
| 27 | |
| 28 | ## Code After Refactoring 1: |
| 29 | ```java |
| 30 | public Backend selectBackendForGroupCommit(long tableId, ConnectContext context) |
| 31 | throws LoadException, DdlException { |
| 32 | if (!Env.getCurrentEnv().isMaster()) { |
| 33 | try { |
| 34 | long backendId = new MasterOpExecutor(context) |
| 35 | .getGroupCommitLoadBeId(tableId, context.getCloudCluster()); |
| 36 | return Env.getCurrentSystemInfo().getBackend(backendId); |
| 37 | } catch (Exception e) { |
| 38 | throw new LoadException(e.getMessage()); |
| 39 | } |
| 40 | } else { |
| 41 | return Env.getCurrentSystemInfo() |
| 42 | .getBackend(selectBackendForGroupCommitInternal(tableId, context.getCloudCluster())); |
| 43 | } |
| 44 | } |
| 45 | ``` |
| 46 | |
| 47 | ## Code Before Refactoring 2: |
| 48 | ```java |
| 49 | NodeImpl( long id, long firstRel, long firstProp ) |
| 50 | { |
| 51 | this( id, false ); |
| 52 | } |
| 53 | ``` |
| 54 | |
| 55 | ## Code After Refactoring 2: |
| 56 | ```java |
| 57 | NodeImpl( long id) |
| 58 | { |
| 59 | this( id, false ); |
| 60 | } |
| 61 | ``` |
| 62 | |
| 63 | ## Task |
| 64 | |
| 65 | Apply **Remove Parameter** to improve readability, testability, maintainability, reusability, modularity, cohesion, low coupling, and consistency. |
| 66 | |
| 67 | Always return a complete and compilable method (Java 17). |
| 68 | |
| 69 | Perform intermediate steps internally: |
| 70 | - 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). |
| 71 | - For each qualifying method, remove the unnecessary parameters from its definition and from all its internal calls. |
| 72 | - Ensure that the method continues to function correctly after parameter removal. |
| 73 | - Output only the refactored code inside a single ```java``` block. |
| 74 | - Do not remove any functionality from the original method. |
| 75 | - Include a one-line comment above each modified method indicating which parameter was removed and why. |
| 76 | |
| 77 | ## Code to be Refactored: |
| 78 | |
| 79 | Now, assess all methods with unused parameters and refactor them using **Remove Parameter** |