redhat-developer / redhat-developer/vscode-java

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

未关闭
#3,502 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

typing
主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用代码示例或附加的 Main.zip 重现缩进问题,并检查 redhat_server_log.txt 以了解格式化器上下文。当单行条件和循环,以及多行方法签名后的新行,在不影响其他格式的情况下获得预期缩进时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。