apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.63k stars 840 forks source link

Fail to introduce method #7427

Open usersuis opened 3 months ago

usersuis commented 3 months ago

Apache NetBeans version

Apache NetBeans 21

What happened

When I tried to perform "introduce method" refactoring on "int b= 10;" using refactoring tool in NetBeans, it displayed a warning and failed to do the refactoring.

Language / Project Type / NetBeans Component

Java Maven Project Java Application

How to reproduce

Input Program:

public interface I1 {
    int foo(int a);
}

interface I2 {
    I1 i1= (a) -> {
        int b= 10; 
        return a + b;
    };
}

Steps: Select "int b = 10;" Refactor -> Introduce -> Method

Actual Result: a warning: "Invalid Selection."

Expected Result: (from Refactoring tool of IntelliJ)

    public interface I1 {
        int foo(int a);
    }

    interface I2 {
        I1 i1 = (a) -> {
            int b = getB();
            return a + b;
        };

        private static int getB() {
            int b = 10; 
            return b;
        }
    }

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

22.0.1

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

It always occurs.

Are you willing to submit a pull request?

No