What version of OpenRewrite are you using?
I am using
- Maven plugin v6.3.2
- rewrite-migrate-java v3.4.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.3.2</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.staticanalysis.InstanceOfPatternMatch</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
</plugin>
What is the smallest, simplest way to reproduce the problem?
package org.example;
public class Main {
public enum Foo {}
public static void main(String[] args) {
Object o = new Object();
if (o instanceof Foo) {
Foo e = (Foo) o;
System.out.println(e);
}
}
}
What did you expect to see?
package org.example;
public class Main {
public enum Foo {}
public static void main(String[] args) {
Object o = new Object();
if (o instanceof Foo e) {
System.out.println(e);
}
}
}
What did you see instead?
package org.example;
public class Main {
public enum Foo {}
public static void main(String[] args) {
Object o = new Object();
if (o instanceof Foo e1) {
System.out.println(e);
}
}
}
Note: this behavior seems to be specific to enums, the pattern works fine with regular classes.
What is the full stack trace of any errors you encountered?
The migration succeeds, but if you try to compile the changes afterwards javac fails with
cannot find symbol
[ERROR] symbol: variable e
[ERROR] location: class org.example.Main
If I manage to do so with reasonable effort, yes.
What version of OpenRewrite are you using?
I am using
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?
Note: this behavior seems to be specific to enums, the pattern works fine with regular classes.
What is the full stack trace of any errors you encountered?
The migration succeeds, but if you try to compile the changes afterwards javac fails with
Are you interested in contributing a fix to OpenRewrite?
If I manage to do so with reasonable effort, yes.