Skip to content
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

Add Check Support for Java 17 Sealed Classes: ClassFanOutComplexitiy #15078

Open
mahfouz72 opened this issue Jun 21, 2024 · 2 comments
Open

Add Check Support for Java 17 Sealed Classes: ClassFanOutComplexitiy #15078

mahfouz72 opened this issue Jun 21, 2024 · 2 comments

Comments

@mahfouz72
Copy link
Member

child of #14969

Check documentation: https://checkstyle.org/checks/metrics/classfanoutcomplexity.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="ClassFanOutComplexity">
            <property name="max" value="0"/>
        </module>
    </module>
</module>
PS D:\CS\test> cat src/Test.java                                                
public class Test implements I, J {  // violation
}

sealed class C permits D {   // should this be a violation ?
}
final class D extends C {   // violation
}
interface I {
}
interface J {
}
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:1:1: Class Fan-Out Complexity is 2 (max allowed is 0). [ClassFanOutComplexity]
[ERROR] D:\CS\test\src\Test.java:6:1: Class Fan-Out Complexity is 1 (max allowed is 0). [ClassFanOutComplexity]
Audit done.
Checkstyle ends with 2 errors.
PS D:\CS\test> 

from the doc:

Checks the number of other types a given class/record/interface/enum/annotation relies on. Also, the square of this has been shown to indicate the amount of maintenance required in functional programs (on a file basis) at least.

I don't think we should add 1 for the classes in the permits list. The super class C permitted certain classes to extend it but it doesn't rely on the permitted subclasses. the opposite is correct

@rnveach
Copy link
Member

rnveach commented Jun 23, 2024

The super class C permitted certain classes to extend it but it doesn't rely on the permitted subclasses.

I agree.

We definitely need an input for this, and I think documentation has to be added since we declared in documentation how we process things.

@nrmancuso
Copy link
Member

We definitely need an input for this, and I think documentation has to be added since we declared in documentation how we process things.

Agreed.

@nrmancuso nrmancuso assigned mahfouz72 and unassigned nrmancuso Jun 23, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jul 20, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jul 20, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jul 20, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jul 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants