Skip to content

Add Check Support for Java 21 Unnamed Variables & Patterns Syntax: MultipleVariableDeclarations #15070

@mahfouz72

Description

@mahfouz72

child of #14942

check doc: https://checkstyle.org/checks/coding/multiplevariabledeclarations.html


PS D:\CS\test> cat config.xml                                                   
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
    <property name="charset" value="UTF-8"/>
    <module name="TreeWalker">
        <module name="MultipleVariableDeclarationsCheck">
        </module>
    </module>
</module>
PS D:\CS\test> cat src/Test.java                                                
import java.util.LinkedHashMap;
import java.util.List;

record ColoredPoint(String p, String x, int c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }

public class Test {
    void test(Object obj) {
       int x = 0, _ = sideEffect();

    }
    int sideEffect() {
        return 0;
    }
}

PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
[ERROR] D:\CS\test\src\Test.java:9:8: Each variable declaration must be in its own statement. [MultipleVariableDeclarations]
Audit done.
Checkstyle ends with 1 errors.
PS D:\CS\test> 


The check works as intended.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions