Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Class To Record

Aperta
#391 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Inizia con la Java 17 Records specification collegata nella issue ed esamina la Lombok value-to-record implementation referenziata tramite issue #141. Definisci le precondizioni per le classi supportate e le trasformazioni interessate prima di implementarle; il lavoro completato deve includere la ristrutturazione delle classi idonee, l’aggiornamento delle chiamate ai getter e la rimozione dei metodi canonici ove applicabile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

recipe

What problem are you trying to solve?

It would be neat to have a capability to convert a class to a record

What precondition(s) should be checked before applying this recipe?

  • Java 17+
  • Should probably have an arg to specify the type to transform (versus rampantly changing every eligible class to a record)
  • Check for things that would disqualify the class from being a record, such as:
    • type must not participate in inheritance
    • type must be immutable
      • type must not have setters (or maybe make an extra-fancy version of this recipe which can replaces usages of setters with a constructor call) (and/or maybe include a force-override option for this no-setters rule)
      • non-static fields must be final or effectively final
    • any custom constructor(s) must delegate to another constructor via this(...) in the first line

Describe the situation before applying the recipe

See Java's specification for Records for context:
https://docs.oracle.com/en/java/javase/17/language/records.html#GUID-6699E26F-4A9B-4393-A08B-1E47D4B2D263

Describe the situation after applying the recipe

  • The targeted class should be restructured as a record
  • Method invocations of the type's getters should be replaced with record property accessors (eg getColor() to color())
  • (bonus points) "canonical" equals/hashCode/toString implementations are removed in favor of the default

Have you considered any alternatives or workarounds?

Any additional context

The implementation for Lombok value to record likely has some useful code to reference/reuse.

This feels like a problem with many weird edge cases (even beyond what's written above), but even a naive implementation which only handles some of those scenarios could probably still be valuable, and the recipe could grow iteratively from there.

Are you interested in contributing this recipe to OpenRewrite?

Maybe; priority TBD

Lingua principale
Java
Stelle
156
Fork
130
Merge medio
3g 8h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openrewrite/rewrite-migrate-java

Tutte le issue di openrewrite/rewrite-migrate-java

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.