Skip to content

Inconsistent formatting #299

Closed
Closed

Description

@natros

I have this code

@Transactional
public class FichasRepository {
  private final SQLQueryFactory queryFactory;

  @Inject
  public FichasRepository(SQLQueryFactory queryFactory) {
    this.queryFactory = queryFactory;
  }

  public Integer getFichaId(
      int codEscola, int codCurso, int nPlano, int nDiscipplina, int nOpcao, int anoLect) {
    QGeFichas f = Tables.GE_FICHAS;
    QIpbDisciplinas d = Tables.IPB_DISCIPLINAS;
    QIpbOpcoes o = Tables.IPB_OPCOES;
    queryFactory
        .select(f.idFicha)
        .from(f)
        .join(d)
        .on(d.codEscola.eq(f.codEscola),    d.codCurso.eq(f.codCurso),
            d.nPlano.eq(f.nPlano),          d.nDisciplina.eq(f.nDisciplina))
        .leftJoin(o)
        .on(o.codEscola.eq(d.codEscola), o.codCurso.eq(d.codCurso), o.nPlano.eq(f.nPlano));
    return null;
  }
}

when formatted form command line becomes:

@Transactional
public class FichasRepository {
  private final SQLQueryFactory queryFactory;

  @Inject
  public FichasRepository(SQLQueryFactory queryFactory) {
    this.queryFactory = queryFactory;
  }

  public Integer getFichaId(
      int codEscola, int codCurso, int nPlano, int nDiscipplina, int nOpcao, int anoLect) {
    QGeFichas f = Tables.GE_FICHAS;
    QIpbDisciplinas d = Tables.IPB_DISCIPLINAS;
    QIpbOpcoes o = Tables.IPB_OPCOES;
    queryFactory
        .select(f.idFicha)
        .from(f)
        .join(d)
        .on(
            d.codEscola.eq(f.codEscola), d.codCurso.eq(f.codCurso),
            d.nPlano.eq(f.nPlano), d.nDisciplina.eq(f.nDisciplina))
        .leftJoin(o)
        .on(o.codEscola.eq(d.codEscola), o.codCurso.eq(d.codCurso), o.nPlano.eq(f.nPlano));
    return null;
  }
}

but with

@Transactional
public class FichasRepository {
  private final SQLQueryFactory queryFactory;

  @Inject
  public FichasRepository(SQLQueryFactory queryFactory) {
    this.queryFactory = queryFactory;
  }

  public Integer getFichaId(
      int codEscola, int codCurso, int nPlano, int nDiscipplina, int nOpcao, int anoLect) {
    QGeFichas f = Tables.GE_FICHAS;
    QIpbDisciplinas d = Tables.IPB_DISCIPLINAS;
    QIpbOpcoes o = Tables.IPB_OPCOES;
    queryFactory
        .select(f.idFicha)
        .from(f)
        .join(d)
        .on(d.codEscola.eq(f.codEscola), d.codCurso.eq(f.codCurso), d.nPlano.eq(f.nPlano), d.nDisciplina.eq(f.nDisciplina))
        .leftJoin(o)
        .on(o.codEscola.eq(d.codEscola), o.codCurso.eq(d.codCurso), o.nPlano.eq(f.nPlano));
    return null;
  }
}

becomes:

@Transactional
public class FichasRepository {
  private final SQLQueryFactory queryFactory;

  @Inject
  public FichasRepository(SQLQueryFactory queryFactory) {
    this.queryFactory = queryFactory;
  }

  public Integer getFichaId(
      int codEscola, int codCurso, int nPlano, int nDiscipplina, int nOpcao, int anoLect) {
    QGeFichas f = Tables.GE_FICHAS;
    QIpbDisciplinas d = Tables.IPB_DISCIPLINAS;
    QIpbOpcoes o = Tables.IPB_OPCOES;
    queryFactory
        .select(f.idFicha)
        .from(f)
        .join(d)
        .on(
            d.codEscola.eq(f.codEscola),
            d.codCurso.eq(f.codCurso),
            d.nPlano.eq(f.nPlano),
            d.nDisciplina.eq(f.nDisciplina))
        .leftJoin(o)
        .on(o.codEscola.eq(d.codEscola), o.codCurso.eq(d.codCurso), o.nPlano.eq(f.nPlano));
    return null;
  }
}

shouldn't the result be same?

I'm using the last snapshot.

Activity

  1. cushon commented on Aug 24, 2018

    @cushon
    Collaborator

    The source of the inconsistency is that the formatter has some logic to try to preserve arguments laid out in a grid, e.g.:

    Map.of(
        "key1", 1,
        "key2", 2,
        ...);
    

    ... since that reads better than:

    Map.of("key1", 1, "key2", 2, ...);
    

    This is one of the few places the output depends on the existing formatting of the input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions