Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Formatting code with intellij plugin and using the jar gives different results

Abierto
#566 8 comentarios 3 reacciones 1 asignado Ver en GitHub

@plumpy ya está trabajando en esto.

Desde el 23/2/2021.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

IntelliJ

If I format the following file using the intellij plugin (IDE version: Ultimate 2020.2.4 / plugin version: google-java-format 1.9.0.0. ) I get different result when compared to using the jar on the command line.

original example file:

package x;

public class test2 {

  static final String LONG_STRING = "This is a long string that makes the total line length for this line over 100 characters";

  static final String ANOTHER_LONG_STRING =
      "This is another long string but this line is under 100 characters "
      + "and this line is also under 100 characters "
      + "but this line is over 100 characters and will not be reformatted to under 100 characters using the intellij plugin but will be reformatted to under 100 characters using the jar.";

  public test2() {
    int x=1;if(x==1){x=2;}else{x=3;}
  }

}

after formatting using intellij plugin (using menu code / reformat code) I get this:

package x;

public class test2 {

  static final String LONG_STRING =
      "This is a long string that makes the total line length for this line over 100 characters";

  static final String ANOTHER_LONG_STRING =
      "This is another long string but this line is under 100 characters "
          + "and this line is also under 100 characters "
          + "but this line is over 100 characters and will not be reformatted to under 100 characters using the intellij plugin but will be reformatted to under 100 characters using the jar.";

  public test2() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}

And after formatting on the command line:

/tmp $ java -version
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+11, mixed mode)
/tmp $ cksum ~/lib/google-java-format-1.9-all-deps.jar
2002751029 3404610 ~/lib/google-java-format-1.9-all-deps.jar
 /tmp $ java -jar ~/lib/google-java-format-1.9-all-deps.jar ./test2.java

I get this:

package x;

public class test2 {

  static final String LONG_STRING =
      "This is a long string that makes the total line length for this line over 100 characters";

  static final String ANOTHER_LONG_STRING =
      "This is another long string but this line is under 100 characters and this line is also"
          + " under 100 characters but this line is over 100 characters and will not be"
          + " reformatted to under 100 characters using the intellij plugin but will be"
          + " reformatted to under 100 characters using the jar.";

  public test2() {
    int x = 1;
    if (x == 1) {
      x = 2;
    } else {
      x = 3;
    }
  }
}
Lenguaje dominante
Java
Estrellas
6.2k
Forks
936
Merge medio
6 min
PR fusionados (30 d)
3

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de google/google-java-format

Todos los issues de google/google-java-format

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.