ArchUnit icon indicating copy to clipboard operation
ArchUnit copied to clipboard

More easily detect overridden methods & calls to super

Open java-coding-prodigy opened this issue 3 years ago • 7 comments

Fixes #982

Currently added a JavaMethod#isOverridden method for now.

java-coding-prodigy avatar Jan 06 '23 09:01 java-coding-prodigy

I couldn't figure out a direct way to get the inherited methods of the super class I tried to use .getMethods() but that only returns the public methods. If we have something like a class extending a class which also extends another class, and the lowest class has a method that the highest class has, but the middle class does not, then .isOverridden() returns false. I don't know whether our API or the reflection API has an easy way to fix this or not

java-coding-prodigy avatar Jan 07 '23 11:01 java-coding-prodigy

So far I think I know what we can do to fix the issue. We need to get the supperclasses and interfaces of the method's class but they cannot be the raw ones as they don't have type arguments. So looks like we can keep on calling a .supperclass() again and again unti we reach java.lang.Object as well as use .interfaces However this solves the current problem at hand, it may not be bug-free.

Also ignore JavaMethodTest.java that is just me playing around with the objects while debugging.

java-coding-prodigy avatar May 17 '23 14:05 java-coding-prodigy

@java-coding-prodigy are you still working on this? Do you need any support?

codecholeric avatar Oct 08 '23 15:10 codecholeric

@java-coding-prodigy are you still working on this? Do you need any support?

I was working on it some time ago and I could continue now. However I had run into some issues earlier. I'll see what I can do.

java-coding-prodigy avatar Oct 15 '23 08:10 java-coding-prodigy

Fixed the generic issue, however code is too ugly and slow, we should try to enhance it. I have only done this for classes, but I presume it would be similar for interfaces too.

java-coding-prodigy avatar Nov 11 '23 15:11 java-coding-prodigy

I'm thinking of adding a JavaMethod#overridenFrom(JavaType and make isOverriden call that method. What do you think @hankem ?

java-coding-prodigy avatar Nov 11 '23 15:11 java-coding-prodigy