wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.04k stars 606 forks source link

Use Java 17 features #6691

Closed Gold856 closed 1 month ago

Gold856 commented 1 month ago

Uses enhanced instanceof (and simplify equals methods) Uses switch expressions and arrow labels Seal and finalize some Shuffleboard classes

Starlight220 commented 1 month ago

apparently none of the linters can handle an exhaustive switch expression with no default

Are you handling the case of null? (Or otherwise proving it's not null)

Gold856 commented 1 month ago

Are you handling the case of null? (Or otherwise proving it's not null)

That's not available until Java 21. Switch expressions/statements have historically thrown NPEs until Java 21. And some of the tools say they won't warn on switch expressions because javac will check switch exhaustiveness, but they still warn anyways.

Gold856 commented 1 month ago

Apparently switch expressions are separate from arrow labels, so when the linters were warning about missing switch defaults on switch statements, they were, in fact, warning about missing switch defaults on switch statements. Defaults have been put back in, matching whatever previous logic was present.

sciencewhiz commented 1 month ago

Did you do this by hand, or did you use a tool?

Gold856 commented 1 month ago

I cherry-picked @SamCarlberg's commit that refactored a bunch of code to use Java 21 features, removed the Java 21 parts to make it Java 17 compatible, and refactored any remaining code, mostly by using VS Code's search feature with the regexes case .*: to convert case labels, else if to search for places where a switch would be better, and instanceof to convert instanceof usages.