Recipe Name:
Convert print() to format()
Description:
Convert print() to format()
Level:
error
Language:
  • java
Tags:
  • framework specific
  • java.time
  • Joda-Time
  • quality
Documentation

Migrate from org.joda.time.DateTimeFormatter to Java Time

Joda-Time DateTimeFormatter migrates to java.time DateTimeFormatter.

It's a same concept, an immutable formatter

Before
    DateTimeFormatter dtf = DateTimeFormat.fullDate();
After
    java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
References
Recipe
id: scw:java.time:Joda-Time:datetimeformatter-print-readable
version: 10
metadata:
  name: Convert print() to format()
  shortDescription: Convert print() to format()
  level: error
  language: java
  enabled: true
  comment: "Searches for a print method called and provides fixes to migrate to a java.time equivalent.\n\nThis recipe is designed to match on broken code. This method originally was called by org.joda.time.format.DateTimeFormatter type, \nhowever this object type should first be migrated to java.time.format.DateTimeFormatter using the other migration recipes.\nThis recipe will then match on the broken code, and the fixes in this recipe will allow the completion of the migration.\n\nDouble check your DateTime type is compatible with your desired output format."
  descriptionFile: descriptions/datetimeformatter.html
  tags: framework specific;java.time;Joda-Time;quality
search:
  methodcall:
    args:
      1:
        anyOf:
        - type: org.joda.time.ReadablePartial
        - type: org.joda.time.ReadableInstant
        - type: java.time.temporal.TemporalAccessor
    argCount: 1
    name: print
    type: java.time.format.DateTimeFormatter
availableFixes:
- name: Rewrite to .format(TemporalAccessor)
  actions:
  - rewrite:
      to: '{{{ qualifier }}}.format({{{ arguments }}})'