Comments (7)
I think it would be weird to have the .of
not line-broken, but have the .getOrElseThrow
line-broken later. It seems like prettier and prettier-java both try to follow the philosophy where as soon as one element in an expression get line-broken, then every element gets line-broken (same idea for call chains and method arguments). This avoids any heuristics so you get simple, predictable behavior, it scales up very well to arbitrarily complex nested expressions, and the downside is you end up with a lot of linebreaks
from prettier-java.
I believe the TypeScript equivalent of the input you provided would roughly be:
class Example {
private static createInstance<T extends Group>(entity: Group): (ctor: { newInstance: (...args: unknown[]) => unknown }) => T {
return ctor => Try.of(() => {
var ng = ctor.newInstance(entity.getId(), entity.getSystemGenerated(), entity.getVersionKey()) as T;
return ng;
})
.getOrElseThrow(ex => new RuntimeException(ex));
}
}
Such an input yields the following output from Prettier (playground):
class Example {
private static createInstance<T extends Group>(
entity: Group,
): (ctor: { newInstance: (...args: unknown[]) => unknown }) => T {
return ctor =>
Try.of(() => {
var ng = ctor.newInstance(entity.getId(), entity.getSystemGenerated(), entity.getVersionKey()) as T;
return ng;
}).getOrElseThrow(ex => new RuntimeException(ex));
}
}
I think an appropriate action item for this issue would be to try to align Prettier Java's formatting of chained method invocations with lambda parameters more closely with Prettier TypeScript's.
from prettier-java.
I think the difference is that the .getOrElseThrow
isn't line-broken.
from prettier-java.
is this consistent with typescript?
var result = ImmutableFindCustomerCommand
.builder()
.correlationId(UUID.randomUUID().toString())
.build()
.apply(customerApi)
.block();
again, I thought that formatter did
var result = ImmutableFindCustomerCommand.builder()
.correlationId(UUID.randomUUID().toString())
.build()
.apply(customerApi)
.block();
thinking this is just another example of this same issue.
P.S. Not to be an impatient jerk... is this ticket something you think will be fixed within the next few weeks, or is it a ways off. Only asking because I'm implementing prettier where java is the primary concern, and if anyone asks I'd love to have an answer if asked.
from prettier-java.
maybe, although, now I find myself trying to recall if typescript has static functions on classes. usually if you want a static function it doesn't go into a class itself. Do what though wilt. I just thought it was odd, but it's not a huge deal. We were comparing style outputs between a few formatters, and I generally use this one ;) .
from prettier-java.
Yeah that looks closer (If not the same?) As what I said I was expecting.
from prettier-java.
Hey, thanks for the good work, I suspect the PR fixed this, but in case it didn't, I figured I'd share it now. Checkstyle alerted me. Although, I'm not certain if it's actually complaining about this issue, it thinks the indentation is wrong on line ... well 3 of the markdown excerpt. I have to refactor this code anyways. Might be a 2nd issue here though.
Supplier<String> gitVersion = () ->
Optional
.ofNullable(porcelainGit.describe())
.map(v -> v.substring(1))
.map(v -> v.contains("g") ? v + "-SNAPSHOT" : v)
.orElse(null);
from prettier-java.
Related Issues (20)
- Migrate e2e pipeline tests to use Java 17 HOT 2
- Record pattern in exhaustive switch syntax unsupported HOT 4
- Support JDK 22 multiple patterns in switch case label HOT 3
- Support preview feature "Unnamed Classes and Instance main Methods "
- Support JDK 22 string templates HOT 1
- [FEATURE REQUEST] make online playground please HOT 2
- Add formatted examples to readme
- Global formatter on macOS - cannot find package 'prettier-plugin-java' HOT 1
- checkstyle inconsistent with prettier HOT 2
- Make use of "Bracket Line" option
- (switch) case with braces not consistent with checkstyle HOT 2
- checkstyle RightCurly not correct when there are comments HOT 1
- Unexpected new line when assigning to a class member
- How do specify plugins without requiring a fully qualified path? HOT 1
- sort module-info
- prettier doesn't correct EmptyLineSeparator for checkstyle with comments
- Regression: more builder chaining being off
- Wrap long javadoc lines where possible
- Unknown 'es5' option for 'trailingComma' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-java.