Skip to content

Replace google-java-format with palantir-java-format #8028

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

SamCarlberg
Copy link
Member

google-java-format is terrible for nested lambdas. Palantir's fork fixes that

Most of the formatting changes are from palantir placing variable assignments on the same line as declarations, unlike google's formatter which wanted to place them on different lines

Google's formatter is terrible for nested lambda expressions. Palantir's fork fixes that
@SamCarlberg SamCarlberg requested review from PeterJohnson and a team as code owners June 16, 2025 22:55
Copy link
Contributor

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@github-actions github-actions bot added component: ntcore NetworkTables library component: cscore CameraServer library component: wpiutil WPI utility library component: wpilibj WPILib Java component: hal Hardware Abstraction Layer component: command-based WPILib Command Based Library component: wpimath Math library component: apriltag AprilTag library component: examples component: wpiunits Java units library component: epilogue Annotation-based logging library labels Jun 16, 2025
The palantir formatter broke a little bit. But, since we shouldn't reassign arguments anyway, changing the code to assign to local variables instead is still a win
Comment on lines +122 to +123
Map<String, List<Element>> usedNames = Stream.concat(
fieldsToLog.stream(), methodsToLog.stream())
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I like this

Comment on lines +224 to +234
.andThen(m_mechanism.m_subsystem.run(() -> {
m_mechanism.m_drive.accept(m_outputVolts.mut_replace(
outputSign * timer.get() * m_config.m_rampRate.in(Volts.per(Second)), Volts));
m_mechanism.m_log.accept(this);
m_recordState.accept(state);
}))
.finallyDo(() -> {
m_mechanism.m_drive.accept(Volts.of(0));
m_recordState.accept(State.kNone);
timer.stop();
})
Copy link
Member Author

Choose a reason for hiding this comment

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

This is so much nicer now

Comment on lines +362 to +365
new FunctionalCommand(() -> {}, () -> firstHasRun.set(true), interrupted -> {}, () -> {
firstWasPolled.set(true);
return true;
});
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I like this, though. Having each lambda argument on its own line was more organized, imo

Comment on lines +425 to +432
() -> {},
() -> {},
interrupted -> {
if (!interrupted) {
first.incrementAndGet();
}
},
() -> true)
Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting how this one kept one line per argument

Copy link
Member

Choose a reason for hiding this comment

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

I think this is because the lambda in the middle is multiline

@auscompgeek
Copy link
Member

auscompgeek commented Jun 18, 2025

FWIW I tried rolling out palantir-java-format at work, and found there's some subtle bugs that are fixed in google-java-format. In particular PJF has poor support for newer Java syntax, sometimes crashing on long text blocks or the ordering of class modifiers.

There's open PRs to PJF to fix some of these, but have sat for months with no response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: apriltag AprilTag library component: command-based WPILib Command Based Library component: cscore CameraServer library component: epilogue Annotation-based logging library component: examples component: hal Hardware Abstraction Layer component: ntcore NetworkTables library component: wpilibj WPILib Java component: wpimath Math library component: wpiunits Java units library component: wpiutil WPI utility library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants