A Checkstyle Rule for OpenJDK's Local Variable Type Inference Style Guidelines
Asked Answered
D

1

6

Background:

OpenJDK have released a style guide for local variable type inference.

I was looking for a checkstyle built in rule that addresses it but didn't found one.

What I'm trying to get is pretty simple but I'm not that familiar with writing custom Modules.

Example:

Allow:

  • instance creation, it's clear what's being created
var something = new Anything(); // OK
  • it's a literal, it's obvious what type it has
var something = "literal"; // OK

Violation:

  • even with good naming, no clue what's the type
var something = anything.doAnything(); // Violation
  • it improves readability to use var here
Anything<Foo<Bar>> something = new Anything<>(); // Violation
  • not a big deal but just for consistency
String something = "literal"; // Violation

Question:

Is there any existing rule I can extend / tweak to get the above? Should I try writing my own rule? I assume RegExp can handle some cases but not all.

Delphine answered 29/5, 2020 at 4:10 Comment(1)
Should I try writing my own rule - why notBoner
E
1

You can tweak this one : enter image description here

find it here : https://checkstyle.sourceforge.io/checks/coding/matchxpath.html#MatchXpath

Note : MatchXpath is Since Checkstyle 8.39

Epinasty answered 23/8, 2022 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.