You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "homberghp (via GitHub)" <gi...@apache.org> on 2024/02/08 10:51:42 UTC

[I] Refactor "Move Inner to Outer level" on record drops the record details [netbeans]

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

   ### Apache NetBeans version
   
   Apache NetBeans 20
   
   ### What happened
   
   When you have an inner record like so;
   
   ```
   package example;
   import java.time.LocalDate;
   public class Example {
       public record Studentje(int id, String fullName, LocalDate dob){}
   }
   
   ```
   and for some reason you want it to be an outer class in its own file, then 
   refactor Move Inner to Outer level, then the result in the that file is
   
   ```
   package example;
   import java.time.LocalDate;
   public class Studentje {
   }
   ``` 
    dropping all record details.
   
   
   ### Language / Project Type / NetBeans Component
   
   java editor
   
   ### How to reproduce
   
   make class as above with inner record and apply refactoring  Move Inner to.
   The resulting class is no longer a record, the record component parameters including parenthesis are dropped,
   but the import (LocalDate) is handed over, but is useless because of the stripping.
   
   ### Did this work correctly in an earlier version?
   
   No / Don't know
   
   ### Operating System
   
   ubuntu 22.04, Windows 11
   
   ### JDK
   
   java 21, Java 17 at least
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   occurs always.
   
   
   ### 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 "Move Inner to Outer level" on record drops the record details [netbeans]

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

   finally solved with PR 8374


-- 
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 "Move Inner to Outer level" on record drops the record details [netbeans]

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

   Working on tests. Tests first. Then I might be able to resolve the issue, so answer to 'willing to submit a pull request is maybe'


-- 
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 "Move Inner to Outer level" on record drops the record details [netbeans]

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

   Further investigation revealed the following.
   
   After adding two times RECORD as case label in file `java.source.base/org.netbeans.api.java.source.WorkingCopy.java`, 
   and adding a non-null test in `java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java` I am able to  get nearer to a solution. 
   
   My tests now produces 
   ```
   /*                                                                              
   * Refactoring License                                                           
   */                                                                              
   package t;                                                                      
   import java.time.LocalDate;                                                     
   import java.util.Objects;                                                       
   /**                                                                             
   *                                                                               
   * @author junit                                                                 
   */                                                                              
   record F(private final int id, private final String name, private final LocalDate dob) { //<1>
     /**                                                                             
      * Validate stuff.                                                               
      */                                                                              
       public F(int id, String name, LocalDate dob) {  //<2>                                
             Objects.requireNonNull(id);                                                     
             Objects.requireNonNull(name);                                                   
              Objects.requireNonNull(dob);                                                    
              assert !name.isEmpty() && !name.isBlank();                                      
              assert dob.isAfter(LocalDate.EPOCH);                                            
         }                                                                                 
   }                                                                               
   ```
   
   from the following original inner/outer class text:
   ```
   package t;
   
   import java.time.LocalDate;
   import java.util.Objects;
   
   public class A {
   
         void useStudent() {
               F s = new F(42,"Jan Klaassen", LocalDate.now().minusDays(1));
                System.out.println("student = " + s);
           }
   
           record F(int id, String name, LocalDate dob) {
   
                   /**
                       * Validate stuff.
                        */
                   public F {
                             Objects.requireNonNull(id);
                              Objects.requireNonNull(name);
                              Objects.requireNonNull(dob);
                              assert !name.isEmpty() && !name.isBlank();
                              assert dob.isAfter(LocalDate.EPOCH);
                      }
              }
   }
   ```
   .
   
   As can be seen is
   1. The record header has wrong RecordComponent declarations (they include `private final`) 
   2. The constructor is not a compact constructor but a 'normal' one, but is not sufficient to be designated as the canonical constructor because it is missing the field assignments.
   
   So I am stuck with finding how information from the AST parsetree (classtree) is written out as java code.
   
   A simpler test with a record within a record shows that outer record is properly generated, but the inner record
   is malformed to 
   ```
   record F(private final int x, private final int y) {} 
   ```
   
   It might have to do with Templates, but I have no idea where I can find them.
   
   
   


-- 
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 "Move Inner to Outer level" on record drops the record details [netbeans]

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

   Dropped earlier pull request and created a new one based on a branch: issu7044.


-- 
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