redhat-developer / redhat-developer/vscode-java

Inline Method leaves unqualified instance method call inside local class when inlining into static context

Đang mở
#4,464 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug
Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
546
Merge trung bình
20 giờ 1 phút
Pull request đã merge (30 ngày)
11

Mô tả

Description

Inline Method produces uncompilable code when inlining an instance method that contains a local class into the static method main.

Before refactoring, the local class H is declared inside the instance method f(). The call helper() inside H.g() is valid because it is implicitly bound to the enclosing I01 instance.

After applying Inline Method to the invocation obj.f(), the local class H is moved into the static method main. However, the call inside H.g() remains:

return helper();

At this point, there is no implicit I01.this available in the static context. The call should be qualified with the original receiver, for example:

return obj.helper();

The refactored code no longer compiles.

Code before refactoring

public class I01 {
    public static void main(String[] args) {
        I01 obj = new I01();

        // Refactoring operation: Inline Method
        // Target invocation: obj.f()
        int result = obj.f();

        System.out.println(result);
    }

    int helper() {
        return 7;
    }

    int f() {
        class H {
            int g() {
                return helper();
            }
        }

        return H.class.getSimpleName().length();
    }
}

Code after refactoring

public class I01 {
    public static void main(String[] args) {
        I01 obj = new I01();

        class H {
            int g() {
                return helper();
            }
        }

        // Refactoring operation: Inline Method
        // Target invocation: obj.f()
        int result = H.class.getSimpleName().length();

        System.out.println(result);
    }

    int helper() {
        return 7;
    }

    int f() {
        class H {
            int g() {
                return helper();
            }
        }

        return H.class.getSimpleName().length();
    }
}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với phần triển khai Inline Method và tái hiện vấn đề bằng ví dụ I01, tập trung vào các lớp cục bộ được chuyển vào các ngữ cảnh main static. Theo dõi cách receiver của obj.f() ban đầu được xử lý bên trong H.g(); hoàn tất khi lệnh gọi helper() được tạo ra có receiver làm tiền tố và mã Java đã refactor biên dịch được.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.