Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`AddMissingMethodImplementation` generates wrong method for constructors

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với bản tái hiện AddMissingMethodImplementationTest được cung cấp và kiểm tra AddMissingMethodImplementation để xem các mẫu phương thức constructor được kết xuất như thế nào. Chạy bài kiểm thử được tham số hóa cho cả hai mẫu phương thức; hoàn tất khi constructor được tạo có tên là ImplementationClass, không có kiểu trả về Template không chính xác và khớp với mã dự kiến.

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

Mô tả

bug java

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v8.9.4
  • Maven/Gradle plugin RELEASE
  • rewrite-migrate-java v2.3.0

How are you running OpenRewrite?

I'm applying rules using the maven plugin and a custom recipe artifact

What is the smallest, simplest way to reproduce the problem?

package org.openrewrite.java.migrate;

import org.intellij.lang.annotations.Language;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

class AddMissingMethodImplementationTest implements RewriteTest {

    @ParameterizedTest
    @ValueSource(strings = {
      "*..* <constructor>(String)",
      "org.openrewrite.example.ImplementationClass <constructor>(String)",
    })
    void addMissingConstructor(String methodPattern) {
        @Language("java")
        final String abstractClassTemplate = """
          package org.openrewrite.example;

          public abstract class AbstractClass {
              private final String param;
              
              protected AbstractClass(String param) {
                  this.param = param;
              }
              
              public String getParam() {
                  return param;
              }
          }
          """;

        @Language("java")
        final String originalClass = """
          package org.openrewrite.example;

          public class ImplementationClass extends AbstractClass {
          }
          """;

        @Language("java")
        final String expected = """
          package org.openrewrite.example;
                    
          public class ImplementationClass extends AbstractClass {
                    
              public ImplementationClass(String param) {
                  super(param);
              }
          }
          """;

        rewriteRun(
          spec -> spec
            .parser(JavaParser.fromJavaVersion().dependsOn(abstractClassTemplate))
            .recipe(new AddMissingMethodImplementation(
              "org.openrewrite.example.AbstractClass",
              methodPattern,
              """
                public ImplementationClass(String param) {
                    super(param);
                }"""
            )),
          java(originalClass, expected)
        );
    }
}

What did you expect to see?

package org.openrewrite.example;
  
public class ImplementationClass extends AbstractClass {
    public ImplementationClass(String param) {
        super(param);
    }
}

What did you see instead?

 package org.openrewrite.example;
 
 public class ImplementationClass extends AbstractClass {
-    public ImplementationClass(String param) {
+    public Template ImplementationClass(String param) {
         super(param);
     }
 }

What is the full stack trace of any errors you encountered?

recipe completes successfully

Are you interested in contributing a fix to OpenRewrite?

Ngôn ngữ chính
Java
Star
156
Fork
129
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

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.

Issue khác của openrewrite/rewrite-migrate-java

Tất cả issue của openrewrite/rewrite-migrate-java

Issue tương tự

Thêm issue về Java

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.