You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Top level types should be defined in a file with a matching name. For public types this is enforced by the compiler, but for package-private types it's possible to have a mismatch. That can be confusing for developers who expect to be able to locate a source file based on class name.
Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.
// content of Foo.javaclassBar { // violation, should be defined in Bar.java
}
// content of Baz.javaclassBaz {
classFoo { } // OK, nested classes are allowed
}
classBar { // violation, second top-level class should be in its own file
}
What do you think about checking the directory structure as well? For example, making sure that a class in the foo.bar.baz package is located in a directory called .../foo/bar/baz?
Activity
UncleOwen commentedon Sep 5, 2026
What do you think about checking the directory structure as well? For example, making sure that a class in the
foo.bar.bazpackage is located in a directory called.../foo/bar/baz?