Skip to content

Fix expression print#223

Merged
clementdessoude merged 10 commits intojhipster:masterfrom
Shaolans:fix-expression-print
Jun 21, 2019
Merged

Fix expression print#223
clementdessoude merged 10 commits intojhipster:masterfrom
Shaolans:fix-expression-print

Conversation

@Shaolans
Copy link
Member

@Shaolans Shaolans commented Jun 20, 2019

Fix the breaking expression discussed here

Example:
input:

public class Args {

  public static void main(String[] args) {
    if(test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1) {

    }
}
}

output:

public class Args {

  public static void main(String[] args) {
    if (
      test == 1 &&
      test == 1 &&
      test == 1 &&
      test == 1 &&
      test == 1 &&
      test == 1 &&
      test == 1 &&
      test == 1
    ) {}
  }
}

However, it will only breaks on && and ||.
if we have if(aVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable == aVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable2), it won't break on ==.
Is it bothersome ? I am not sure... It will be hard to tell how we should break each operator since we just have an array on all operators on the cstnode.

I am working with @clement26695 to make it work 👍

@Shaolans Shaolans requested review from bd82 and clementdessoude June 20, 2019 12:04
@clementdessoude
Copy link
Contributor

Shouldn't the catch Clause be updated too?

@clementdessoude
Copy link
Contributor

Maybe also add some test case which should not break? Like:

if (test1 == true && test2 != null)

@Shaolans
Copy link
Member Author

Shaolans commented Jun 20, 2019

Shouldn't the catch Clause be updated too?

This is already handled by a different "rule", but it add the | on the new line and not on the end of line. However when I add it to the end of line, my visual studio linter for Java does not recognize the "Exception"
example

try {} catch (
      Exception
      | Exception
      | Exception
      | Exception
      | Exception
      | Exception
      | Exception
      | Exception
      | Exception
      | Exception e
    ) {}

This one is recognized.

try {} catch (
      Exception |
      Exception |
      Exception |
      Exception |
      Exception |
      Exception |
      Exception |
      Exception |
      Exception |
      Exception e
    ) {}

Not this one.

@Shaolans Shaolans changed the title Fix expression print WIP: Fix expression print Jun 20, 2019
@Shaolans Shaolans changed the title WIP: Fix expression print Fix expression print Jun 20, 2019
@Shaolans
Copy link
Member Author

Shaolans commented Jun 20, 2019

this looks good now.

Example:
input:

if(test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && test == 1 && mljkejkoerjkotjerjtlejlrtj == elkrjtklerjtklejklrtjkeljtklejklrtjklejrtkljeklrjtklejrkltjelkrtjl) {

    }

output:

if (
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  test == 1 &&
  mljkejkoerjkotjerjtlejlrtj ==
    elkrjtklerjtklejklrtjkeljtklejklrtjklejrtkljeklrjtklejrkltjelkrtjl
 ) {}

@Shaolans Shaolans requested a review from clementdessoude June 21, 2019 07:16
Copy link
Contributor

@clementdessoude clementdessoude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little comment, but LGTM.

I find the binary expression code much cleaner now 👍

const { groups, sortedBinOps } = separateTokensIntoGroups(ctx);
const allSegment = [];
let tmpSegment = [];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to clarify what those variables mean.

Maybe:

  • groupsOfOperator instead of groups,
  • sortedBinaryOperators instead of sortedBinOps,
  • segmentsSplittedByBinaryOperator instead of allSegments
  • currentSegment instead of tmpSegment

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep those variables fits it better 👍

@Shaolans Shaolans removed the request for review from bd82 June 21, 2019 10:02
@clementdessoude clementdessoude merged commit b241c6b into jhipster:master Jun 21, 2019
@Shaolans Shaolans deleted the fix-expression-print branch June 25, 2019 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants