redhat-developer / redhat-developer/vscode-java
Java code formatter improperly formats one-liner conditions and loops, and after method signatures
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- TypeScript
- Estrellas
- 2.3k
- Forks
- 546
- Merge medio
- 20 h 1 min
- PR fusionados (30 d)
- 11
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo los problemas de indentación con los ejemplos de código o el Main.zip adjunto, y revisa redhat_server_log.txt para consultar el contexto del formateador. Se considera terminado cuando las condiciones y los bucles de una sola línea, así como las líneas nuevas después de firmas de métodos multilínea, reciben la indentación esperada sin afectar a ningún otro formato.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100