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

   ### Apache NetBeans version
   
   Apache NetBeans 32
   
   ### What happened
   
   When the **Inline Method** refactoring is applied to a method call that 
appears
   as the initializer of one declarator inside a **comma-separated local 
variable
   declaration statement** (e.g. `int a = 1, b = method(), c = 3;`), NetBeans
   splices the inlined method body into the declaration list instead of hoisting
   its local declarations above the enclosing statement. The resulting source
   does **not compile**:
   
   - The enclosing type keyword is duplicated on the inlined variable: `int int 
b = ...`.
   - Method-body local declarations are interleaved into the declarator list,
     leaving a dangling comma after `int a = 1,`.
   
   
[NewClass.java](https://github.com/user-attachments/files/35399296/NewClass.java)
   
   ### Language / Project Type / NetBeans Component
   
   Java
   
   ### How to reproduce
   
   1.Create a Java class with the code shown in "Before" below.
   2. Place the caret on `computeMiddle()` inside the call in `run()`.
   3. Run **Refactor > Inline...** (`Ctrl+Alt+N`) and confirm the inline 
operation.
   
   ### Did this work correctly in an earlier version?
   
   Apache NetBeans 31
   
   ### Operating System
   
   Windows 11
   
   ### JDK
   
   JDK 21
   
   ### Apache NetBeans packaging
   
   Apache NetBeans binary zip
   
   ### Anything else
   
   ## Before (compiles and runs correctly)
   ```java
   package generated.refactoring.tests;
   
   public class NewClass {
   
       static int computeMiddle() {
           int x = 2;
           int y = 3;
           return x * y;
       }
   
       static void run() {
           int a = 1, b = computeMiddle(), c = 3;
           System.out.println("a=" + a + " b=" + b + " c=" + c);
       }
   
       public static void main(String[] args) {
           run();
       }
   }
   ```
   Expected output: a=1 b=6 c=3.
   ### Actual behavior — after Inline Method (does NOT compile)
   ```java
   public class NewClass {
   
       static void run() {
           int a = 1,
               int x = 2;
               int y = 3;
           int int b = x * y, c = 3;
           System.out.println("a=" + a + " b=" + b + " c=" + c);
       }
   
       public static void main(String[] args) {
           run();
       }
   }
   ```
   Observed problems:
   1. int int b = x * y, c = 3; — duplicated type keyword (int int), illegal 
start of expression.
   2. int a = 1, ends with a dangling comma, immediately followed by another
   local declaration int x = 2; inside the same declaration list.
   3. The method-body locals x, y are placed between declarators of the
   enclosing statement, rather than before the declaration statement.
   4. The refactoring completes without any warning that the result is
   syntactically invalid; the editor marks the broken lines with red errors.
   
   ### 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to