checkstyle / checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.
https://checkstyle.org
GNU Lesser General Public License v2.1
8.31k stars 3.66k forks source link

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: Design Checks detected in #14942 #15109

Closed mahfouz72 closed 2 months ago

mahfouz72 commented 3 months ago

child of #14942

HideUtilityClassConstructorCheck

doc : https://checkstyle.org/checks/design/hideutilityclassconstructor.html#HideUtilityClassConstructor

Makes sure that utility classes (classes that contain only static methods or fields in their API) do not have a public constructor.

unnamed variables can't be a static field. This is completely unrelated to unnamed variables.


InnerTypeLast

doc: https://checkstyle.org/checks/design/innertypelast.html

Checks nested (internal) classes/interfaces are declared at the bottom of the primary (top-level) class after all init and static init blocks, method, constructor and field declarations.

variable definition in this check appears in class member tokens and unnamed variables can't be class members


InterfaceIsTypeCheck

doc : https://checkstyle.org/checks/design/interfaceistype.html

an interface should describe a type. It is therefore inappropriate to define an interface that does not contain any methods but only constants

variable definition in this check is as an interface member token and unnamed variables can't be interface members.


MutableExceptionCheck

doc: https://checkstyle.org/checks/design/mutableexception.html

Ensures that exception classes (classes with names conforming to some pattern and explicitly extending classes with names conforming to other pattern) are immutable, that is, that they have only final fields.

variable definition in this check refers to the class fields that should be final and unnamed variables can't be class fields.


VisibilityModifierCheck

doc : https://checkstyle.org/checks/design/visibilitymodifier.html

Checks visibility of class members. Only static final, immutable or annotated by specified annotation members may be public

This check checks the visibility of class members and unnamed variables can't be class members.


PS D:\CS\test> cat src/Test.java                                                
public class Test {
    int _ = 0;
}
interface Test2 {
    int _ = 0;
}
PS D:\CS\test> javac src/Test.java                                              
src\Test.java:2: error: underscore not allowed here
    int _ = 0;
        ^
src\Test.java:5: error: underscore not allowed here
    int _ = 0;
        ^
2 errors
PS D:\CS\test> 
rnveach commented 3 months ago

Design Checks

I am not seeing all design checks. FinalClass and atleast one other isn't listed. If issue title is going to say "all X", then we either need all X or a description of which ones are dropped and why. I assume maybe the other designs are moved to their own issues? Pointing to those issues will be helpful.

Edit: It looks like these checks aren't picked up in the tracker's scan. I still think this is sort of misleading.

rnveach commented 3 months ago

I am good to approve despite above comment. This issue looks like we will close with no other changes.

nrmancuso commented 2 months ago

I have updated the issue title to be a bit more specific, we can close this one.