Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ScopeAwareVisitor extends JavaVisitor<ExecutionContext> {

@Override
public J preVisit(J j, ExecutionContext ctx) {
if (j instanceof J.ClassDeclaration) {
scopes.push(new VariablesInScope(getCursor()));
}
if (j instanceof J.Block) {
scopes.push(new VariablesInScope(getCursor()));
}
Expand All @@ -50,9 +53,15 @@ public J preVisit(J j, ExecutionContext ctx) {

@Override
public J postVisit(J j, ExecutionContext ctx) {
if (j instanceof J.ClassDeclaration) {
scopes.pop();
}
if (j instanceof J.Block) {
scopes.pop();
}
if (j instanceof J.MethodDeclaration) {
scopes.pop();
}
return super.postVisit(j, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,45 @@ public void bar(ZonedDateTime dt) {
);
}

@Test
void migrationWithRecord() {
//language=java
rewriteRun(
java(
"""
import org.joda.time.DateTime;

record A(String x) {
public void foo() {
new Bar().bar(new DateTime());
}

private static class Bar {
public void bar(DateTime dt) {
dt.getMillis();
}
}
}
""",
"""
import java.time.ZonedDateTime;

record A(String x) {
public void foo() {
new Bar().bar(ZonedDateTime.now());
}

private static class Bar {
public void bar(ZonedDateTime dt) {
dt.toInstant().toEpochMilli();
}
}
}
"""
)
);
}

@Test
void migrateMethodWithSafeReturnExpression() {
//language=java
Expand Down
Loading