redhat-developer / redhat-developer/vscode-java
Java code formatter improperly formats one-liner conditions and loops, and after method signatures
还没有人认领这个 Issue。
- 主要语言
- 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:
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:
The same goes with one-liner loops:
A sample file saved unformatted:
Main.zip
Log file generated by RedHat formatting server:
redhat_server_log.txt
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用代码示例或附加的 Main.zip 重现缩进问题,并检查 redhat_server_log.txt 以了解格式化器上下文。当单行条件和循环,以及多行方法签名后的新行,在不影响其他格式的情况下获得预期缩进时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100