redhat-developer / redhat-developer/vscode-java
Inline Method leaves unqualified instance method call inside local class when inlining into static context
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 2.3k
- 派生
- 546
- 平均合并
- 20 小时 1 分钟
- 30 天内合并 PR
- 11
描述
Description
Inline Method produces uncompilable code when inlining an instance method that contains a local class into the static method main.
Before refactoring, the local class H is declared inside the instance method f(). The call helper() inside H.g() is valid because it is implicitly bound to the enclosing I01 instance.
After applying Inline Method to the invocation obj.f(), the local class H is moved into the static method main. However, the call inside H.g() remains:
return helper();
At this point, there is no implicit I01.this available in the static context. The call should be qualified with the original receiver, for example:
return obj.helper();
The refactored code no longer compiles.
Code before refactoring
public class I01 {
public static void main(String[] args) {
I01 obj = new I01();
// Refactoring operation: Inline Method
// Target invocation: obj.f()
int result = obj.f();
System.out.println(result);
}
int helper() {
return 7;
}
int f() {
class H {
int g() {
return helper();
}
}
return H.class.getSimpleName().length();
}
}
Code after refactoring
public class I01 {
public static void main(String[] args) {
I01 obj = new I01();
class H {
int g() {
return helper();
}
}
// Refactoring operation: Inline Method
// Target invocation: obj.f()
int result = H.class.getSimpleName().length();
System.out.println(result);
}
int helper() {
return 7;
}
int f() {
class H {
int g() {
return helper();
}
}
return H.class.getSimpleName().length();
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Inline Method 的实现开始,并使用 I01 示例重现该问题,重点关注被移动到静态 main 上下文中的局部类。跟踪原始 obj.f() 的接收者在 H.g() 内部是如何处理的;完成标准是生成的 helper() 调用带有接收者限定,并且重构后的 Java 代码能够编译。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100