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

Intellij Plugin breaks method inlining and variable extraction from inside if condition

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

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

評価

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

調査の方向性

Issue 内の Java 再現から始め、if 条件内でのメソッドのインライン化および変数の抽出と IntelliJ plugin のフォーマット処理の相互作用を調査してください。plugin を有効にした状態で変換を再現し、無効にした場合の結果と比較してください。refactoring が不要な if (true) を挿入せず、エラーを報告せず、フォーマットを壊したままにしなくなれば完了です。

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

説明

IntelliJ

Consider the following code and try inlining isEmpty2:

import java.util.Collection;
import java.util.List;

public class InliningWithJavaFormat {
  static boolean isEmpty(Collection<?> c) {
    return c == null || c.isEmpty();
  }

  static boolean isEmpty2(Collection<?> c) {
    return isEmpty(c);
  }

  public static void main(String[] args){
    var pojo = new MyPojo();
    if (pojo != null && !isEmpty2(pojo.getCollection())) {
      System.out.println("empty");
    }
  }

  static class MyPojo {
    Collection<String> getCollection() {
      return List.of();
    }
  }
}

Not only does it fail (without reporting it), but it adds an additional if (true):

  public static void main(String[] args){
    var pojo = new MyPojo();
    if (pojo != null && !isEmpty2(pojo.getCollection())) {
      if (true) {
        System.out.println("empty");
      }
    }
  }

with the plugin disabled, it works:

  public static void main(String[] args){
    var pojo = new MyPojo();
    if (pojo != null) {
      Collection<?> c = pojo.getCollection();
      if (!isEmpty(c)) {
        System.out.println("empty");
      }
    }
  }

(not the ideal result but at least it does not fail)

In addition, when I do that on my actual project I get an error notification from the plugin and the formatting gets broken:
error notification
(I did not try to reproduce this with an MRE, I guess it is a side effect of the first issue)

主要言語
Java
スター
6.2k
フォーク
936
平均マージ
6分
マージ済み PR(30日)
3

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

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

はじめの一歩

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

google/google-java-format のほかの issue

google/google-java-format の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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