redhat-developer / redhat-developer/vscode-java

Inline Method leaves unqualified instance method call inside local class when inlining into static context

オープン
#4,464 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
TypeScript
スター
2.3k
フォーク
546
平均マージ
20時間 1分
マージ済み PR(30日)
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();
    }
}

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Inline Method の実装から始め、I01 の例を使って問題を再現します。static な main コンテキストに移動されたローカルクラスに焦点を当ててください。元の obj.f() のレシーバーが H.g() 内でどのように扱われるかを追跡します。生成された helper() 呼び出しがレシーバーで修飾され、リファクタリング後の Java コードがコンパイルできれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。