This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 254748

Summary: "Introduce Variable" ignores function usages in previous lines
Product: cnd Reporter: soldatov <soldatov>
Component: Code ModelAssignee: Alexander Simon <alexvsimon>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.1   
Hardware: PC   
OS: Solaris   
Issue Type: DEFECT Exception Reporter:

Description soldatov 2015-08-26 09:46:58 UTC
Java sample:
- select latest foo(1), press Alt+Shift+V and press OK
==> IDE replaces
===============================================================
package javaapplication3;

public class JavaApplication3 {

    public static int foo(int x) {
        return 2 * x;
    }

    public static void main(String[] args) {
        int x = foo(1) + foo(2);
        if (true) {
            int y = foo(2) + foo(1);
            int z = foo(1) + foo(1); // <-- replace latest foo(1)
        }
    }
    
}
===============================================================
on
===============================================================
    public static void main(String[] args) {
        final int foo = foo(1); // <-- new line
        int x = foo + foo(2); // <-- replaced
        if (true) {
            int y = foo(2) + foo; // <-- replaced
            int z = foo + foo; // <-- replaced (2 times)
        }
    }

===============================================================
In C++ IDE will replace
===============================================================
int foo(int x) {
    return 2 * x;
}

int main() {
    int x = foo(1) + foo(2);
    if (true) {
        int y = foo(2) + foo(1);
        int z = foo(1) + foo(1); // <-- replace latest foo(1)
    }
}
===============================================================
on
int main() {
    int x = foo(1) + foo(2);
    if (true) {
        int y = foo(2) + foo(1);
        int foo = foo(1); // <-- new line
        int z = foo(1) + foo; // <-- replaced
    }
}
===============================================================