Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Make Static Refactoring] Make static refactoring produce uncompilable code for a method uses outer class properties #1824

Open
RETester66 opened this issue Dec 2, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@RETester66
Copy link

Steps to reproduce

The input program is following:

public class Foo {
    private int counter;

    public Foo(int initialCounter) {
        this.counter = initialCounter;
    }

    void toBeRefactored() { // make static refactoring on this method
        new Foo(counter + 10) {
            void toImplement() {
                // Calling outer class method directly
                Foo.this.toCall();
            }
        }.toImplement();
    }

    void toCall() {
        System.out.println("Counter: " + counter);
    }

    public static void main(String[] args) {
        Foo foo = new Foo(5);
        foo.toBeRefactored();
    }
}

Left click toBeRefactored(), then right click -> Refactor -> Make Static, use the default configuration shown below, click OK:

image

The refactoring is performed without any warning or exception. The refactored program is following, which contains syntax error:

image

Environment

OS Version

Windows 10, 64-bit Operating System, x64-based processor

Eclipse Version

Eclipse IDE for Enterprise Java and Web Developers (includes Incubating components)
Version: 2024-09 (4.33.0)
Build id: 20240905-0614

JDK Version

java version "22.0.1" 2024-04-16
Java(TM) SE Runtime Environment (build 22.0.1+8-16)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)

@jukzi
Copy link
Contributor

jukzi commented Dec 2, 2024

The refactoring was added with #689
@CodeLtDave can you take a look?

@jukzi jukzi added the bug Something isn't working label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants