diff --git a/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java b/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java index 53483591e0..120476654f 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/JodaTimeVisitor.java @@ -22,11 +22,7 @@ import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.migrate.joda.templates.*; -import org.openrewrite.java.tree.Expression; -import org.openrewrite.java.tree.J; -import org.openrewrite.java.tree.JavaType; -import org.openrewrite.java.tree.MethodCall; -import org.openrewrite.java.tree.TypeUtils; +import org.openrewrite.java.tree.*; import java.util.List; import java.util.Optional; @@ -34,148 +30,147 @@ import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; - public class JodaTimeVisitor extends JavaVisitor { - private final MethodMatcher anyNewDateTime = new MethodMatcher(JODA_DATE_TIME + "(..)"); - private final MethodMatcher anyDateTime = new MethodMatcher(JODA_DATE_TIME + " *(..)"); - private final MethodMatcher anyBaseDateTime = new MethodMatcher(JODA_BASE_DATE_TIME + " *(..)"); - private final MethodMatcher zoneFor = new MethodMatcher(JODA_DATE_TIME_ZONE + " for*(..)"); - private final MethodMatcher anyTimeFormatter = new MethodMatcher(JODA_TIME_FORMAT + " *(..)"); - private final MethodMatcher anyNewDuration = new MethodMatcher(JODA_DURATION + "(..)"); - private final MethodMatcher anyDuration = new MethodMatcher(JODA_DURATION + " *(..)"); - - @Override - public @NonNull J visitCompilationUnit(@NonNull J.CompilationUnit cu, @NonNull ExecutionContext ctx) { - maybeRemoveImport(JODA_DATE_TIME); - maybeRemoveImport(JODA_DATE_TIME_ZONE); - maybeRemoveImport(JODA_TIME_FORMAT); - maybeRemoveImport(JODA_DURATION); - maybeRemoveImport("java.util.Locale"); - - maybeAddImport(JAVA_DATE_TIME); - maybeAddImport(JAVA_ZONE_OFFSET); - maybeAddImport(JAVA_ZONE_ID); - maybeAddImport(JAVA_INSTANT); - maybeAddImport(JAVA_TIME_FORMATTER); - maybeAddImport(JAVA_TIME_FORMAT_STYLE); - maybeAddImport(JAVA_DURATION); - maybeAddImport(JAVA_LOCAL_DATE); - maybeAddImport(JAVA_LOCAL_TIME); - maybeAddImport(JAVA_TEMPORAL_ISO_FIELDS); - maybeAddImport(JAVA_CHRONO_FIELD); - return super.visitCompilationUnit(cu, ctx); - } - - @Override - public @NonNull J visitVariable(@NonNull J.VariableDeclarations.NamedVariable variable, @NonNull ExecutionContext ctx) { - // TODO implement logic for safe variable migration - if (variable.getType().isAssignableFrom(JODA_CLASS_PATTERN)) { - return variable; - } - return super.visitVariable(variable, ctx); - } - - @Override - public @NonNull J visitNewClass(@NonNull J.NewClass newClass, @NonNull ExecutionContext ctx) { - MethodCall updated = (MethodCall) super.visitNewClass(newClass, ctx); - if (hasJodaType(updated.getArguments())) { - return newClass; - } - if (anyNewDateTime.matches(newClass)) { - return applyTemplate(newClass, updated, DateTimeTemplates.getTemplates()).orElse(newClass); - } - if (anyNewDuration.matches(newClass)) { - return applyTemplate(newClass, updated, DurationTemplates.getTemplates()).orElse(newClass); + private final MethodMatcher anyNewDateTime = new MethodMatcher(JODA_DATE_TIME + "(..)"); + private final MethodMatcher anyDateTime = new MethodMatcher(JODA_DATE_TIME + " *(..)"); + private final MethodMatcher anyBaseDateTime = new MethodMatcher(JODA_BASE_DATE_TIME + " *(..)"); + private final MethodMatcher zoneFor = new MethodMatcher(JODA_DATE_TIME_ZONE + " for*(..)"); + private final MethodMatcher anyTimeFormatter = new MethodMatcher(JODA_TIME_FORMAT + " *(..)"); + private final MethodMatcher anyNewDuration = new MethodMatcher(JODA_DURATION + "(..)"); + private final MethodMatcher anyDuration = new MethodMatcher(JODA_DURATION + " *(..)"); + + @Override + public @NonNull J visitCompilationUnit(@NonNull J.CompilationUnit cu, @NonNull ExecutionContext ctx) { + maybeRemoveImport(JODA_DATE_TIME); + maybeRemoveImport(JODA_DATE_TIME_ZONE); + maybeRemoveImport(JODA_TIME_FORMAT); + maybeRemoveImport(JODA_DURATION); + maybeRemoveImport("java.util.Locale"); + + maybeAddImport(JAVA_DATE_TIME); + maybeAddImport(JAVA_ZONE_OFFSET); + maybeAddImport(JAVA_ZONE_ID); + maybeAddImport(JAVA_INSTANT); + maybeAddImport(JAVA_TIME_FORMATTER); + maybeAddImport(JAVA_TIME_FORMAT_STYLE); + maybeAddImport(JAVA_DURATION); + maybeAddImport(JAVA_LOCAL_DATE); + maybeAddImport(JAVA_LOCAL_TIME); + maybeAddImport(JAVA_TEMPORAL_ISO_FIELDS); + maybeAddImport(JAVA_CHRONO_FIELD); + return super.visitCompilationUnit(cu, ctx); + } + + @Override + public @NonNull J visitVariable(@NonNull J.VariableDeclarations.NamedVariable variable, @NonNull ExecutionContext ctx) { + // TODO implement logic for safe variable migration + if (variable.getType().isAssignableFrom(JODA_CLASS_PATTERN)) { + return variable; + } + return super.visitVariable(variable, ctx); } - if (areArgumentsAssignable(updated)) { - return updated; + + @Override + public @NonNull J visitNewClass(@NonNull J.NewClass newClass, @NonNull ExecutionContext ctx) { + MethodCall updated = (MethodCall) super.visitNewClass(newClass, ctx); + if (hasJodaType(updated.getArguments())) { + return newClass; + } + if (anyNewDateTime.matches(newClass)) { + return applyTemplate(newClass, updated, DateTimeTemplates.getTemplates()).orElse(newClass); + } + if (anyNewDuration.matches(newClass)) { + return applyTemplate(newClass, updated, DurationTemplates.getTemplates()).orElse(newClass); + } + if (areArgumentsAssignable(updated)) { + return updated; + } + return newClass; } - return newClass; - } - @Override - public @NonNull J visitMethodInvocation(@NonNull J.MethodInvocation method, @NonNull ExecutionContext ctx) { - J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); - if (hasJodaType(m.getArguments()) || isJodaVarRef(m.getSelect())) { - return method; - } - if (zoneFor.matches(method)) { - return applyTemplate(method, m, TimeZoneTemplates.getTemplates()).orElse(method); - } - if (anyDateTime.matches(method) || anyBaseDateTime.matches(method)) { - return applyTemplate(method, m, DateTimeTemplates.getTemplates()).orElse(method); - } - if (anyTimeFormatter.matches(method)) { - return applyTemplate(method, m, DateTimeFormatTemplates.getTemplates()).orElse(method); - } - if (anyDuration.matches(method)) { - return applyTemplate(method, m, DurationTemplates.getTemplates()).orElse(method); - } - if (areArgumentsAssignable(m)) { - return m; - } - return method; - } - - @Override - public @NonNull J visitFieldAccess(@NonNull J.FieldAccess fieldAccess, @NonNull ExecutionContext ctx) { - J.FieldAccess f = (J.FieldAccess) super.visitFieldAccess(fieldAccess, ctx); - if (TypeUtils.isOfClassType(f.getType(), JODA_DATE_TIME_ZONE) && f.getSimpleName().equals("UTC")) { - return JavaTemplate.builder("ZoneOffset.UTC") - .imports(JAVA_ZONE_OFFSET) - .build() - .apply(updateCursor(f), f.getCoordinates().replace()); + @Override + public @NonNull J visitMethodInvocation(@NonNull J.MethodInvocation method, @NonNull ExecutionContext ctx) { + J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); + if (hasJodaType(m.getArguments()) || isJodaVarRef(m.getSelect())) { + return method; + } + if (zoneFor.matches(method)) { + return applyTemplate(method, m, TimeZoneTemplates.getTemplates()).orElse(method); + } + if (anyDateTime.matches(method) || anyBaseDateTime.matches(method)) { + return applyTemplate(method, m, DateTimeTemplates.getTemplates()).orElse(method); + } + if (anyTimeFormatter.matches(method)) { + return applyTemplate(method, m, DateTimeFormatTemplates.getTemplates()).orElse(method); + } + if (anyDuration.matches(method)) { + return applyTemplate(method, m, DurationTemplates.getTemplates()).orElse(method); + } + if (areArgumentsAssignable(m)) { + return m; + } + return method; } - return f; - } - private boolean hasJodaType(List exprs) { - for (Expression expr : exprs) { - JavaType exprType = expr.getType(); - if (exprType != null && exprType.isAssignableFrom(Pattern.compile("org.joda.time.*"))) { - return true; - } - } - return false; - } - - private Optional applyTemplate(MethodCall original, MethodCall updated, List templates) { - for (MethodTemplate template : templates) { - if (template.getMatcher().matches(original)) { - Expression[] args = template.getTemplateArgsFunc().apply(updated); - if (args.length == 0) { - return Optional.of(template.getTemplate().apply(updateCursor(updated), updated.getCoordinates().replace())); - } - return Optional.of(template.getTemplate().apply(updateCursor(updated), updated.getCoordinates().replace(), (Object[]) args)); - } + @Override + public @NonNull J visitFieldAccess(@NonNull J.FieldAccess fieldAccess, @NonNull ExecutionContext ctx) { + J.FieldAccess f = (J.FieldAccess) super.visitFieldAccess(fieldAccess, ctx); + if (TypeUtils.isOfClassType(f.getType(), JODA_DATE_TIME_ZONE) && f.getSimpleName().equals("UTC")) { + return JavaTemplate.builder("ZoneOffset.UTC") + .imports(JAVA_ZONE_OFFSET) + .build() + .apply(updateCursor(f), f.getCoordinates().replace()); + } + return f; } - return Optional.empty(); // unhandled case - } - private boolean areArgumentsAssignable(MethodCall m) { - if (m.getMethodType() == null || m.getArguments().size() != m.getMethodType().getParameterTypes().size()) { - return false; - } - for (int i = 0; i < m.getArguments().size(); i++) { - if (!TypeUtils.isAssignableTo(m.getMethodType().getParameterTypes().get(i), m.getArguments().get(i).getType())) { + private boolean hasJodaType(List exprs) { + for (Expression expr : exprs) { + JavaType exprType = expr.getType(); + if (exprType != null && exprType.isAssignableFrom(Pattern.compile("org.joda.time.*"))) { + return true; + } + } return false; - } } - return true; - } - private boolean isJodaVarRef(@Nullable Expression expr) { - if (expr == null || expr.getType() == null || !expr.getType().isAssignableFrom(JODA_CLASS_PATTERN)) { - return false; + private Optional applyTemplate(MethodCall original, MethodCall updated, List templates) { + for (MethodTemplate template : templates) { + if (template.getMatcher().matches(original)) { + Expression[] args = template.getTemplateArgsFunc().apply(updated); + if (args.length == 0) { + return Optional.of(template.getTemplate().apply(updateCursor(updated), updated.getCoordinates().replace())); + } + return Optional.of(template.getTemplate().apply(updateCursor(updated), updated.getCoordinates().replace(), (Object[]) args)); + } + } + return Optional.empty(); // unhandled case } - if (expr instanceof J.FieldAccess) { - return ((J.FieldAccess) expr).getName().getFieldType() != null; + + private boolean areArgumentsAssignable(MethodCall m) { + if (m.getMethodType() == null || m.getArguments().size() != m.getMethodType().getParameterTypes().size()) { + return false; + } + for (int i = 0; i < m.getArguments().size(); i++) { + if (!TypeUtils.isAssignableTo(m.getMethodType().getParameterTypes().get(i), m.getArguments().get(i).getType())) { + return false; + } + } + return true; } - if (expr instanceof J.Identifier) { - return ((J.Identifier) expr).getFieldType() != null; + + private boolean isJodaVarRef(@Nullable Expression expr) { + if (expr == null || expr.getType() == null || !expr.getType().isAssignableFrom(JODA_CLASS_PATTERN)) { + return false; + } + if (expr instanceof J.FieldAccess) { + return ((J.FieldAccess) expr).getName().getFieldType() != null; + } + if (expr instanceof J.Identifier) { + return ((J.Identifier) expr).getFieldType() != null; + } + return false; } - return false; - } } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java index ef6d50208c..25d5ad37b0 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeFormatTemplates.java @@ -24,80 +24,80 @@ import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; public class DateTimeFormatTemplates { - private final MethodMatcher forPattern = new MethodMatcher(JODA_TIME_FORMAT + " forPattern(String)"); - private final MethodMatcher forStyle = new MethodMatcher(JODA_TIME_FORMAT + " forStyle(String)"); - private final MethodMatcher patternForStyle = new MethodMatcher(JODA_TIME_FORMAT + " patternForStyle(String, java.util.Locale)"); - private final MethodMatcher shortDate = new MethodMatcher(JODA_TIME_FORMAT + " shortDate()"); - private final MethodMatcher mediumDate = new MethodMatcher(JODA_TIME_FORMAT + " mediumDate()"); - private final MethodMatcher longDate = new MethodMatcher(JODA_TIME_FORMAT + " longDate()"); - private final MethodMatcher fullDate = new MethodMatcher(JODA_TIME_FORMAT + " fullDate()"); - private final MethodMatcher shortTime = new MethodMatcher(JODA_TIME_FORMAT + " shortTime()"); - private final MethodMatcher mediumTime = new MethodMatcher(JODA_TIME_FORMAT + " mediumTime()"); - private final MethodMatcher longTime = new MethodMatcher(JODA_TIME_FORMAT + " longTime()"); - private final MethodMatcher fullTime = new MethodMatcher(JODA_TIME_FORMAT + " fullTime()"); - private final MethodMatcher shortDateTime = new MethodMatcher(JODA_TIME_FORMAT + " shortDateTime()"); - private final MethodMatcher mediumDateTime = new MethodMatcher(JODA_TIME_FORMAT + " mediumDateTime()"); - private final MethodMatcher longDateTime = new MethodMatcher(JODA_TIME_FORMAT + " longDateTime()"); - private final MethodMatcher fullDateTime = new MethodMatcher(JODA_TIME_FORMAT + " fullDateTime()"); + private final MethodMatcher forPattern = new MethodMatcher(JODA_TIME_FORMAT + " forPattern(String)"); + private final MethodMatcher forStyle = new MethodMatcher(JODA_TIME_FORMAT + " forStyle(String)"); + private final MethodMatcher patternForStyle = new MethodMatcher(JODA_TIME_FORMAT + " patternForStyle(String, java.util.Locale)"); + private final MethodMatcher shortDate = new MethodMatcher(JODA_TIME_FORMAT + " shortDate()"); + private final MethodMatcher mediumDate = new MethodMatcher(JODA_TIME_FORMAT + " mediumDate()"); + private final MethodMatcher longDate = new MethodMatcher(JODA_TIME_FORMAT + " longDate()"); + private final MethodMatcher fullDate = new MethodMatcher(JODA_TIME_FORMAT + " fullDate()"); + private final MethodMatcher shortTime = new MethodMatcher(JODA_TIME_FORMAT + " shortTime()"); + private final MethodMatcher mediumTime = new MethodMatcher(JODA_TIME_FORMAT + " mediumTime()"); + private final MethodMatcher longTime = new MethodMatcher(JODA_TIME_FORMAT + " longTime()"); + private final MethodMatcher fullTime = new MethodMatcher(JODA_TIME_FORMAT + " fullTime()"); + private final MethodMatcher shortDateTime = new MethodMatcher(JODA_TIME_FORMAT + " shortDateTime()"); + private final MethodMatcher mediumDateTime = new MethodMatcher(JODA_TIME_FORMAT + " mediumDateTime()"); + private final MethodMatcher longDateTime = new MethodMatcher(JODA_TIME_FORMAT + " longDateTime()"); + private final MethodMatcher fullDateTime = new MethodMatcher(JODA_TIME_FORMAT + " fullDateTime()"); - private final JavaTemplate ofPatternTemplate = JavaTemplate.builder("DateTimeFormatter.ofPattern(#{any(String)})") - .imports("java.time.format.DateTimeFormatter") - .build(); - private final JavaTemplate shortDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate mediumDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate longDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate fullDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate shortTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate mediumTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate longTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.LONG)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate fullTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate shortDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate mediumDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate longDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.LONG)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final JavaTemplate fullDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL)") - .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) - .build(); - private final List templates = new ArrayList() { - { - add(new MethodTemplate(forPattern, ofPatternTemplate)); - add(new MethodTemplate(shortDate, shortDateTemplate)); - add(new MethodTemplate(mediumDate, mediumDateTemplate)); - add(new MethodTemplate(longDate, longDateTemplate)); - add(new MethodTemplate(fullDate, fullDateTemplate)); - add(new MethodTemplate(shortTime, shortTimeTemplate)); - add(new MethodTemplate(mediumTime, mediumTimeTemplate)); - add(new MethodTemplate(longTime, longTimeTemplate)); - add(new MethodTemplate(fullTime, fullTimeTemplate)); - add(new MethodTemplate(shortDateTime, shortDateTimeTemplate)); - add(new MethodTemplate(mediumDateTime, mediumDateTimeTemplate)); - add(new MethodTemplate(longDateTime, longDateTimeTemplate)); - add(new MethodTemplate(fullDateTime, fullDateTimeTemplate)); - } - }; + private final JavaTemplate ofPatternTemplate = JavaTemplate.builder("DateTimeFormatter.ofPattern(#{any(String)})") + .imports("java.time.format.DateTimeFormatter") + .build(); + private final JavaTemplate shortDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate mediumDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate longDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate fullDateTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate shortTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate mediumTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate longTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.LONG)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate fullTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate shortDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate mediumDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate longDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.LONG)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final JavaTemplate fullDateTimeTemplate = JavaTemplate.builder("DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL)") + .imports(JAVA_TIME_FORMATTER, JAVA_TIME_FORMAT_STYLE) + .build(); + private final List templates = new ArrayList() { + { + add(new MethodTemplate(forPattern, ofPatternTemplate)); + add(new MethodTemplate(shortDate, shortDateTemplate)); + add(new MethodTemplate(mediumDate, mediumDateTemplate)); + add(new MethodTemplate(longDate, longDateTemplate)); + add(new MethodTemplate(fullDate, fullDateTemplate)); + add(new MethodTemplate(shortTime, shortTimeTemplate)); + add(new MethodTemplate(mediumTime, mediumTimeTemplate)); + add(new MethodTemplate(longTime, longTimeTemplate)); + add(new MethodTemplate(fullTime, fullTimeTemplate)); + add(new MethodTemplate(shortDateTime, shortDateTimeTemplate)); + add(new MethodTemplate(mediumDateTime, mediumDateTimeTemplate)); + add(new MethodTemplate(longDateTime, longDateTimeTemplate)); + add(new MethodTemplate(fullDateTime, fullDateTimeTemplate)); + } + }; - public static List getTemplates() { - return new DateTimeFormatTemplates().templates; - } + public static List getTemplates() { + return new DateTimeFormatTemplates().templates; + } } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeTemplates.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeTemplates.java index fb5c2f5040..17da53f65b 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeTemplates.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/DateTimeTemplates.java @@ -28,320 +28,320 @@ @NoArgsConstructor public class DateTimeTemplates { - private final MethodMatcher newDateTime = new MethodMatcher(JODA_DATE_TIME + "()"); - private final MethodMatcher newDateTimeWithZone = new MethodMatcher(JODA_DATE_TIME + "(" + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher newDateTimeWithEpoch = new MethodMatcher(JODA_DATE_TIME + "(long)"); - private final MethodMatcher newDateTimeWithEpochAndZone = new MethodMatcher(JODA_DATE_TIME + "(long, " + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher newDateTimeWithMin = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int)"); - private final MethodMatcher newDateTimeWithMinAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher newDateTimeWithSec = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int)"); - private final MethodMatcher newDateTimeWithSecAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher newDateTimeWithMillis = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, int)"); - private final MethodMatcher newDateTimeWithMillisAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher newDateTime = new MethodMatcher(JODA_DATE_TIME + "()"); + private final MethodMatcher newDateTimeWithZone = new MethodMatcher(JODA_DATE_TIME + "(" + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher newDateTimeWithEpoch = new MethodMatcher(JODA_DATE_TIME + "(long)"); + private final MethodMatcher newDateTimeWithEpochAndZone = new MethodMatcher(JODA_DATE_TIME + "(long, " + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher newDateTimeWithMin = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int)"); + private final MethodMatcher newDateTimeWithMinAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher newDateTimeWithSec = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int)"); + private final MethodMatcher newDateTimeWithSecAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher newDateTimeWithMillis = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, int)"); + private final MethodMatcher newDateTimeWithMillisAndZone = new MethodMatcher(JODA_DATE_TIME + "(int, int, int, int, int, int, int, " + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher dateTimeNow = new MethodMatcher(JODA_DATE_TIME + " now()"); - private final MethodMatcher dateTimeNowWithZone = new MethodMatcher(JODA_DATE_TIME + " now(" + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher dateTimeParse = new MethodMatcher(JODA_DATE_TIME + " parse(String)"); - private final MethodMatcher dateTimeParseWithFormatter = new MethodMatcher(JODA_DATE_TIME + " parse(String, " + JODA_TIME_FORMATTER +")"); + private final MethodMatcher dateTimeNow = new MethodMatcher(JODA_DATE_TIME + " now()"); + private final MethodMatcher dateTimeNowWithZone = new MethodMatcher(JODA_DATE_TIME + " now(" + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher dateTimeParse = new MethodMatcher(JODA_DATE_TIME + " parse(String)"); + private final MethodMatcher dateTimeParseWithFormatter = new MethodMatcher(JODA_DATE_TIME + " parse(String, " + JODA_TIME_FORMATTER + ")"); - private final MethodMatcher toDateTime = new MethodMatcher(JODA_DATE_TIME + " toDateTime()"); - private final MethodMatcher toDateTimeWithZone = new MethodMatcher(JODA_DATE_TIME + " toDateTime(" + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher getMillis = new MethodMatcher(JODA_BASE_DATE_TIME + " getMillis()"); - private final MethodMatcher withMillis = new MethodMatcher(JODA_DATE_TIME + " withMillis(long)"); - private final MethodMatcher withZone = new MethodMatcher(JODA_DATE_TIME + " withZone(" + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher withZoneRetainFields = new MethodMatcher(JODA_DATE_TIME + " withZoneRetainFields(" + JODA_DATE_TIME_ZONE + ")"); - private final MethodMatcher withEarlierOffsetAtOverlap = new MethodMatcher(JODA_DATE_TIME + " withEarlierOffsetAtOverlap()"); - private final MethodMatcher withLaterOffsetAtOverlap = new MethodMatcher(JODA_DATE_TIME + " withLaterOffsetAtOverlap()"); - private final MethodMatcher withDate = new MethodMatcher(JODA_DATE_TIME + " withDate(int, int, int)"); - private final MethodMatcher withDateLocalDate = new MethodMatcher(JODA_DATE_TIME + " withDate(" + JODA_LOCAL_DATE + ")"); - private final MethodMatcher withTime = new MethodMatcher(JODA_DATE_TIME + " withTime(int, int, int, int)"); - private final MethodMatcher withTimeLocalTime = new MethodMatcher(JODA_DATE_TIME + " withTime(" + JODA_LOCAL_TIME + ")"); - private final MethodMatcher withTimeAtStartOfDay = new MethodMatcher(JODA_DATE_TIME + " withTimeAtStartOfDay()"); - private final MethodMatcher withField = new MethodMatcher(JODA_DATE_TIME + " withField(" + JODA_DATE_TIME_FIELD_TYPE + ", int)"); - private final MethodMatcher withFieldAdded = new MethodMatcher(JODA_DATE_TIME + " withFieldAdded(" + JODA_DURATION_FIELD_TYPE + ", int)"); - private final MethodMatcher withDurationAdded = new MethodMatcher(JODA_DATE_TIME + " withDurationAdded(long, int)"); - private final MethodMatcher plusLong = new MethodMatcher(JODA_DATE_TIME + " plus(long)"); - private final MethodMatcher plusReadableDuration = new MethodMatcher(JODA_DATE_TIME + " plus(" + JODA_READABLE_DURATION + ")"); - private final MethodMatcher plusYears = new MethodMatcher(JODA_DATE_TIME + " plusYears(int)"); - private final MethodMatcher plusMonths = new MethodMatcher(JODA_DATE_TIME + " plusMonths(int)"); - private final MethodMatcher plusWeeks = new MethodMatcher(JODA_DATE_TIME + " plusWeeks(int)"); - private final MethodMatcher plusDays = new MethodMatcher(JODA_DATE_TIME + " plusDays(int)"); - private final MethodMatcher plusHours = new MethodMatcher(JODA_DATE_TIME + " plusHours(int)"); - private final MethodMatcher plusMinutes = new MethodMatcher(JODA_DATE_TIME + " plusMinutes(int)"); - private final MethodMatcher plusSeconds = new MethodMatcher(JODA_DATE_TIME + " plusSeconds(int)"); - private final MethodMatcher plusMillis = new MethodMatcher(JODA_DATE_TIME + " plusMillis(int)"); - private final MethodMatcher minusLong = new MethodMatcher(JODA_DATE_TIME + " minus(long)"); - private final MethodMatcher minusReadableDuration = new MethodMatcher(JODA_DATE_TIME + " minus(" + JODA_READABLE_DURATION + ")"); - private final MethodMatcher minusYears = new MethodMatcher(JODA_DATE_TIME + " minusYears(int)"); - private final MethodMatcher minusMonths = new MethodMatcher(JODA_DATE_TIME + " minusMonths(int)"); - private final MethodMatcher minusWeeks = new MethodMatcher(JODA_DATE_TIME + " minusWeeks(int)"); - private final MethodMatcher minusDays = new MethodMatcher(JODA_DATE_TIME + " minusDays(int)"); - private final MethodMatcher minusHours = new MethodMatcher(JODA_DATE_TIME + " minusHours(int)"); - private final MethodMatcher minusMinutes = new MethodMatcher(JODA_DATE_TIME + " minusMinutes(int)"); - private final MethodMatcher minusSeconds = new MethodMatcher(JODA_DATE_TIME + " minusSeconds(int)"); - private final MethodMatcher minusMillis = new MethodMatcher(JODA_DATE_TIME + " minusMillis(int)"); - private final MethodMatcher toDateMidnight = new MethodMatcher(JODA_DATE_TIME + " toDateMidnight()"); - private final MethodMatcher toYearMonthDay = new MethodMatcher(JODA_DATE_TIME + " toYearMonthDay()"); - private final MethodMatcher toTimeOfDay = new MethodMatcher(JODA_DATE_TIME + " toTimeOfDay()"); - private final MethodMatcher toLocalDateTime = new MethodMatcher(JODA_DATE_TIME + " toLocalDateTime()"); - private final MethodMatcher toLocalDate = new MethodMatcher(JODA_DATE_TIME + " toLocalDate()"); - private final MethodMatcher toLocalTime = new MethodMatcher(JODA_DATE_TIME + " toLocalTime()"); - private final MethodMatcher withEra = new MethodMatcher(JODA_DATE_TIME + " withEra(int)"); - private final MethodMatcher withCenturyOfEra = new MethodMatcher(JODA_DATE_TIME + " withCenturyOfEra(int)"); - private final MethodMatcher withYearOfEra = new MethodMatcher(JODA_DATE_TIME + " withYearOfEra(int)"); - private final MethodMatcher withYearOfCentury = new MethodMatcher(JODA_DATE_TIME + " withYearOfCentury(int)"); - private final MethodMatcher withYear = new MethodMatcher(JODA_DATE_TIME + " withYear(int)"); - private final MethodMatcher withWeekyear = new MethodMatcher(JODA_DATE_TIME + " withWeekyear(int)"); - private final MethodMatcher withMonthOfYear = new MethodMatcher(JODA_DATE_TIME + " withMonthOfYear(int)"); - private final MethodMatcher withWeekOfWeekyear = new MethodMatcher(JODA_DATE_TIME + " withWeekOfWeekyear(int)"); - private final MethodMatcher withDayOfYear = new MethodMatcher(JODA_DATE_TIME + " withDayOfYear(int)"); - private final MethodMatcher withDayOfMonth = new MethodMatcher(JODA_DATE_TIME + " withDayOfMonth(int)"); - private final MethodMatcher withDayOfWeek = new MethodMatcher(JODA_DATE_TIME + " withDayOfWeek(int)"); - private final MethodMatcher withHourOfDay = new MethodMatcher(JODA_DATE_TIME + " withHourOfDay(int)"); - private final MethodMatcher withMinuteOfHour = new MethodMatcher(JODA_DATE_TIME + " withMinuteOfHour(int)"); - private final MethodMatcher withSecondOfMinute = new MethodMatcher(JODA_DATE_TIME + " withSecondOfMinute(int)"); - private final MethodMatcher withMillisOfSecond = new MethodMatcher(JODA_DATE_TIME + " withMillisOfSecond(int)"); - private final MethodMatcher withMillisOfDay = new MethodMatcher(JODA_DATE_TIME + " withMillisOfDay(int)"); - private final MethodMatcher era = new MethodMatcher(JODA_DATE_TIME + " era()"); - private final MethodMatcher centuryOfEra = new MethodMatcher(JODA_DATE_TIME + " centuryOfEra()"); - private final MethodMatcher yearOfCentury = new MethodMatcher(JODA_DATE_TIME + " yearOfCentury()"); - private final MethodMatcher yearOfEra = new MethodMatcher(JODA_DATE_TIME + " yearOfEra()"); - private final MethodMatcher year = new MethodMatcher(JODA_DATE_TIME + " year()"); - private final MethodMatcher weekyear = new MethodMatcher(JODA_DATE_TIME + " weekyear()"); - private final MethodMatcher monthOfYear = new MethodMatcher(JODA_DATE_TIME + " monthOfYear()"); - private final MethodMatcher weekOfWeekyear = new MethodMatcher(JODA_DATE_TIME + " weekOfWeekyear()"); - private final MethodMatcher dayOfYear = new MethodMatcher(JODA_DATE_TIME + " dayOfYear()"); - private final MethodMatcher dayOfMonth = new MethodMatcher(JODA_DATE_TIME + " dayOfMonth()"); - private final MethodMatcher dayOfWeek = new MethodMatcher(JODA_DATE_TIME + " dayOfWeek()"); - private final MethodMatcher hourOfDay = new MethodMatcher(JODA_DATE_TIME + " hourOfDay()"); - private final MethodMatcher minuteOfDay = new MethodMatcher(JODA_DATE_TIME + " minuteOfDay()"); - private final MethodMatcher minuteOfHour = new MethodMatcher(JODA_DATE_TIME + " minuteOfHour()"); - private final MethodMatcher secondOfDay = new MethodMatcher(JODA_DATE_TIME + " secondOfDay()"); - private final MethodMatcher secondOfMinute = new MethodMatcher(JODA_DATE_TIME + " secondOfMinute()"); - private final MethodMatcher millisOfDay = new MethodMatcher(JODA_DATE_TIME + " millisOfDay()"); - private final MethodMatcher millisOfSecond = new MethodMatcher(JODA_DATE_TIME + " millisOfSecond()"); + private final MethodMatcher toDateTime = new MethodMatcher(JODA_DATE_TIME + " toDateTime()"); + private final MethodMatcher toDateTimeWithZone = new MethodMatcher(JODA_DATE_TIME + " toDateTime(" + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher getMillis = new MethodMatcher(JODA_BASE_DATE_TIME + " getMillis()"); + private final MethodMatcher withMillis = new MethodMatcher(JODA_DATE_TIME + " withMillis(long)"); + private final MethodMatcher withZone = new MethodMatcher(JODA_DATE_TIME + " withZone(" + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher withZoneRetainFields = new MethodMatcher(JODA_DATE_TIME + " withZoneRetainFields(" + JODA_DATE_TIME_ZONE + ")"); + private final MethodMatcher withEarlierOffsetAtOverlap = new MethodMatcher(JODA_DATE_TIME + " withEarlierOffsetAtOverlap()"); + private final MethodMatcher withLaterOffsetAtOverlap = new MethodMatcher(JODA_DATE_TIME + " withLaterOffsetAtOverlap()"); + private final MethodMatcher withDate = new MethodMatcher(JODA_DATE_TIME + " withDate(int, int, int)"); + private final MethodMatcher withDateLocalDate = new MethodMatcher(JODA_DATE_TIME + " withDate(" + JODA_LOCAL_DATE + ")"); + private final MethodMatcher withTime = new MethodMatcher(JODA_DATE_TIME + " withTime(int, int, int, int)"); + private final MethodMatcher withTimeLocalTime = new MethodMatcher(JODA_DATE_TIME + " withTime(" + JODA_LOCAL_TIME + ")"); + private final MethodMatcher withTimeAtStartOfDay = new MethodMatcher(JODA_DATE_TIME + " withTimeAtStartOfDay()"); + private final MethodMatcher withField = new MethodMatcher(JODA_DATE_TIME + " withField(" + JODA_DATE_TIME_FIELD_TYPE + ", int)"); + private final MethodMatcher withFieldAdded = new MethodMatcher(JODA_DATE_TIME + " withFieldAdded(" + JODA_DURATION_FIELD_TYPE + ", int)"); + private final MethodMatcher withDurationAdded = new MethodMatcher(JODA_DATE_TIME + " withDurationAdded(long, int)"); + private final MethodMatcher plusLong = new MethodMatcher(JODA_DATE_TIME + " plus(long)"); + private final MethodMatcher plusReadableDuration = new MethodMatcher(JODA_DATE_TIME + " plus(" + JODA_READABLE_DURATION + ")"); + private final MethodMatcher plusYears = new MethodMatcher(JODA_DATE_TIME + " plusYears(int)"); + private final MethodMatcher plusMonths = new MethodMatcher(JODA_DATE_TIME + " plusMonths(int)"); + private final MethodMatcher plusWeeks = new MethodMatcher(JODA_DATE_TIME + " plusWeeks(int)"); + private final MethodMatcher plusDays = new MethodMatcher(JODA_DATE_TIME + " plusDays(int)"); + private final MethodMatcher plusHours = new MethodMatcher(JODA_DATE_TIME + " plusHours(int)"); + private final MethodMatcher plusMinutes = new MethodMatcher(JODA_DATE_TIME + " plusMinutes(int)"); + private final MethodMatcher plusSeconds = new MethodMatcher(JODA_DATE_TIME + " plusSeconds(int)"); + private final MethodMatcher plusMillis = new MethodMatcher(JODA_DATE_TIME + " plusMillis(int)"); + private final MethodMatcher minusLong = new MethodMatcher(JODA_DATE_TIME + " minus(long)"); + private final MethodMatcher minusReadableDuration = new MethodMatcher(JODA_DATE_TIME + " minus(" + JODA_READABLE_DURATION + ")"); + private final MethodMatcher minusYears = new MethodMatcher(JODA_DATE_TIME + " minusYears(int)"); + private final MethodMatcher minusMonths = new MethodMatcher(JODA_DATE_TIME + " minusMonths(int)"); + private final MethodMatcher minusWeeks = new MethodMatcher(JODA_DATE_TIME + " minusWeeks(int)"); + private final MethodMatcher minusDays = new MethodMatcher(JODA_DATE_TIME + " minusDays(int)"); + private final MethodMatcher minusHours = new MethodMatcher(JODA_DATE_TIME + " minusHours(int)"); + private final MethodMatcher minusMinutes = new MethodMatcher(JODA_DATE_TIME + " minusMinutes(int)"); + private final MethodMatcher minusSeconds = new MethodMatcher(JODA_DATE_TIME + " minusSeconds(int)"); + private final MethodMatcher minusMillis = new MethodMatcher(JODA_DATE_TIME + " minusMillis(int)"); + private final MethodMatcher toDateMidnight = new MethodMatcher(JODA_DATE_TIME + " toDateMidnight()"); + private final MethodMatcher toYearMonthDay = new MethodMatcher(JODA_DATE_TIME + " toYearMonthDay()"); + private final MethodMatcher toTimeOfDay = new MethodMatcher(JODA_DATE_TIME + " toTimeOfDay()"); + private final MethodMatcher toLocalDateTime = new MethodMatcher(JODA_DATE_TIME + " toLocalDateTime()"); + private final MethodMatcher toLocalDate = new MethodMatcher(JODA_DATE_TIME + " toLocalDate()"); + private final MethodMatcher toLocalTime = new MethodMatcher(JODA_DATE_TIME + " toLocalTime()"); + private final MethodMatcher withEra = new MethodMatcher(JODA_DATE_TIME + " withEra(int)"); + private final MethodMatcher withCenturyOfEra = new MethodMatcher(JODA_DATE_TIME + " withCenturyOfEra(int)"); + private final MethodMatcher withYearOfEra = new MethodMatcher(JODA_DATE_TIME + " withYearOfEra(int)"); + private final MethodMatcher withYearOfCentury = new MethodMatcher(JODA_DATE_TIME + " withYearOfCentury(int)"); + private final MethodMatcher withYear = new MethodMatcher(JODA_DATE_TIME + " withYear(int)"); + private final MethodMatcher withWeekyear = new MethodMatcher(JODA_DATE_TIME + " withWeekyear(int)"); + private final MethodMatcher withMonthOfYear = new MethodMatcher(JODA_DATE_TIME + " withMonthOfYear(int)"); + private final MethodMatcher withWeekOfWeekyear = new MethodMatcher(JODA_DATE_TIME + " withWeekOfWeekyear(int)"); + private final MethodMatcher withDayOfYear = new MethodMatcher(JODA_DATE_TIME + " withDayOfYear(int)"); + private final MethodMatcher withDayOfMonth = new MethodMatcher(JODA_DATE_TIME + " withDayOfMonth(int)"); + private final MethodMatcher withDayOfWeek = new MethodMatcher(JODA_DATE_TIME + " withDayOfWeek(int)"); + private final MethodMatcher withHourOfDay = new MethodMatcher(JODA_DATE_TIME + " withHourOfDay(int)"); + private final MethodMatcher withMinuteOfHour = new MethodMatcher(JODA_DATE_TIME + " withMinuteOfHour(int)"); + private final MethodMatcher withSecondOfMinute = new MethodMatcher(JODA_DATE_TIME + " withSecondOfMinute(int)"); + private final MethodMatcher withMillisOfSecond = new MethodMatcher(JODA_DATE_TIME + " withMillisOfSecond(int)"); + private final MethodMatcher withMillisOfDay = new MethodMatcher(JODA_DATE_TIME + " withMillisOfDay(int)"); + private final MethodMatcher era = new MethodMatcher(JODA_DATE_TIME + " era()"); + private final MethodMatcher centuryOfEra = new MethodMatcher(JODA_DATE_TIME + " centuryOfEra()"); + private final MethodMatcher yearOfCentury = new MethodMatcher(JODA_DATE_TIME + " yearOfCentury()"); + private final MethodMatcher yearOfEra = new MethodMatcher(JODA_DATE_TIME + " yearOfEra()"); + private final MethodMatcher year = new MethodMatcher(JODA_DATE_TIME + " year()"); + private final MethodMatcher weekyear = new MethodMatcher(JODA_DATE_TIME + " weekyear()"); + private final MethodMatcher monthOfYear = new MethodMatcher(JODA_DATE_TIME + " monthOfYear()"); + private final MethodMatcher weekOfWeekyear = new MethodMatcher(JODA_DATE_TIME + " weekOfWeekyear()"); + private final MethodMatcher dayOfYear = new MethodMatcher(JODA_DATE_TIME + " dayOfYear()"); + private final MethodMatcher dayOfMonth = new MethodMatcher(JODA_DATE_TIME + " dayOfMonth()"); + private final MethodMatcher dayOfWeek = new MethodMatcher(JODA_DATE_TIME + " dayOfWeek()"); + private final MethodMatcher hourOfDay = new MethodMatcher(JODA_DATE_TIME + " hourOfDay()"); + private final MethodMatcher minuteOfDay = new MethodMatcher(JODA_DATE_TIME + " minuteOfDay()"); + private final MethodMatcher minuteOfHour = new MethodMatcher(JODA_DATE_TIME + " minuteOfHour()"); + private final MethodMatcher secondOfDay = new MethodMatcher(JODA_DATE_TIME + " secondOfDay()"); + private final MethodMatcher secondOfMinute = new MethodMatcher(JODA_DATE_TIME + " secondOfMinute()"); + private final MethodMatcher millisOfDay = new MethodMatcher(JODA_DATE_TIME + " millisOfDay()"); + private final MethodMatcher millisOfSecond = new MethodMatcher(JODA_DATE_TIME + " millisOfSecond()"); - private final JavaTemplate dateTimeTemplate = JavaTemplate.builder("ZonedDateTime.now()") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate dateTimeWithZoneTemplate = JavaTemplate.builder("ZonedDateTime.now(#{any(java.time.ZoneOffset)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate dateTimeWithEpochTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}), ZoneId.systemDefault())") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID, JAVA_INSTANT) - .build(); - private final JavaTemplate dateTimeWithEpochAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}), #{any(java.time.ZoneId)})") - .imports(JAVA_DATE_TIME, JAVA_ZONE_OFFSET, JAVA_ZONE_ID, JAVA_INSTANT) - .build(); - private final JavaTemplate dateTimeWithMinTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, 0, ZoneId.systemDefault())") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) - .build(); - private final JavaTemplate dateTimeWithMinAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, 0, #{any(java.time.ZoneId)})") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) - .build(); - private final JavaTemplate dateTimeWithSecTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, ZoneId.systemDefault())") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) - .build(); - private final JavaTemplate dateTimeWithSecAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, #{any(java.time.ZoneId)})") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) - .build(); - private final JavaTemplate dateTimeWithMillisTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)} * 1_000_000, ZoneId.systemDefault())") - .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) - .build(); - private final JavaTemplate dateTimeWithMillisAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)} * 1_000_000, #{any(java.time.ZoneId)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate dateTimeParseTemplate = JavaTemplate.builder("ZonedDateTime.parse(#{any(String)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate dateTimeParseWithFormatterTemplate = JavaTemplate.builder("ZonedDateTime.parse(#{any(String)}, #{any(java.time.format.DateTimeFormatter)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate toDateTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}") - .build(); - private final JavaTemplate getMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toInstant().toEpochMilli()") - .build(); - private final JavaTemplate withMillisTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}),#{any(java.time.ZonedDateTime)}.getZone())") - .imports(JAVA_DATE_TIME, JAVA_INSTANT) - .build(); - private final JavaTemplate withZoneTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withZoneSameInstant(#{any(java.time.ZoneId)})") - .build(); - private final JavaTemplate withZoneRetainFieldsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withZoneSameLocal(#{any(java.time.ZoneId)})") - .build(); - private final JavaTemplate withEarlierOffsetAtOverlapTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withEarlierOffsetAtOverlap()") - .build(); - private final JavaTemplate withLaterOffsetAtOverlapTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withLaterOffsetAtOverlap()") - .build(); - private final JavaTemplate withDateTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withYear(#{any(int)}).withMonth(#{any(int)}).withDayOfMonth(#{any(int)})") - .build(); - private final JavaTemplate withTemporalAdjusterTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(#{any(java.time.temporal.TemporalAdjuster)})") - .imports(JAVA_TEMPORAL_ADJUSTER) - .build(); - private final JavaTemplate withTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withHour(#{any(int)}).withMinute(#{any(int)}).withSecond(#{any(int)}).withNano(#{any(int)} * 1_000_000)") - .build(); - private final JavaTemplate withTimeAtStartOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.atStartOfDay(#{any(java.time.ZonedDateTime)}.getZone())") - .build(); - private final JavaTemplate withDurationAddedTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(Duration.ofMillis(#{any(long)}).multipliedBy(#{any(int)}))") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate plusReadableDurationTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(#{any(java.time.Duration)})") - .build(); - private final JavaTemplate plusYearsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusYears(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate plusMonthsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusMonths(#{any(int)})") - .build(); - private final JavaTemplate plusWeeksTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusWeeks(#{any(int)})") - .build(); - private final JavaTemplate plusDaysTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusDays(#{any(int)})") - .build(); - private final JavaTemplate plusHoursTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusHours(#{any(int)})") - .build(); - private final JavaTemplate plusMinutesTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusMinutes(#{any(int)})") - .build(); - private final JavaTemplate plusSecondsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusSeconds(#{any(int)})") - .build(); - private final JavaTemplate plusMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(Duration.ofMillis(#{any(int)}))") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate minusMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minus(Duration.ofMillis(#{any(int)}))") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate minusReadableDurationTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minus(#{any(java.time.Duration)})") - .imports(JAVA_DATE_TIME, JAVA_DURATION) - .build(); - private final JavaTemplate minusYearsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusYears(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusMonthsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusMonths(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusWeeksTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusWeeks(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusDaysTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusDays(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusHoursTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusHours(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusMinutesTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusMinutes(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate minusSecondsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusSeconds(#{any(int)})") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate toLocalDateTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalDateTime()") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate toLocalDateTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalDate()") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate toLocalTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalTime()") - .imports(JAVA_DATE_TIME) - .build(); - private final JavaTemplate withYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withYear(#{any(int)})") - .build(); - private final JavaTemplate withWeekyearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(IsoFields.WEEK_BASED_YEAR, #{any(int)})") - .imports(JAVA_TEMPORAL_ISO_FIELDS) - .build(); - private final JavaTemplate withMonthOfYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withMonth(#{any(int)})") - .build(); - private final JavaTemplate withWeekOfWeekyearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.ALIGNED_WEEK_OF_YEAR, #{any(int)})") - .imports(JAVA_CHRONO_FIELD) - .build(); - private final JavaTemplate withDayOfYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withDayOfYear(#{any(int)})") - .build(); - private final JavaTemplate withDayOfMonthTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withDayOfMonth(#{any(int)})") - .build(); - private final JavaTemplate withDayOfWeekTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.DAY_OF_WEEK, #{any(int)})") - .imports(JAVA_CHRONO_FIELD) - .build(); - private final JavaTemplate withHourOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withHour(#{any(int)})") - .build(); - private final JavaTemplate withMinuteOfHourTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withMinute(#{any(int)})") - .build(); - private final JavaTemplate withSecondOfMinuteTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withSecond(#{any(int)})") - .build(); - private final JavaTemplate withMillisOfSecondTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withNano(#{any(int)} * 1_000_000)") - .build(); - private final JavaTemplate withMillisOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.MILLI_OF_DAY, #{any(int)})") - .imports(JAVA_CHRONO_FIELD) - .build(); + private final JavaTemplate dateTimeTemplate = JavaTemplate.builder("ZonedDateTime.now()") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate dateTimeWithZoneTemplate = JavaTemplate.builder("ZonedDateTime.now(#{any(java.time.ZoneOffset)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate dateTimeWithEpochTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}), ZoneId.systemDefault())") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID, JAVA_INSTANT) + .build(); + private final JavaTemplate dateTimeWithEpochAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}), #{any(java.time.ZoneId)})") + .imports(JAVA_DATE_TIME, JAVA_ZONE_OFFSET, JAVA_ZONE_ID, JAVA_INSTANT) + .build(); + private final JavaTemplate dateTimeWithMinTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, 0, ZoneId.systemDefault())") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) + .build(); + private final JavaTemplate dateTimeWithMinAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, 0, #{any(java.time.ZoneId)})") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) + .build(); + private final JavaTemplate dateTimeWithSecTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, ZoneId.systemDefault())") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) + .build(); + private final JavaTemplate dateTimeWithSecAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, 0, #{any(java.time.ZoneId)})") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) + .build(); + private final JavaTemplate dateTimeWithMillisTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)} * 1_000_000, ZoneId.systemDefault())") + .imports(JAVA_DATE_TIME, JAVA_ZONE_ID) + .build(); + private final JavaTemplate dateTimeWithMillisAndZoneTemplate = JavaTemplate.builder("ZonedDateTime.of(#{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)}, #{any(int)} * 1_000_000, #{any(java.time.ZoneId)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate dateTimeParseTemplate = JavaTemplate.builder("ZonedDateTime.parse(#{any(String)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate dateTimeParseWithFormatterTemplate = JavaTemplate.builder("ZonedDateTime.parse(#{any(String)}, #{any(java.time.format.DateTimeFormatter)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate toDateTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}") + .build(); + private final JavaTemplate getMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toInstant().toEpochMilli()") + .build(); + private final JavaTemplate withMillisTemplate = JavaTemplate.builder("ZonedDateTime.ofInstant(Instant.ofEpochMilli(#{any(long)}),#{any(java.time.ZonedDateTime)}.getZone())") + .imports(JAVA_DATE_TIME, JAVA_INSTANT) + .build(); + private final JavaTemplate withZoneTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withZoneSameInstant(#{any(java.time.ZoneId)})") + .build(); + private final JavaTemplate withZoneRetainFieldsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withZoneSameLocal(#{any(java.time.ZoneId)})") + .build(); + private final JavaTemplate withEarlierOffsetAtOverlapTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withEarlierOffsetAtOverlap()") + .build(); + private final JavaTemplate withLaterOffsetAtOverlapTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withLaterOffsetAtOverlap()") + .build(); + private final JavaTemplate withDateTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withYear(#{any(int)}).withMonth(#{any(int)}).withDayOfMonth(#{any(int)})") + .build(); + private final JavaTemplate withTemporalAdjusterTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(#{any(java.time.temporal.TemporalAdjuster)})") + .imports(JAVA_TEMPORAL_ADJUSTER) + .build(); + private final JavaTemplate withTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withHour(#{any(int)}).withMinute(#{any(int)}).withSecond(#{any(int)}).withNano(#{any(int)} * 1_000_000)") + .build(); + private final JavaTemplate withTimeAtStartOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.atStartOfDay(#{any(java.time.ZonedDateTime)}.getZone())") + .build(); + private final JavaTemplate withDurationAddedTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(Duration.ofMillis(#{any(long)}).multipliedBy(#{any(int)}))") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate plusReadableDurationTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(#{any(java.time.Duration)})") + .build(); + private final JavaTemplate plusYearsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusYears(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate plusMonthsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusMonths(#{any(int)})") + .build(); + private final JavaTemplate plusWeeksTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusWeeks(#{any(int)})") + .build(); + private final JavaTemplate plusDaysTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusDays(#{any(int)})") + .build(); + private final JavaTemplate plusHoursTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusHours(#{any(int)})") + .build(); + private final JavaTemplate plusMinutesTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusMinutes(#{any(int)})") + .build(); + private final JavaTemplate plusSecondsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plusSeconds(#{any(int)})") + .build(); + private final JavaTemplate plusMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.plus(Duration.ofMillis(#{any(int)}))") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate minusMillisTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minus(Duration.ofMillis(#{any(int)}))") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate minusReadableDurationTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minus(#{any(java.time.Duration)})") + .imports(JAVA_DATE_TIME, JAVA_DURATION) + .build(); + private final JavaTemplate minusYearsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusYears(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusMonthsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusMonths(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusWeeksTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusWeeks(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusDaysTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusDays(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusHoursTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusHours(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusMinutesTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusMinutes(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate minusSecondsTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.minusSeconds(#{any(int)})") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate toLocalDateTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalDateTime()") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate toLocalDateTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalDate()") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate toLocalTimeTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.toLocalTime()") + .imports(JAVA_DATE_TIME) + .build(); + private final JavaTemplate withYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withYear(#{any(int)})") + .build(); + private final JavaTemplate withWeekyearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(IsoFields.WEEK_BASED_YEAR, #{any(int)})") + .imports(JAVA_TEMPORAL_ISO_FIELDS) + .build(); + private final JavaTemplate withMonthOfYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withMonth(#{any(int)})") + .build(); + private final JavaTemplate withWeekOfWeekyearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.ALIGNED_WEEK_OF_YEAR, #{any(int)})") + .imports(JAVA_CHRONO_FIELD) + .build(); + private final JavaTemplate withDayOfYearTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withDayOfYear(#{any(int)})") + .build(); + private final JavaTemplate withDayOfMonthTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withDayOfMonth(#{any(int)})") + .build(); + private final JavaTemplate withDayOfWeekTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.DAY_OF_WEEK, #{any(int)})") + .imports(JAVA_CHRONO_FIELD) + .build(); + private final JavaTemplate withHourOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withHour(#{any(int)})") + .build(); + private final JavaTemplate withMinuteOfHourTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withMinute(#{any(int)})") + .build(); + private final JavaTemplate withSecondOfMinuteTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withSecond(#{any(int)})") + .build(); + private final JavaTemplate withMillisOfSecondTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.withNano(#{any(int)} * 1_000_000)") + .build(); + private final JavaTemplate withMillisOfDayTemplate = JavaTemplate.builder("#{any(java.time.ZonedDateTime)}.with(ChronoField.MILLI_OF_DAY, #{any(int)})") + .imports(JAVA_CHRONO_FIELD) + .build(); - private final List templates = new ArrayList() { - { - add(new MethodTemplate(newDateTime, dateTimeTemplate)); - add(new MethodTemplate(newDateTimeWithZone, dateTimeWithZoneTemplate)); - add(new MethodTemplate(newDateTimeWithEpoch, dateTimeWithEpochTemplate)); - add(new MethodTemplate(newDateTimeWithEpochAndZone, dateTimeWithEpochAndZoneTemplate)); - add(new MethodTemplate(newDateTimeWithMin, dateTimeWithMinTemplate)); - add(new MethodTemplate(newDateTimeWithMinAndZone, dateTimeWithMinAndZoneTemplate)); - add(new MethodTemplate(newDateTimeWithSec, dateTimeWithSecTemplate)); - add(new MethodTemplate(newDateTimeWithSecAndZone, dateTimeWithSecAndZoneTemplate)); - add(new MethodTemplate(newDateTimeWithMillis, dateTimeWithMillisTemplate)); - add(new MethodTemplate(newDateTimeWithMillisAndZone, dateTimeWithMillisAndZoneTemplate)); - add(new MethodTemplate(dateTimeNow, dateTimeTemplate)); - add(new MethodTemplate(dateTimeNowWithZone, dateTimeWithZoneTemplate)); - add(new MethodTemplate(dateTimeParse, dateTimeParseTemplate)); - add(new MethodTemplate(dateTimeParseWithFormatter, dateTimeParseWithFormatterTemplate)); - add(new MethodTemplate(toDateTime, toDateTimeTemplate)); - add(new MethodTemplate(toDateTimeWithZone, withZoneTemplate)); - add(new MethodTemplate(getMillis, getMillisTemplate)); - add(new MethodTemplate(withMillis, withMillisTemplate, m -> { - J.MethodInvocation mi = (J.MethodInvocation) m; - return new Expression[] {mi.getArguments().get(0), mi.getSelect()}; - })); - add(new MethodTemplate(withZone, withZoneTemplate)); - add(new MethodTemplate(withZoneRetainFields, withZoneRetainFieldsTemplate)); - add(new MethodTemplate(withEarlierOffsetAtOverlap, withEarlierOffsetAtOverlapTemplate)); - add(new MethodTemplate(withLaterOffsetAtOverlap, withLaterOffsetAtOverlapTemplate)); - add(new MethodTemplate(withDate, withDateTemplate)); - add(new MethodTemplate(withDateLocalDate, withTemporalAdjusterTemplate)); - add(new MethodTemplate(withTime, withTimeTemplate)); - add(new MethodTemplate(withTimeLocalTime, withTemporalAdjusterTemplate)); - add(new MethodTemplate(withTimeAtStartOfDay, withTimeAtStartOfDayTemplate)); - add(new MethodTemplate(withDurationAdded, withDurationAddedTemplate)); - add(new MethodTemplate(plusLong, plusMillisTemplate)); - add(new MethodTemplate(plusReadableDuration, plusReadableDurationTemplate)); - add(new MethodTemplate(plusYears, plusYearsTemplate)); - add(new MethodTemplate(plusMonths, plusMonthsTemplate)); - add(new MethodTemplate(plusWeeks, plusWeeksTemplate)); - add(new MethodTemplate(plusDays, plusDaysTemplate)); - add(new MethodTemplate(plusHours, plusHoursTemplate)); - add(new MethodTemplate(plusMinutes, plusMinutesTemplate)); - add(new MethodTemplate(plusSeconds, plusSecondsTemplate)); - add(new MethodTemplate(plusMillis, plusMillisTemplate)); - add(new MethodTemplate(minusLong, minusMillisTemplate)); - add(new MethodTemplate(minusReadableDuration, minusReadableDurationTemplate)); - add(new MethodTemplate(minusYears, minusYearsTemplate)); - add(new MethodTemplate(minusMonths, minusMonthsTemplate)); - add(new MethodTemplate(minusWeeks, minusWeeksTemplate)); - add(new MethodTemplate(minusDays, minusDaysTemplate)); - add(new MethodTemplate(minusHours, minusHoursTemplate)); - add(new MethodTemplate(minusMinutes, minusMinutesTemplate)); - add(new MethodTemplate(minusSeconds, minusSecondsTemplate)); - add(new MethodTemplate(minusMillis, minusMillisTemplate)); - add(new MethodTemplate(toLocalDateTime, toLocalDateTimeTemplate)); - add(new MethodTemplate(toLocalDate, toLocalDateTemplate)); - add(new MethodTemplate(toLocalTime, toLocalTimeTemplate)); - add(new MethodTemplate(withYear, withYearTemplate)); - add(new MethodTemplate(withWeekyear, withWeekyearTemplate)); - add(new MethodTemplate(withMonthOfYear, withMonthOfYearTemplate)); - add(new MethodTemplate(withWeekOfWeekyear, withWeekOfWeekyearTemplate)); - add(new MethodTemplate(withDayOfYear, withDayOfYearTemplate)); - add(new MethodTemplate(withDayOfMonth, withDayOfMonthTemplate)); - add(new MethodTemplate(withDayOfWeek, withDayOfWeekTemplate)); - add(new MethodTemplate(withHourOfDay, withHourOfDayTemplate)); - add(new MethodTemplate(withMinuteOfHour, withMinuteOfHourTemplate)); - add(new MethodTemplate(withSecondOfMinute, withSecondOfMinuteTemplate)); - add(new MethodTemplate(withMillisOfSecond, withMillisOfSecondTemplate)); - add(new MethodTemplate(withMillisOfDay, withMillisOfDayTemplate)); - } - }; + private final List templates = new ArrayList() { + { + add(new MethodTemplate(newDateTime, dateTimeTemplate)); + add(new MethodTemplate(newDateTimeWithZone, dateTimeWithZoneTemplate)); + add(new MethodTemplate(newDateTimeWithEpoch, dateTimeWithEpochTemplate)); + add(new MethodTemplate(newDateTimeWithEpochAndZone, dateTimeWithEpochAndZoneTemplate)); + add(new MethodTemplate(newDateTimeWithMin, dateTimeWithMinTemplate)); + add(new MethodTemplate(newDateTimeWithMinAndZone, dateTimeWithMinAndZoneTemplate)); + add(new MethodTemplate(newDateTimeWithSec, dateTimeWithSecTemplate)); + add(new MethodTemplate(newDateTimeWithSecAndZone, dateTimeWithSecAndZoneTemplate)); + add(new MethodTemplate(newDateTimeWithMillis, dateTimeWithMillisTemplate)); + add(new MethodTemplate(newDateTimeWithMillisAndZone, dateTimeWithMillisAndZoneTemplate)); + add(new MethodTemplate(dateTimeNow, dateTimeTemplate)); + add(new MethodTemplate(dateTimeNowWithZone, dateTimeWithZoneTemplate)); + add(new MethodTemplate(dateTimeParse, dateTimeParseTemplate)); + add(new MethodTemplate(dateTimeParseWithFormatter, dateTimeParseWithFormatterTemplate)); + add(new MethodTemplate(toDateTime, toDateTimeTemplate)); + add(new MethodTemplate(toDateTimeWithZone, withZoneTemplate)); + add(new MethodTemplate(getMillis, getMillisTemplate)); + add(new MethodTemplate(withMillis, withMillisTemplate, m -> { + J.MethodInvocation mi = (J.MethodInvocation) m; + return new Expression[]{mi.getArguments().get(0), mi.getSelect()}; + })); + add(new MethodTemplate(withZone, withZoneTemplate)); + add(new MethodTemplate(withZoneRetainFields, withZoneRetainFieldsTemplate)); + add(new MethodTemplate(withEarlierOffsetAtOverlap, withEarlierOffsetAtOverlapTemplate)); + add(new MethodTemplate(withLaterOffsetAtOverlap, withLaterOffsetAtOverlapTemplate)); + add(new MethodTemplate(withDate, withDateTemplate)); + add(new MethodTemplate(withDateLocalDate, withTemporalAdjusterTemplate)); + add(new MethodTemplate(withTime, withTimeTemplate)); + add(new MethodTemplate(withTimeLocalTime, withTemporalAdjusterTemplate)); + add(new MethodTemplate(withTimeAtStartOfDay, withTimeAtStartOfDayTemplate)); + add(new MethodTemplate(withDurationAdded, withDurationAddedTemplate)); + add(new MethodTemplate(plusLong, plusMillisTemplate)); + add(new MethodTemplate(plusReadableDuration, plusReadableDurationTemplate)); + add(new MethodTemplate(plusYears, plusYearsTemplate)); + add(new MethodTemplate(plusMonths, plusMonthsTemplate)); + add(new MethodTemplate(plusWeeks, plusWeeksTemplate)); + add(new MethodTemplate(plusDays, plusDaysTemplate)); + add(new MethodTemplate(plusHours, plusHoursTemplate)); + add(new MethodTemplate(plusMinutes, plusMinutesTemplate)); + add(new MethodTemplate(plusSeconds, plusSecondsTemplate)); + add(new MethodTemplate(plusMillis, plusMillisTemplate)); + add(new MethodTemplate(minusLong, minusMillisTemplate)); + add(new MethodTemplate(minusReadableDuration, minusReadableDurationTemplate)); + add(new MethodTemplate(minusYears, minusYearsTemplate)); + add(new MethodTemplate(minusMonths, minusMonthsTemplate)); + add(new MethodTemplate(minusWeeks, minusWeeksTemplate)); + add(new MethodTemplate(minusDays, minusDaysTemplate)); + add(new MethodTemplate(minusHours, minusHoursTemplate)); + add(new MethodTemplate(minusMinutes, minusMinutesTemplate)); + add(new MethodTemplate(minusSeconds, minusSecondsTemplate)); + add(new MethodTemplate(minusMillis, minusMillisTemplate)); + add(new MethodTemplate(toLocalDateTime, toLocalDateTimeTemplate)); + add(new MethodTemplate(toLocalDate, toLocalDateTemplate)); + add(new MethodTemplate(toLocalTime, toLocalTimeTemplate)); + add(new MethodTemplate(withYear, withYearTemplate)); + add(new MethodTemplate(withWeekyear, withWeekyearTemplate)); + add(new MethodTemplate(withMonthOfYear, withMonthOfYearTemplate)); + add(new MethodTemplate(withWeekOfWeekyear, withWeekOfWeekyearTemplate)); + add(new MethodTemplate(withDayOfYear, withDayOfYearTemplate)); + add(new MethodTemplate(withDayOfMonth, withDayOfMonthTemplate)); + add(new MethodTemplate(withDayOfWeek, withDayOfWeekTemplate)); + add(new MethodTemplate(withHourOfDay, withHourOfDayTemplate)); + add(new MethodTemplate(withMinuteOfHour, withMinuteOfHourTemplate)); + add(new MethodTemplate(withSecondOfMinute, withSecondOfMinuteTemplate)); + add(new MethodTemplate(withMillisOfSecond, withMillisOfSecondTemplate)); + add(new MethodTemplate(withMillisOfDay, withMillisOfDayTemplate)); + } + }; - public static List getTemplates() { - return new DateTimeTemplates().templates; - } + public static List getTemplates() { + return new DateTimeTemplates().templates; + } } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/DurationTemplates.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/DurationTemplates.java index e5016af94f..d0912dd748 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/DurationTemplates.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/DurationTemplates.java @@ -27,144 +27,144 @@ @NoArgsConstructor public class DurationTemplates { - private final MethodMatcher parse = new MethodMatcher(JODA_DURATION + " parse(String)"); - private final MethodMatcher standardDays = new MethodMatcher(JODA_DURATION + " standardDays(long)"); - private final MethodMatcher standardHours = new MethodMatcher(JODA_DURATION + " standardHours(long)"); - private final MethodMatcher standardMinutes = new MethodMatcher(JODA_DURATION + " standardMinutes(long)"); - private final MethodMatcher standardSeconds = new MethodMatcher(JODA_DURATION + " standardSeconds(long)"); - private final MethodMatcher millis = new MethodMatcher(JODA_DURATION + " millis(long)"); - - private final MethodMatcher newDuration = new MethodMatcher(JODA_DURATION + "(long)"); - private final MethodMatcher newDurationWithInstants = new MethodMatcher(JODA_DURATION + "(long,long)"); - - private final MethodMatcher getStandardDays = new MethodMatcher(JODA_DURATION + " getStandardDays()"); - private final MethodMatcher getStandardHours = new MethodMatcher(JODA_DURATION + " getStandardHours()"); - private final MethodMatcher getStandardMinutes = new MethodMatcher(JODA_DURATION + " getStandardMinutes()"); - private final MethodMatcher getStandardSeconds = new MethodMatcher(JODA_DURATION + " getStandardSeconds()"); - - private final MethodMatcher toDuration = new MethodMatcher(JODA_DURATION + " toDuration()"); - - private final MethodMatcher toStandardDays = new MethodMatcher(JODA_DURATION + " toStandardDays()"); - private final MethodMatcher toStandardHours = new MethodMatcher(JODA_DURATION + " toStandardHours()"); - private final MethodMatcher toStandardMinutes = new MethodMatcher(JODA_DURATION + " toStandardMinutes()"); - private final MethodMatcher toStandardSeconds = new MethodMatcher(JODA_DURATION + " toStandardSeconds()"); - - private final MethodMatcher withMillis = new MethodMatcher(JODA_DURATION + " withMillis(long)"); - private final MethodMatcher withDurationAdded = new MethodMatcher(JODA_DURATION + " withDurationAdded(long,int)"); - private final MethodMatcher withDurationAddedReadable = new MethodMatcher(JODA_DURATION + " withDurationAdded(" + JODA_READABLE_DURATION + ",int)"); - - private final MethodMatcher plusLong = new MethodMatcher(JODA_DURATION + " plus(long)"); - private final MethodMatcher plusReadable = new MethodMatcher(JODA_DURATION + " plus(" + JODA_READABLE_DURATION + ")"); - private final MethodMatcher minusLong = new MethodMatcher(JODA_DURATION + " minus(long)"); - private final MethodMatcher minusReadable = new MethodMatcher(JODA_DURATION + " minus(" + JODA_READABLE_DURATION + ")"); - - private final MethodMatcher multipliedBy = new MethodMatcher(JODA_DURATION + " multipliedBy(long)"); - private final MethodMatcher dividedBy = new MethodMatcher(JODA_DURATION + " dividedBy(long)"); - - private final MethodMatcher negated = new MethodMatcher(JODA_DURATION + " negated()"); - private final MethodMatcher abs = new MethodMatcher(JODA_DURATION + " abs()"); - - private final JavaTemplate parseTemplate = JavaTemplate.builder("Duration.parse(#{any(String)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate standardDaysTemplate = JavaTemplate.builder("Duration.ofDays(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate standardHoursTemplate = JavaTemplate.builder("Duration.ofHours(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate standardMinutesTemplate = JavaTemplate.builder("Duration.ofMinutes(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate standardSecondsTemplate = JavaTemplate.builder("Duration.ofSeconds(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate millisTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - - private final JavaTemplate newDurationTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate newDurationWithInstantsTemplate = JavaTemplate.builder("Duration.between(Instant.ofEpochMilli(#{any(long)}), Instant.ofEpochMilli(#{any(long)}))") - .imports(JAVA_DURATION, JAVA_INSTANT) - .build(); - private final JavaTemplate toDurationTemplate = JavaTemplate.builder("#{any(java.time.Duration)}") - .build(); - private final JavaTemplate toDaysTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toDays()") - .build(); - private final JavaTemplate toHoursTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toHours()") - .build(); - private final JavaTemplate toMinutesTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toMinutes()") - .build(); - private final JavaTemplate getSecondsTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.getSeconds()") - .build(); - private final JavaTemplate ofMillisTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") - .imports(JAVA_DURATION) - .build(); - private final JavaTemplate withDurationAddedTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plusMillis(#{any(long)} * #{any(int)})") - .build(); - private final JavaTemplate withDurationAddedReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plus(#{any(java.time.Duration)}.multipliedBy(#{any(int)}))") - .build(); - private final JavaTemplate plusLongTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plusMillis(#{any(long)})") - .build(); - private final JavaTemplate plusReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plus(#{any(java.time.Duration)})") - .build(); - private final JavaTemplate minusLongTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.minusMillis(#{any(long)})") - .build(); - private final JavaTemplate minusReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.minus(#{any(java.time.Duration)})") - .build(); - private final JavaTemplate multipliedByTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.multipliedBy(#{any(long)})") - .build(); - private final JavaTemplate dividedByTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.dividedBy(#{any(long)})") - .build(); - private final JavaTemplate negatedTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.negated()") - .build(); - private final JavaTemplate absTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.abs()") - .build(); - - private final List templates = new ArrayList() { - { - add(new MethodTemplate(parse, parseTemplate)); - add(new MethodTemplate(standardDays, standardDaysTemplate)); - add(new MethodTemplate(standardHours, standardHoursTemplate)); - add(new MethodTemplate(standardMinutes, standardMinutesTemplate)); - add(new MethodTemplate(standardSeconds, standardSecondsTemplate)); - add(new MethodTemplate(millis, millisTemplate)); - - add(new MethodTemplate(newDuration, newDurationTemplate)); - add(new MethodTemplate(newDurationWithInstants, newDurationWithInstantsTemplate)); - - add(new MethodTemplate(getStandardDays, toDaysTemplate)); - add(new MethodTemplate(getStandardHours, toHoursTemplate)); - add(new MethodTemplate(getStandardMinutes, toMinutesTemplate)); - add(new MethodTemplate(getStandardSeconds, getSecondsTemplate)); - - add(new MethodTemplate(toDuration, toDurationTemplate)); - - add(new MethodTemplate(toStandardDays, toDaysTemplate)); - add(new MethodTemplate(toStandardHours, toHoursTemplate)); - add(new MethodTemplate(toStandardMinutes, toMinutesTemplate)); - add(new MethodTemplate(toStandardSeconds, getSecondsTemplate)); - - add(new MethodTemplate(withMillis, ofMillisTemplate, m -> new Expression[]{m.getArguments().get(0)})); - add(new MethodTemplate(withDurationAdded, withDurationAddedTemplate)); - add(new MethodTemplate(withDurationAddedReadable, withDurationAddedReadableTemplate)); - - add(new MethodTemplate(plusLong, plusLongTemplate)); - add(new MethodTemplate(plusReadable, plusReadableTemplate)); - add(new MethodTemplate(minusLong, minusLongTemplate)); - add(new MethodTemplate(minusReadable, minusReadableTemplate)); - - add(new MethodTemplate(multipliedBy, multipliedByTemplate)); - add(new MethodTemplate(dividedBy, dividedByTemplate)); - - add(new MethodTemplate(negated, negatedTemplate)); - add(new MethodTemplate(abs, absTemplate)); + private final MethodMatcher parse = new MethodMatcher(JODA_DURATION + " parse(String)"); + private final MethodMatcher standardDays = new MethodMatcher(JODA_DURATION + " standardDays(long)"); + private final MethodMatcher standardHours = new MethodMatcher(JODA_DURATION + " standardHours(long)"); + private final MethodMatcher standardMinutes = new MethodMatcher(JODA_DURATION + " standardMinutes(long)"); + private final MethodMatcher standardSeconds = new MethodMatcher(JODA_DURATION + " standardSeconds(long)"); + private final MethodMatcher millis = new MethodMatcher(JODA_DURATION + " millis(long)"); + + private final MethodMatcher newDuration = new MethodMatcher(JODA_DURATION + "(long)"); + private final MethodMatcher newDurationWithInstants = new MethodMatcher(JODA_DURATION + "(long,long)"); + + private final MethodMatcher getStandardDays = new MethodMatcher(JODA_DURATION + " getStandardDays()"); + private final MethodMatcher getStandardHours = new MethodMatcher(JODA_DURATION + " getStandardHours()"); + private final MethodMatcher getStandardMinutes = new MethodMatcher(JODA_DURATION + " getStandardMinutes()"); + private final MethodMatcher getStandardSeconds = new MethodMatcher(JODA_DURATION + " getStandardSeconds()"); + + private final MethodMatcher toDuration = new MethodMatcher(JODA_DURATION + " toDuration()"); + + private final MethodMatcher toStandardDays = new MethodMatcher(JODA_DURATION + " toStandardDays()"); + private final MethodMatcher toStandardHours = new MethodMatcher(JODA_DURATION + " toStandardHours()"); + private final MethodMatcher toStandardMinutes = new MethodMatcher(JODA_DURATION + " toStandardMinutes()"); + private final MethodMatcher toStandardSeconds = new MethodMatcher(JODA_DURATION + " toStandardSeconds()"); + + private final MethodMatcher withMillis = new MethodMatcher(JODA_DURATION + " withMillis(long)"); + private final MethodMatcher withDurationAdded = new MethodMatcher(JODA_DURATION + " withDurationAdded(long,int)"); + private final MethodMatcher withDurationAddedReadable = new MethodMatcher(JODA_DURATION + " withDurationAdded(" + JODA_READABLE_DURATION + ",int)"); + + private final MethodMatcher plusLong = new MethodMatcher(JODA_DURATION + " plus(long)"); + private final MethodMatcher plusReadable = new MethodMatcher(JODA_DURATION + " plus(" + JODA_READABLE_DURATION + ")"); + private final MethodMatcher minusLong = new MethodMatcher(JODA_DURATION + " minus(long)"); + private final MethodMatcher minusReadable = new MethodMatcher(JODA_DURATION + " minus(" + JODA_READABLE_DURATION + ")"); + + private final MethodMatcher multipliedBy = new MethodMatcher(JODA_DURATION + " multipliedBy(long)"); + private final MethodMatcher dividedBy = new MethodMatcher(JODA_DURATION + " dividedBy(long)"); + + private final MethodMatcher negated = new MethodMatcher(JODA_DURATION + " negated()"); + private final MethodMatcher abs = new MethodMatcher(JODA_DURATION + " abs()"); + + private final JavaTemplate parseTemplate = JavaTemplate.builder("Duration.parse(#{any(String)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate standardDaysTemplate = JavaTemplate.builder("Duration.ofDays(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate standardHoursTemplate = JavaTemplate.builder("Duration.ofHours(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate standardMinutesTemplate = JavaTemplate.builder("Duration.ofMinutes(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate standardSecondsTemplate = JavaTemplate.builder("Duration.ofSeconds(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate millisTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + + private final JavaTemplate newDurationTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate newDurationWithInstantsTemplate = JavaTemplate.builder("Duration.between(Instant.ofEpochMilli(#{any(long)}), Instant.ofEpochMilli(#{any(long)}))") + .imports(JAVA_DURATION, JAVA_INSTANT) + .build(); + private final JavaTemplate toDurationTemplate = JavaTemplate.builder("#{any(java.time.Duration)}") + .build(); + private final JavaTemplate toDaysTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toDays()") + .build(); + private final JavaTemplate toHoursTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toHours()") + .build(); + private final JavaTemplate toMinutesTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.toMinutes()") + .build(); + private final JavaTemplate getSecondsTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.getSeconds()") + .build(); + private final JavaTemplate ofMillisTemplate = JavaTemplate.builder("Duration.ofMillis(#{any(long)})") + .imports(JAVA_DURATION) + .build(); + private final JavaTemplate withDurationAddedTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plusMillis(#{any(long)} * #{any(int)})") + .build(); + private final JavaTemplate withDurationAddedReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plus(#{any(java.time.Duration)}.multipliedBy(#{any(int)}))") + .build(); + private final JavaTemplate plusLongTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plusMillis(#{any(long)})") + .build(); + private final JavaTemplate plusReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.plus(#{any(java.time.Duration)})") + .build(); + private final JavaTemplate minusLongTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.minusMillis(#{any(long)})") + .build(); + private final JavaTemplate minusReadableTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.minus(#{any(java.time.Duration)})") + .build(); + private final JavaTemplate multipliedByTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.multipliedBy(#{any(long)})") + .build(); + private final JavaTemplate dividedByTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.dividedBy(#{any(long)})") + .build(); + private final JavaTemplate negatedTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.negated()") + .build(); + private final JavaTemplate absTemplate = JavaTemplate.builder("#{any(java.time.Duration)}.abs()") + .build(); + + private final List templates = new ArrayList() { + { + add(new MethodTemplate(parse, parseTemplate)); + add(new MethodTemplate(standardDays, standardDaysTemplate)); + add(new MethodTemplate(standardHours, standardHoursTemplate)); + add(new MethodTemplate(standardMinutes, standardMinutesTemplate)); + add(new MethodTemplate(standardSeconds, standardSecondsTemplate)); + add(new MethodTemplate(millis, millisTemplate)); + + add(new MethodTemplate(newDuration, newDurationTemplate)); + add(new MethodTemplate(newDurationWithInstants, newDurationWithInstantsTemplate)); + + add(new MethodTemplate(getStandardDays, toDaysTemplate)); + add(new MethodTemplate(getStandardHours, toHoursTemplate)); + add(new MethodTemplate(getStandardMinutes, toMinutesTemplate)); + add(new MethodTemplate(getStandardSeconds, getSecondsTemplate)); + + add(new MethodTemplate(toDuration, toDurationTemplate)); + + add(new MethodTemplate(toStandardDays, toDaysTemplate)); + add(new MethodTemplate(toStandardHours, toHoursTemplate)); + add(new MethodTemplate(toStandardMinutes, toMinutesTemplate)); + add(new MethodTemplate(toStandardSeconds, getSecondsTemplate)); + + add(new MethodTemplate(withMillis, ofMillisTemplate, m -> new Expression[]{m.getArguments().get(0)})); + add(new MethodTemplate(withDurationAdded, withDurationAddedTemplate)); + add(new MethodTemplate(withDurationAddedReadable, withDurationAddedReadableTemplate)); + + add(new MethodTemplate(plusLong, plusLongTemplate)); + add(new MethodTemplate(plusReadable, plusReadableTemplate)); + add(new MethodTemplate(minusLong, minusLongTemplate)); + add(new MethodTemplate(minusReadable, minusReadableTemplate)); + + add(new MethodTemplate(multipliedBy, multipliedByTemplate)); + add(new MethodTemplate(dividedBy, dividedByTemplate)); + + add(new MethodTemplate(negated, negatedTemplate)); + add(new MethodTemplate(abs, absTemplate)); + } + }; + + public static List getTemplates() { + return new DurationTemplates().templates; } - }; - - public static List getTemplates() { - return new DurationTemplates().templates; - } } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/MethodTemplate.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/MethodTemplate.java index 06aa731966..61e13d809c 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/MethodTemplate.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/MethodTemplate.java @@ -26,46 +26,46 @@ @Value public class MethodTemplate { - MethodMatcher matcher; - JavaTemplate template; - Function templateArgsFunc; + MethodMatcher matcher; + JavaTemplate template; + Function templateArgsFunc; - public MethodTemplate(MethodMatcher matcher, JavaTemplate template) { - this(matcher, template, m -> { - Expression select = isInstanceCall(m) ? ((J.MethodInvocation) m).getSelect() : null; + public MethodTemplate(MethodMatcher matcher, JavaTemplate template) { + this(matcher, template, m -> { + Expression select = isInstanceCall(m) ? ((J.MethodInvocation) m).getSelect() : null; - if (m.getArguments().isEmpty() || m.getArguments().get(0) instanceof J.Empty) { - return select != null ? new Expression[]{select} : new Expression[0]; - } + if (m.getArguments().isEmpty() || m.getArguments().get(0) instanceof J.Empty) { + return select != null ? new Expression[]{select} : new Expression[0]; + } - Expression[] args = m.getArguments().toArray(new Expression[0]); - if (select != null) { - Expression[] newArgs = new Expression[args.length + 1]; - newArgs[0] = select; - System.arraycopy(args, 0, newArgs, 1, args.length); - return newArgs; - } - return args; - }); - } - - public MethodTemplate(MethodMatcher matcher, JavaTemplate template, Function templateArgsFunc) { - this.matcher = matcher; - this.template = template; - this.templateArgsFunc = templateArgsFunc; - } - - private static boolean isInstanceCall(MethodCall m) { - if (!(m instanceof J.MethodInvocation)) { - return false; + Expression[] args = m.getArguments().toArray(new Expression[0]); + if (select != null) { + Expression[] newArgs = new Expression[args.length + 1]; + newArgs[0] = select; + System.arraycopy(args, 0, newArgs, 1, args.length); + return newArgs; + } + return args; + }); } - J.MethodInvocation mi = (J.MethodInvocation) m; - if (mi.getSelect() instanceof J.FieldAccess) { - return ((J.FieldAccess) mi.getSelect()).getName().getFieldType() != null; + + public MethodTemplate(MethodMatcher matcher, JavaTemplate template, Function templateArgsFunc) { + this.matcher = matcher; + this.template = template; + this.templateArgsFunc = templateArgsFunc; } - if (mi.getSelect() instanceof J.Identifier) { - return ((J.Identifier) mi.getSelect()).getFieldType() != null; + + private static boolean isInstanceCall(MethodCall m) { + if (!(m instanceof J.MethodInvocation)) { + return false; + } + J.MethodInvocation mi = (J.MethodInvocation) m; + if (mi.getSelect() instanceof J.FieldAccess) { + return ((J.FieldAccess) mi.getSelect()).getName().getFieldType() != null; + } + if (mi.getSelect() instanceof J.Identifier) { + return ((J.Identifier) mi.getSelect()).getFieldType() != null; + } + return true; } - return true; - } } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassNames.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassNames.java index a4b9226488..a9d56b0e40 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassNames.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassNames.java @@ -18,33 +18,33 @@ import java.util.regex.Pattern; public class TimeClassNames { - public static final Pattern JODA_CLASS_PATTERN = Pattern.compile("org\\.joda\\.time\\..*"); - // Joda-Time classes - public static final String JODA_TIME_PKG = "org.joda.time"; - public static final String JODA_BASE_DATE_TIME = JODA_TIME_PKG + ".base.BaseDateTime"; - public static final String JODA_DATE_TIME = JODA_TIME_PKG + ".DateTime"; - public static final String JODA_DATE_TIME_ZONE = JODA_TIME_PKG + ".DateTimeZone"; - public static final String JODA_TIME_FORMAT = JODA_TIME_PKG + ".format.DateTimeFormat"; - public static final String JODA_TIME_FORMATTER = JODA_TIME_PKG + ".format.DateTimeFormatter"; - public static final String JODA_LOCAL_DATE = JODA_TIME_PKG + ".LocalDate"; - public static final String JODA_LOCAL_TIME = JODA_TIME_PKG + ".LocalTime"; - public static final String JODA_DATE_TIME_FIELD_TYPE = JODA_TIME_PKG + ".DateTimeFieldType"; - public static final String JODA_DURATION_FIELD_TYPE = JODA_TIME_PKG + ".DurationFieldType"; - public static final String JODA_DURATION = JODA_TIME_PKG + ".Duration"; - public static final String JODA_READABLE_DURATION = JODA_TIME_PKG + ".ReadableDuration"; + public static final Pattern JODA_CLASS_PATTERN = Pattern.compile("org\\.joda\\.time\\..*"); + // Joda-Time classes + public static final String JODA_TIME_PKG = "org.joda.time"; + public static final String JODA_BASE_DATE_TIME = JODA_TIME_PKG + ".base.BaseDateTime"; + public static final String JODA_DATE_TIME = JODA_TIME_PKG + ".DateTime"; + public static final String JODA_DATE_TIME_ZONE = JODA_TIME_PKG + ".DateTimeZone"; + public static final String JODA_TIME_FORMAT = JODA_TIME_PKG + ".format.DateTimeFormat"; + public static final String JODA_TIME_FORMATTER = JODA_TIME_PKG + ".format.DateTimeFormatter"; + public static final String JODA_LOCAL_DATE = JODA_TIME_PKG + ".LocalDate"; + public static final String JODA_LOCAL_TIME = JODA_TIME_PKG + ".LocalTime"; + public static final String JODA_DATE_TIME_FIELD_TYPE = JODA_TIME_PKG + ".DateTimeFieldType"; + public static final String JODA_DURATION_FIELD_TYPE = JODA_TIME_PKG + ".DurationFieldType"; + public static final String JODA_DURATION = JODA_TIME_PKG + ".Duration"; + public static final String JODA_READABLE_DURATION = JODA_TIME_PKG + ".ReadableDuration"; - // Java Time classes - public static final String JAVA_TIME_PKG = "java.time"; - public static final String JAVA_DATE_TIME = JAVA_TIME_PKG + ".ZonedDateTime"; - public static final String JAVA_DURATION = JAVA_TIME_PKG + ".Duration"; - public static final String JAVA_ZONE_OFFSET = JAVA_TIME_PKG + ".ZoneOffset"; - public static final String JAVA_ZONE_ID = JAVA_TIME_PKG + ".ZoneId"; - public static final String JAVA_INSTANT = JAVA_TIME_PKG + ".Instant"; - public static final String JAVA_TIME_FORMATTER = JAVA_TIME_PKG + ".format.DateTimeFormatter"; - public static final String JAVA_TIME_FORMAT_STYLE = JAVA_TIME_PKG + ".format.FormatStyle"; - public static final String JAVA_TEMPORAL_ADJUSTER = JAVA_TIME_PKG + ".temporal.TemporalAdjuster"; - public static final String JAVA_LOCAL_DATE = JAVA_TIME_PKG + ".LocalDate"; - public static final String JAVA_LOCAL_TIME = JAVA_TIME_PKG + ".LocalTime"; - public static final String JAVA_TEMPORAL_ISO_FIELDS = JAVA_TIME_PKG + ".temporal.IsoFields"; - public static final String JAVA_CHRONO_FIELD = JAVA_TIME_PKG + ".temporal.ChronoField"; + // Java Time classes + public static final String JAVA_TIME_PKG = "java.time"; + public static final String JAVA_DATE_TIME = JAVA_TIME_PKG + ".ZonedDateTime"; + public static final String JAVA_DURATION = JAVA_TIME_PKG + ".Duration"; + public static final String JAVA_ZONE_OFFSET = JAVA_TIME_PKG + ".ZoneOffset"; + public static final String JAVA_ZONE_ID = JAVA_TIME_PKG + ".ZoneId"; + public static final String JAVA_INSTANT = JAVA_TIME_PKG + ".Instant"; + public static final String JAVA_TIME_FORMATTER = JAVA_TIME_PKG + ".format.DateTimeFormatter"; + public static final String JAVA_TIME_FORMAT_STYLE = JAVA_TIME_PKG + ".format.FormatStyle"; + public static final String JAVA_TEMPORAL_ADJUSTER = JAVA_TIME_PKG + ".temporal.TemporalAdjuster"; + public static final String JAVA_LOCAL_DATE = JAVA_TIME_PKG + ".LocalDate"; + public static final String JAVA_LOCAL_TIME = JAVA_TIME_PKG + ".LocalTime"; + public static final String JAVA_TEMPORAL_ISO_FIELDS = JAVA_TIME_PKG + ".temporal.IsoFields"; + public static final String JAVA_CHRONO_FIELD = JAVA_TIME_PKG + ".temporal.ChronoField"; } diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeZoneTemplates.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeZoneTemplates.java index ee55c031c7..1ee2be95fc 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeZoneTemplates.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeZoneTemplates.java @@ -24,33 +24,33 @@ import static org.openrewrite.java.migrate.joda.templates.TimeClassNames.*; public class TimeZoneTemplates { - private final MethodMatcher zoneForID = new MethodMatcher(JODA_DATE_TIME_ZONE + " forID(String)"); - private final MethodMatcher zoneForOffsetHours = new MethodMatcher(JODA_DATE_TIME_ZONE + " forOffsetHours(int)"); - private final MethodMatcher zoneForOffsetHoursMinutes = new MethodMatcher(JODA_DATE_TIME_ZONE + " forOffsetHoursMinutes(int, int)"); - private final MethodMatcher zoneForTimeZone = new MethodMatcher(JODA_DATE_TIME_ZONE + " forTimeZone(java.util.TimeZone)"); + private final MethodMatcher zoneForID = new MethodMatcher(JODA_DATE_TIME_ZONE + " forID(String)"); + private final MethodMatcher zoneForOffsetHours = new MethodMatcher(JODA_DATE_TIME_ZONE + " forOffsetHours(int)"); + private final MethodMatcher zoneForOffsetHoursMinutes = new MethodMatcher(JODA_DATE_TIME_ZONE + " forOffsetHoursMinutes(int, int)"); + private final MethodMatcher zoneForTimeZone = new MethodMatcher(JODA_DATE_TIME_ZONE + " forTimeZone(java.util.TimeZone)"); - private final JavaTemplate zoneIdOfTemplate = JavaTemplate.builder("ZoneId.of(#{any(String)})") - .imports(JAVA_ZONE_ID) - .build(); - private final JavaTemplate zoneOffsetHoursTemplate = JavaTemplate.builder("ZoneOffset.ofHours(#{any(int)})") - .imports(JAVA_ZONE_OFFSET) - .build(); - private final JavaTemplate zoneOffsetHoursMinutesTemplate = JavaTemplate.builder("ZoneOffset.ofHoursMinutes(#{any(int)}, #{any(int)})") - .imports(JAVA_ZONE_OFFSET) - .build(); - private final JavaTemplate timeZoneToZoneIdTemplate = JavaTemplate.builder("#{any(java.util.TimeZone)}.toZoneId()") - .build(); + private final JavaTemplate zoneIdOfTemplate = JavaTemplate.builder("ZoneId.of(#{any(String)})") + .imports(JAVA_ZONE_ID) + .build(); + private final JavaTemplate zoneOffsetHoursTemplate = JavaTemplate.builder("ZoneOffset.ofHours(#{any(int)})") + .imports(JAVA_ZONE_OFFSET) + .build(); + private final JavaTemplate zoneOffsetHoursMinutesTemplate = JavaTemplate.builder("ZoneOffset.ofHoursMinutes(#{any(int)}, #{any(int)})") + .imports(JAVA_ZONE_OFFSET) + .build(); + private final JavaTemplate timeZoneToZoneIdTemplate = JavaTemplate.builder("#{any(java.util.TimeZone)}.toZoneId()") + .build(); - private final List templates = new ArrayList() { - { - add(new MethodTemplate(zoneForID, zoneIdOfTemplate)); - add(new MethodTemplate(zoneForOffsetHours, zoneOffsetHoursTemplate)); - add(new MethodTemplate(zoneForOffsetHoursMinutes, zoneOffsetHoursMinutesTemplate)); - add(new MethodTemplate(zoneForTimeZone, timeZoneToZoneIdTemplate)); - } - }; + private final List templates = new ArrayList() { + { + add(new MethodTemplate(zoneForID, zoneIdOfTemplate)); + add(new MethodTemplate(zoneForOffsetHours, zoneOffsetHoursTemplate)); + add(new MethodTemplate(zoneForOffsetHoursMinutes, zoneOffsetHoursMinutesTemplate)); + add(new MethodTemplate(zoneForTimeZone, timeZoneToZoneIdTemplate)); + } + }; - public static List getTemplates() { - return new TimeZoneTemplates().templates; - } + public static List getTemplates() { + return new TimeZoneTemplates().templates; + } } diff --git a/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeVisitorTest.java b/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeVisitorTest.java index a6f14d5d04..37b8734d99 100644 --- a/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeVisitorTest.java +++ b/src/test/java/org/openrewrite/java/migrate/joda/JodaTimeVisitorTest.java @@ -42,7 +42,7 @@ void migrateNewDateTime() { import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import java.util.TimeZone; - + class A { public void foo() { System.out.println(new DateTime()); @@ -64,7 +64,7 @@ public void foo() { import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.TimeZone; - + class A { public void foo() { System.out.println(ZonedDateTime.now()); @@ -94,7 +94,7 @@ void migrateDateTimeStaticCalls() { import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; import java.util.TimeZone; - + class A { public void foo() { System.out.println(DateTime.now()); @@ -109,7 +109,7 @@ public void foo() { import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.TimeZone; - + class A { public void foo() { System.out.println(ZonedDateTime.now()); @@ -133,7 +133,7 @@ void migrateDateTimeInstanceCalls() { import org.joda.time.DateTimeZone; import org.joda.time.Duration; import java.util.TimeZone; - + class A { public void foo() { System.out.println(new DateTime().toDateTime()); @@ -192,7 +192,7 @@ public void foo() { import java.time.temporal.ChronoField; import java.time.temporal.IsoFields; import java.util.TimeZone; - + class A { public void foo() { System.out.println(ZonedDateTime.now()); @@ -255,7 +255,7 @@ void migrateDateTimeZone() { """ import org.joda.time.DateTimeZone; import java.util.TimeZone; - + class A { public void foo() { System.out.println(DateTimeZone.UTC); @@ -270,7 +270,7 @@ public void foo() { import java.time.ZoneId; import java.time.ZoneOffset; import java.util.TimeZone; - + class A { public void foo() { System.out.println(ZoneOffset.UTC); @@ -292,7 +292,7 @@ void migrateDateTimeFormatter() { java( """ import org.joda.time.format.DateTimeFormat; - + class A { public void foo() { System.out.println(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); @@ -316,7 +316,7 @@ public void foo() { """ import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; - + class A { public void foo() { System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); @@ -348,7 +348,7 @@ void migrateJodaDuration() { java( """ import org.joda.time.Duration; - + class A { public void foo() { System.out.println(Duration.standardDays(1L)); @@ -380,7 +380,7 @@ public void foo() { """ import java.time.Duration; import java.time.Instant; - + class A { public void foo() { System.out.println(Duration.ofDays(1L)); @@ -427,7 +427,7 @@ public void foo() { """, """ import java.time.format.DateTimeFormatter; - + class A { public void foo() { System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")); @@ -445,7 +445,7 @@ void migrateJodaTypeExpressionReferencingNonJodaTypeVar() { java( """ import org.joda.time.DateTime; - + class A { public void foo() { long millis = DateTime.now().getMillis(); @@ -475,7 +475,7 @@ void dontChangeMethodAccessOnVariable() { java( """ import org.joda.time.DateTime; - + class A { public void foo() { DateTime dt = new DateTime(); @@ -498,13 +498,13 @@ void dontChangeIncompatibleType() { java( """ import org.joda.time.DateTime; - + class A { public void foo() { new B().print(new DateTime()); // print is public method accepting DateTime, not handled yet } } - + class B { public void print(DateTime dateTime) { System.out.println(dateTime); @@ -523,7 +523,7 @@ void dontChangeMethodsWithUnhandledArguments() { """ import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; - + class A { public void foo() { // DateTimeFormat.forStyle is unhandled so parent method should not be changed