redhat-developer / redhat-developer/vscode-java

Java code formatter improperly formats one-liner conditions and loops, and after method signatures

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

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

typing
主要言語
TypeScript
スター
2.3k
フォーク
546
平均マージ
20時間 1分
マージ済み PR(30日)
11

説明

The Java code formatter is working improperly after single-line conditions, loops, and specifically after multiline method signatures. For example, consider the following code segment:

public static List<List<Integer>> combinationSum(
        int[] candidates, int target) {

    return new ArrayList<>();
}

Now, if you hit Enter after the opening curly brace, the cursor will be jumped right to the next line with unexpected indentation:

Unexpected indentation

Environment
  • Operating System: Windows 10 22H2
  • JDK version: javac 17.0.10
  • Visual Studio Code version: 1.86.2
  • Java extension version: 1.28.1
Steps To Reproduce

The brief information above represents just one example. Here is more with single-line conditions and loops:

Consider this code segment:

public static List<List<Integer>> combinationSum(
        int[] candidates, int target) {
    int x = 5;

    if (x > 5)
        System.out.println("ok");
    else
        System.out.println("Not ok");

        

    return new ArrayList<>();
}

Have a look after the end of the else statement. It should not be indented in such cases.
Here is the screenshot:

Indentation problem in conditional statements

The same goes with one-liner loops:

Indentation problem in loop statements

A sample file saved unformatted:
Main.zip

Log file generated by RedHat formatting server:
redhat_server_log.txt

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

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

はじめの一歩

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

調査の方向性

まず、コード例または添付された Main.zip を使ってインデントの問題を再現し、フォーマッターのコンテキストを確認するために redhat_server_log.txt を調べます。1 行の条件文とループ、および複数行のメソッドシグネチャの後の新しい行が、他のフォーマットに影響を与えることなく期待どおりにインデントされれば完了です。

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

評価

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

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

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