-
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
Collection the methods of all interfaces #1117
Comments
If the @Test
void properties_of_fully_imported_interface() {
interface Parent {
void parentMethod();
}
interface Child extends Parent {
void childMethod();
}
JavaClass childClass = new ClassFileImporter().importClasses(Child.class, Parent.class).get(Child.class);
assertThat(childClass.isFullyImported()).isTrue();
assertThat(childClass.isInterface()).isTrue();
assertThat(childClass.getMethods()).extracting(JavaMethod::getName).containsExactly("childMethod");
assertThat(childClass.getAllMethods()).extracting(JavaMethod::getName).containsExactly("childMethod", "parentMethod");
} I assume that you ended up with a @Test
void properties_of_not_fully_imported_classe() {
interface Dependency {
void method();
}
class DependencyHolder {
Dependency dependency;
}
ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);
JavaClass dependencyClass = new ClassFileImporter().importClass(DependencyHolder.class).getField("dependency").getRawType();
assertThat(dependencyClass.isFullyImported()).isFalse();
assertThat(dependencyClass.isInterface()).isFalse(); // We just don't know...
assertThat(dependencyClass.getMethods()).isEmpty(); // We just don't know...
assertThat(dependencyClass.getAllMethods()).isEmpty(); // We just don't know...
} |
Regarding your attempt to find unused methods, you can probably build on #131 (comment). |
I see 🤔 thanks for the clarification on how that works! As you expected it returns To resolve this, do I have to add the necessary dependencies to the ArchUnit-Project? Or is there some other workaround? Also thanks for the pointer to the project! |
I don't know what problem you ha(d/ve) exactly, but generally if you want to find inward dependencies (usages of your class/method), then you have to import all the other sources targeting your class/method as well or ArchUnit has no way to build up the graph and know about those. In the end, if you would e.g. take some library class from a popular library, then there would be tens of thousands of usages somewhere, but impossible to know from a local scope. Only if you import all those other classes as well ArchUnit can know about them. If it's outward dependencies, this can partially be done automatically by configuring the resolution behavior |
Thanks - I have never read that section. It was very insightful 👍
Something which might help people in the future, But this would be a different issue thus I am closing it because I resolved it with that remark. Thanks! |
I try to find all unused methods.
A big set to be ignored methods are those, which have to be implemented by an interface or an abstract method.
My attempt was to:
I saw a potential implementation for superclasses in #982;
but my test seems to fail while gathering all methods of interfaces.
Debugging this code I noticed that an
interface
is of typeJavaClass
and thus automatically the following statements are allfalse
:isAnnotation: false
,isAnonymousClass: false
,isEnum: false
,isMemberClass: false
,isRecord: false
,isInterface: false
.Running either
getMethods
orgetAllMethods
on aninterface
always returns an empty set.Am I misusing the provided APIs?
If yes, can somebody point me into the correct usage?
If no, is this a bug or intentional?
Thanks for reading!
The text was updated successfully, but these errors were encountered: