-
Notifications
You must be signed in to change notification settings - Fork 300
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
Failing to use Override annotaion as a Condition for ArchRule #359
Comments
Unfortunately I think no |
Okay, thanks. Actually I am developing for Checkstyle only, was trying to integrate ArchUnit into the codebase. |
Ah, okay 😄 Yeah, I think Checkstyle and ArchUnit just have a different approach and use case. Some things might overlap, but there also is a good part that's different and pure source assertions are one of those, they are out of scope for ArchUnit... |
I'll close this for now, since I don't think ArchUnit can do anything there with respect to |
Hi, What i tried methods()
.that().areDeclaredInClassesThat(areServiceImpl)
.and().arePublic()
.should().beDeclaredInClassesThat(serviceInterface)
.because("No service should add public methods"); but it seems that if a method is overwriten its signature changes from |
Yes, because the overridden method is actually declared in the implementation. No matter if there is a second declaration in an interface that has been overridden. I think what you want might be
I.e. we check out all the interfaces the class implements and see if we can find a method that matches the signature. (Note that there might be an edge-case here for covariantly overridden methods, where a bridge method has been added! So this is not sophisticated enough for all cases, but I hope you can build on that?) |
Thanks this is actually very helpful. Maybe depending on demand of such overwriting/overloading/inheritance rules it makes sense to integrate a few common checks into the core DSL. If this is considerable i would also be down to implement this and contribute |
Thanks for the offer 😃 Principally yes, I'm just not completely sure how exactly these methods should look like to be useful to a wide user base. In the end it's always a guess, if something is too specific and should just be handled on an individual basis with a custom predicate/condition, or if it should be part of the fluent API 🤔 |
The goal is to ensure all classes of a specific name pattern have non-protected methods, except for those which are annotated with
Override
.But this archrule
gives the following violation
com.tngtech.archunit.base.ArchUnitException$InvalidSyntaxUsageException: Annotation type java.lang.Override has @Retention(SOURCE), thus the information is gone after compile. So checking this with ArchUnit is useless.
Is there any way to fix this/some workarund for static analysis?
The text was updated successfully, but these errors were encountered: