Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested method chains also adhere to column limit #123

Merged
merged 6 commits into from
Jan 14, 2020

Conversation

dansanduleac
Copy link
Contributor

Before this PR

#70 (and #71) failed to account for more complex expressions that contained a nested chain of method calls.

An example where it didn't do the right thing is this test.

After this PR

==COMMIT_MSG==
Nested method chains now also adhere to column limit.

Also, we've made the logic a bit more specific in terms of what are method chains.
We now only apply this restricted column limit to breaks that come before actual method calls, not field accesses or parts of a fully qualified class name.
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Jan 13, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Nested method chains now also adhere to column limit.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from iamdanfox January 13, 2020 15:33
return optional.orElseGet(
(String) () -> bar(Optional.of("some thing that is very very very looooooong")).get());
return optional.orElseGet((String) () ->
bar(Optional.of("some thing that is very very very looooooong")).get());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This changed beause it doesn't allow the dot in the bar(...).get() expression to exceed 80 chars anymore. It now ends up at exactly 80 chars, and to prove that, if I add another character to the string, then the .get() gets pushed onto the next line, as in:

return optional.orElseGet((String) () -> bar(Optional.of("some thing that is very very very loooooooong"))
        .get());

.getActualTypeArguments()[0];
Class<T> tClass = (Class<T>)
verifyNotNull((ParameterizedType) getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unclear if we want to be so strict with all methods, or if we should exempt non-side-effect-sounding methods like those that start with get[A-Z0-9]. @iamdanfox thoughts?

if (doc instanceof Break && ((Break) doc).hasColumnLimit()) {
columnBeforeLastBreak = column;
} else if (doc instanceof Level) {
// Levels might have nested levels that have a 'columnLimitBeforeLastBreak' set, so recurse.
Copy link
Contributor

Choose a reason for hiding this comment

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

This recursion seems like it could end up being pretty expensive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the integration tests take about 15s with this block commented out, and 20s with it as it is, so I think this is fine. (it's pretty much just the extremely degenerate test case that suffers)

Level innerLevel = (Level) doc;
Optional<Integer> newWidth = innerLevel.tryToFitOnOneLine(maxWidth, newState, innerLevel.getDocs());
if (!newWidth.isPresent()) {
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we return early here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It indicates that the innerLevel was not inlineable.
Currently, the only reason for that to happen is that it had a non-prefix method call (i.e. not something like foo.bar().stream()) that occurs after the column limit.
Once this happens it's no point trying to one line the parent level anymore.

@ferozco
Copy link
Contributor

ferozco commented Jan 14, 2020

👍

@bulldozer-bot bulldozer-bot bot merged commit 9a52f03 into develop Jan 14, 2020
@bulldozer-bot bulldozer-bot bot deleted the ds/long-method-chain-arg branch January 14, 2020 13:45
@svc-autorelease
Copy link
Collaborator

Released 0.3.11

bulldozer-bot bot pushed a commit that referenced this pull request Jan 21, 2020
Method chains in initializers may once again be laid onto a single next line, if they are short enough. This fixes a regression from #123 (0.3.11) where the column limit for method chains would prevent us from attempting to put the initializer on the 2nd line first and see if that works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants