You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "maffe (via GitHub)" <gi...@apache.org> on 2024/09/17 17:21:44 UTC

[I] Refactor record to class and vice versa [netbeans]

maffe opened a new issue, #7762:
URL: https://github.com/apache/netbeans/issues/7762

   ### Description
   
   NetBeans should assist in changing records to classes and classes to records.
   
   It already provides a hint to convert some classes to an interface, for example an empty class like
   ```
   public class Empty {
   }
   ```
   can be converted to
   ```
   public interface Empty {
   }
   ```
   with two clicks.
   
   A record like
   ```
   public record R(String name) {
   }
   ```
   should be converted to something like
   ```
   public class R {
   
       private String name;
   
       public R(final String name) {
           this.name = name;
       }
   
       public String name() {
           return name;
       }
   }
   ```
   and a class
   ```
   public class C {
   
       private String name;
   
       public C(String name) {
           this.name = name;
       }
   
       public String getName() {
           return name;
       }
   }
   ```
   to
   ```
   public record C(String name) {
   
       public String getName() {
           return name;
       }
   }
   ```
   Unfortunately classes and records have different naming conventions for getters, but that can be addressed in further refactoring steps.
   
   ### Use case/motivation
   
   Sometimes I start with a class or a record and later the other type seems to be more appropriate, but it is tedious to do the conversion by hand.
   
   ### Related issues
   
   Currently the refactoring action „Move inner to outer level“ converts records to classes, but I don’t think it should do that and it’s broken anyway (#7044, #6139).
   
   ### Are you willing to submit a pull request?
   
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Refactor record to class and vice versa [netbeans]

Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on issue #7762:
URL: https://github.com/apache/netbeans/issues/7762#issuecomment-2651006252

   Stopped on 2025-02-11.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [I] Refactor record to class and vice versa [netbeans]

Posted by "homberghp (via GitHub)" <gi...@apache.org>.
homberghp commented on issue #7762:
URL: https://github.com/apache/netbeans/issues/7762#issuecomment-2624147213

   I will try my hand on this one. Functionally it seems simple enough, based on what I learned from issue #7043 and issue #7044.
   
   ## on the choices to make.
   
   The first version will be very basic. Froe **class to record** will only accept a class with final fields. 
   It will leave any method intact because code based reasoning on the implementations of `toString()`, `hashCode()`, and `equals(Object other) ` is too much effort for this little feature. Testing whether a given implementation of said methods deviates from the automatic in record is brittle at best, so best avoid it. If the user wants the records default, he can simply delete his own after the transformation.
   
   The implementation will simply rewrite the AST to be a record and then save that.
   
   Something similar will apply for **record to class** any given methods will be taken over to the record. Any missing methods (`hashCode()`, `equals(Object other)`, `toString()`) can easily be generated with the already available code generators in Netbeans, so I will not duplicate that here.
   The hard/new part for me will be the proper integration into the menus.
   
   I will create a branch issue7762 on my fork and create a PR when I am ready for preview.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists