-
Notifications
You must be signed in to change notification settings - Fork 282
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
Enum classes not recognized as enums and with with wrong access modifiers #1233
Comments
This looks like a bug in class GH1233 {
@Test
void test() {
JavaClass javaClass = new ClassFileImporter().importClass(GH1233.class);
Set<JavaClass> classesInPackage = javaClass.getPackage().getClasses();
assertThat(classesInPackage).extracting(JavaClass::getSimpleName).containsExactly("GH1233");
}
void foo(GH1233[] bar) {
}
} This test fails, because @kosciuszkopiotr: maybe you can rewrite your rule like this: classes()
.that(describe("reside in command package", javaClass -> javaClass.getPackage().getClasses().stream().anyMatch(simpleNameContaining("Command"))))
.and().areTopLevelClasses()
.and(not(have(modifier(ABSTRACT))))
.and(not(have(simpleNameEndingWith("Result").or(simpleNameEndingWith("Request")).or(simpleNameEndingWith("Command")))))
.should().notBePublic(); |
This works! Thanks a lot :) |
AFAIR this is by design, you can argue if it's the best design of course 🤔 Cause at some point we decided that for most purposes an array should be considered to have the same package as the corresponding component type (as opposed to the Reflection API) and on the other hand all types found during the import are sorted into their respective package. So if you cause an import of an array type, like |
Hello,
I'm using following code for rule:
As per description, the objective of the rule is to keep only selected public classes in packages with "command" in name. The issue is that this rule fails for package-private access enums and even shows those enums with wrong descriptors (Array):
If I make one of the enums public (I have two cases as per screenshot), then this enum will pop up twice in the condition check.
Could you please advise?
Best regards!
The text was updated successfully, but these errors were encountered: