@@ -280,6 +280,105 @@ public void bar(ZonedDateTime dt) {
280280 );
281281 }
282282
283+ @ Test
284+ void migrateMethodWithSafeReturnExpression () {
285+ //language=java
286+ rewriteRun (
287+ java (
288+ """
289+ import org.joda.time.DateTime;
290+ import org.joda.time.Interval;
291+
292+ class A {
293+ public DateTime foo(DateTime dt) {
294+ Interval interval = new Interval(dt, dt.plusDays(1));
295+ return interval.getEnd();
296+ }
297+
298+ private static class Bar {
299+ public void bar(DateTime dt) {
300+ DateTime d = foo(dt);
301+ System.out.println(d.getMillis());
302+ }
303+ }
304+ }
305+ """ ,
306+ """
307+ import org.threeten.extra.Interval;
308+
309+ import java.time.ZoneId;
310+ import java.time.ZonedDateTime;
311+
312+ class A {
313+ public ZonedDateTime foo(ZonedDateTime dt) {
314+ Interval interval = Interval.of(dt.toInstant(), dt.plusDays(1).toInstant());
315+ return interval.getEnd().atZone(ZoneId.systemDefault());
316+ }
317+
318+ private static class Bar {
319+ public void bar(ZonedDateTime dt) {
320+ ZonedDateTime d = foo(dt);
321+ System.out.println(d.toInstant().toEpochMilli());
322+ }
323+ }
324+ }
325+ """
326+ )
327+ );
328+ }
329+
330+ @ Test
331+ void migrateMethodWithSafeReturnExpressionAndUnsafeParam () {
332+ //language=java
333+ rewriteRun (
334+ java (
335+ """
336+ import org.joda.time.DateTime;
337+ import org.joda.time.Interval;
338+
339+ class A {
340+ public DateTime foo(DateTime dt) {
341+ DateTime d = dt.toDateMidnight();
342+ DateTime d2 = DateTime.now();
343+ Interval interval = new Interval(d2, d2.plusDays(1));
344+ return interval.getEnd();
345+ }
346+
347+ private static class Bar {
348+ public void bar() {
349+ DateTime d = foo(new DateTime());
350+ System.out.println(d.getMillis());
351+ }
352+ }
353+ }
354+ """ ,
355+ """
356+ import org.joda.time.DateTime;
357+ import org.threeten.extra.Interval;
358+
359+ import java.time.ZoneId;
360+ import java.time.ZonedDateTime;
361+
362+ class A {
363+ public ZonedDateTime foo(DateTime dt) {
364+ DateTime d = dt.toDateMidnight();
365+ ZonedDateTime d2 = ZonedDateTime.now();
366+ Interval interval = Interval.of(d2.toInstant(), d2.plusDays(1).toInstant());
367+ return interval.getEnd().atZone(ZoneId.systemDefault());
368+ }
369+
370+ private static class Bar {
371+ public void bar() {
372+ ZonedDateTime d = foo(new DateTime());
373+ System.out.println(d.toInstant().toEpochMilli());
374+ }
375+ }
376+ }
377+ """
378+ )
379+ );
380+ }
381+
283382 @ Test
284383 void doNotMigrateUnsafeMethodParam () {
285384 //language=java
0 commit comments