Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Apply var to method invocations

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

メンテナーはふだん 1 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
java
領域
tooling

調査の方向性

まず、#217 で参照されている既存の基本的な var の作業と、そのレシピテストを確認します。次に、Java メソッドの戻り値の型とジェネリック呼び出しがどのように表現されているかを追跡します。提示されている変更前と変更後の例を受け入れ条件として使用し、short、byte、および戻り値の型が一致しない場合について明記された除外も含めます。この issue では実装ファイルやテストパスが示されていないため、まずそれらを特定する必要があります。

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

説明

recipe

What problem are you trying to solve?

While developing basic var usage with #217 java reveals that local variable type inference is a big field, so we decided to split.
One open area is applying var to variable declarations initialized by method invocations.

What precondition(s) should be checked before applying this recipe?

varis not applicable if

  1. the method has return type ´short´ or byte
  2. the method's return type does not match the type definition in the left-hand side

Describe the situation before applying the recipe

class A {
    String getHello() {
        return "Hello Rewrite";
    }
    void simple(String bar) {
        String msg = getHello(); // (1)
        System.out.println(msg);
    }
    void generic(String bar) {
        List<String> msgs = List.of("Hello", "Rewrite"); // (2)
        System.out.println(msgs);
    }
}

Describe the situation after applying the recipe


class A {
    String getHello() {
        return "Hello Rewrite";
    }
    void simple(String bar) {
        var msg = getHello(); // (1)
        System.out.println(msg);
    }
    void generic(String bar) {
        var msgs = List.of("Hello", "Rewrite"); // (2)
        System.out.println(msgs);
    }
}

Have you considered any alternatives or workarounds?

An alternative would be to no support var in combination with methods

Any additional context

It may be a good idea to implement this as an independent recipe, this would increase separation of concern and make configuration easier.

Are you interested in contributing this recipe to OpenRewrite?

Yes, but need additional support understanding generics.

主要言語
Java
スター
156
フォーク
129
平均マージ
3日 8時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

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

openrewrite/rewrite-migrate-java のほかの issue

openrewrite/rewrite-migrate-java の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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