-
Notifications
You must be signed in to change notification settings - Fork 328
Closed
Description
I'm trying to detect if a class has methods that return a specific class (Foo), or a list of this specific class (List<Foo>).
I tested this condition:
private static final ArchCondition<JavaClass> NOT_HAVE_METHODS_RETURNING_FOO =
new ArchCondition<JavaClass>("methods should not return Foo") {
@Override
public void check(@NotNull JavaClass item, ConditionEvents events) {
item.getMethods()
.forEach(method -> {
JavaClass rawReturnType = method.getRawReturnType();
if (rawReturnType.getName().contains("my.package.Foo")) {
String message = String.format("Class %s's method %s returns an entity of type %s",
item.getSimpleName(),
method.getName(),
rawReturnType.getName());
events.add(SimpleConditionEvent.violated(method, message));
}
});
}
};
It works for methods that return Foo: rawReturnType.getName() looks like JavaClass{name='my.package.Foo'},
Problem -> for methods that return List<Foo>, rawReturnType.getName() is equal to JavaClass{name='java.util.List'}. I can't check it's a list of Foo.
Maybe I am missing something. At least, is it feasible?
Thx for your help!
Metadata
Metadata
Assignees
Labels
No labels