Voltar ao índice
Ferramentas e automação Fonte oficial

Refatoração Remove Parameter em Java

Orienta a remover parâmetros desnecessários de métodos Java e atualizar as chamadas relacionadas de forma consistente no código.

Ver código no GitHub Instala diretamente do repositório-fonte.

O que esta skill faz

A skill apresenta o padrão Remove Parameter por exemplos de antes e depois. O objetivo é simplificar assinaturas quando um argumento deixou de ser necessário, ajustando chamadas e métodos internos afetados.

Quando usar

  • Remover flags obsoletas de métodos
  • Simplificar APIs internas Java
  • Atualizar chamadas após eliminar um argumento
  • Reduzir parâmetros que não influenciam o comportamento

Como usar

  1. Revise o repositório e encontre a declaração e todas as referências
  2. Confirme que o parâmetro não afeta nenhum caminho de execução
  3. Remova o argumento da assinatura e das chamadas relacionadas
  4. Atualize métodos delegados e testes afetados
  5. Compile e execute os testes para validar o comportamento

O que revisar antes de instalar

  • Não deve remover parâmetros usados direta ou indiretamente
  • APIs públicas podem exigir avaliação de compatibilidade
  • Sobrecargas, reflexão e chamadas externas podem dificultar a busca completa

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:
```java
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:
```java
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:
```java
NodeImpl( long id, long firstRel, long firstProp )
{
     this( id, false );
}
```

## Code After Refactoring 2:
```java
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**