redhat-developer / redhat-developer/vscode-java
Java code formatter improperly formats one-liner conditions and loops, and after method signatures
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 2.3k
- Fork
- 546
- Merge medio
- 20h 1m
- PR unite (30g)
- 11
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo i problemi di indentazione usando gli esempi di codice o il file Main.zip allegato, quindi esamina redhat_server_log.txt per il contesto del formatter. Il lavoro è completato quando le condizioni e i cicli su una sola riga, così come le nuove righe dopo le firme di metodi multilinea, ricevono l'indentazione prevista senza influire su altra formattazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100