Skip to content

InstanceOfPatternMatch recipe replaces wrapper types with primitives in instanceof #528

Description

@arodionov

It looks like the current PR #489 replacing wrapper types with primitives in instanceof

Test to reproduce (should be added to InstanceOfPatternMatchTest:

@Test
    void matchingPrimitiveVariableInBody() {
        rewriteRun(
          version(
          //language=java
          java(
            """
              public class A {
                  void test(Object o, Integer integer) {
                      if (o instanceof Integer) {
                          for (int j = 0; j < (int) o; j++) {
                          }
                      }
                  }
              }
              """,
            """
              public class A {
                  void test(Object o, Integer integer) {
                      if (o instanceof Integer integer1) {
                          for (int j = 0; j < integer1; j++) {
                          }
                      }
                  }
              }
              """
          ), 17)
        );
    }

The produced code is non-compilable:

public class A {
      void test(Object o, Integer integer) {
          if (o instanceof int integer1) {
              for (int j = 0; j < integer1; j++) {
              }
          }
      }
  } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions