Skip to content

Record support by transformation#3758

Draft
wadoon wants to merge 1 commit intoweigl/key-javaparser3from
weigl/recordbytrans
Draft

Record support by transformation#3758
wadoon wants to merge 1 commit intoweigl/key-javaparser3from
weigl/recordbytrans

Conversation

@wadoon
Copy link
Member

@wadoon wadoon commented Mar 11, 2026

Related Issue

This pull request is part of #3774.

Intended Change

Add a JavaTransformer to handle RecordDeclarations by down-compiling to regular Java classes. The regular pattern looks as:

#modifier record #name(#mod1 #type1 #field1, ...
                       #modN #typeN #fieldN) {
   #bodydeclarations 
}

becomes to:

#modifier #(static when inner-record) final class #name extends java.lang.Record {
   private final #mod1 #type1 #fieldn; 
   ...
   private final #mod1 #typeN #fieldN; 

   public #type1 #name1() { return #name1;} ...
   public #typeN #nameN() { return #nameN;}

   #bodydeclarations 
 
   //# if equals(Object) \not\in #bodydeclaration 
   public final boolean equals(Object o) {
      if(o instanceOf #name n) {
        return java.lang.Objects.equals(#name1, n.#name1) && ... && 
                 java.lang.Objects.equals(#nameN, n.#nameN); 
   }

   //# if hashCode() \not\in #bodydeclaration 
   public final int hashCode() {
      return java.lang.Objects.hash(#name1, ..., #nameN);
   }

   //# if toString() \not\in #bodydeclaration 
   public final String toString() {
      return #name + "["+ 
         ("#name1:" + #name1+",") + ... +
         ("#nameN:" + #nameN+",") + "]";
   }
}

Plan

  • Implement the Java rewriting
  • Contracts?!

Type of pull request

  • New feature (non-breaking change which adds functionality)
  • There are changes to the (Java) code

Ensuring quality

  • I added new test case(s) for new functionality.

@wadoon wadoon changed the base branch from main to weigl/key-javaparser3 March 11, 2026 20:14
@wadoon wadoon mentioned this pull request Mar 17, 2026
24 tasks
@wadoon wadoon force-pushed the weigl/recordbytrans branch from 851457a to bb134dd Compare March 17, 2026 08:48
@wadoon wadoon self-assigned this Mar 17, 2026
@wadoon wadoon added this to the NextMinor milestone Mar 17, 2026
@wadoon wadoon force-pushed the weigl/recordbytrans branch from d7d0301 to 06781a5 Compare March 18, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant