Chuyển đến nội dung
Skillpedia
Lập trình chung40k · #7259

java-refactoring-remove-parameter

Skill này làm gì

Công cụ này giúp dọn dẹp mã Java bằng cách loại bỏ những thông tin không cần thiết được truyền vào hàm. Nhờ vậy mã dễ hiểu và dễ dùng hơn.

Khi nào nên dùng

  • ✓Khi một hàm nhận dữ liệu mà không dùng đến.
  • ✓Khi bạn muốn đơn giản hóa các hàm có quá nhiều đối số.
  • ✓Khi bạn sắp xếp mã để nó rõ ràng hơn.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/java-refactoring-remove-parameter/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/java-refactoring-remove-parameter/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy xóa tham số 'isCloud' khỏi hàm 'selectBackendForGroupCommit' vì nó không được sử dụng.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI phân tích các hàm Java để tìm tham số không được dùng. Sau đó, nó xóa những tham số này và cập nhật mã để mã vẫn hoạt động đúng, nhưng gọn gàng hơn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 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

Câu hỏi thường gặp

Vì sao xóa tham số lại giúp mã tốt hơn?

Bỏ các tham số không cần thiết giúp mã dễ đọc, dễ hiểu và dễ kiểm thử hơn, vì có ít thông tin phải quản lý hơn.

Mã có còn hoạt động sau khi thay đổi không?

Có, mục tiêu là chỉ xóa những gì không được dùng, nên chức năng vẫn giữ nguyên.

Việc này có ảnh hưởng đến các phần khác của chương trình không?

Nếu hàm đã sửa được gọi ở nơi khác, AI cũng sẽ điều chỉnh các lệnh gọi đó để mọi thứ tiếp tục hoạt động cùng nhau.

Chi tiết

Mô tả gốc của tác giả

Refactoring using Remove Parameter in Java Language

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7259
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự