eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

[Bug][Pull Up Refactoring] Pull up refactoring for the method in anonymous class produce uncompilable code

Open
#1,766 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
59
Forks
127
Avg merge
23h 30m
Merged PRs (30d)
35

Description

## Steps to reproduce
For the following Java class:
```
public class A {
public static class BaseTargetClass {}

public static class OriginalClass {
public static int data = 20;

public static void memberMethod() {
new BaseTargetClass() {
void methodToBePulledUp() {
System.out.println("Static Context: " + data);
}
};
}
}
}
```
Left click the `methodToBePulledUp()`, then right click -> Refactor -> Pull Up, and use the default configurations (the destination is set as `BaseTargetClass` by default) as following, click Finish:

![image](https://github.com/user-attachments/assets/0c9e883c-cafa-4e57-a1d5-c4febaa1a481)

The refactoring is performed without any warning or exception. The refactored program is following, which contains syntax error:
```
public class A {
public static class BaseTargetClass {

void methodToBePulledUp() {
System.out.println("Static Context: " + data);// syntax error
}}

public static class OriginalClass {
public static int data = 20;

public static void memberMethod() {
new BaseTargetClass() {
};
}
}
}
```
## 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)

Contributor guide

Open the contributing guide

Research direction

Reproduce the Pull Up refactoring from the issue's Java example using the Eclipse Refactor → Pull Up entry point. Trace the Pull Up refactoring implementation and its handling of methods moved from an anonymous class, then verify the resulting source compiles and does not leave the reference to data out of scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.