You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #171 dependencies have been enhanced to check for annotations (see also #136).
What has not been fixed in this PR is the support for annotations for parameters.
When I define the following rule:
public static final ArchRule NO_FORBIDDEN_ANNOTATIONS_USED =
noClasses().should().dependOnClassesThat(
have(type(edu.umd.cs.findbugs.annotations.CheckForNull.class)));
Then the following code will produce only a violation for the member, but not for the parameter.
@CheckForNull
public boolean exists(@CheckForNull final String fileName) {...}
It would be quite helpful if ArchUnit would also consider parameter annotations as a dependency (the types of parameters are correctly considered a dependency).
The text was updated successfully, but these errors were encountered:
Yes, this is still a shortcoming 😞 It was not forgotten, but it is blocked by #113, i.e. we do not have the info yet, because parameter annotations are not yet imported.
But I agree that once #113 is solved parameter annotations should also be added to the dependencies.
This will extend the domain model of ArchUnit by providing
* `List<Parameter> JavaCodeUnit.getParameters()`
* `List<List<JavaAnnotation<Parameter>> JavaCodeUnit.getParameterAnnotations()`
where `Parameter` also offers `getParameterType()`, `getRawParameterType()` and `getAnnotations()`.
Furthermore parameter annotations are now part of `JavaClass.directDependencies{From/To}Self`.
On the contrary to the Java Reflection API the `JavaCodeUnit.getParameters()` will exactly mirror the (possibly generic) signature and not the raw types. This means that for generic signatures synthetic raw type parameter types (like `name` and `ordinal` for an enum constructor) will not be visible in the `List<Parameter>`. I think for ArchUnit this makes sense, as there is limited interest in synthetic parts of the code and users are only interested in the parameters that have really been introduced by source code. Unfortunately there are many cases where the bytecode does not contain the signature attribute (whenever the signature is non-generic, i.e. does not contain any parameterized types, type variables, etc.). In these cases the parameters will still mirror the raw types (including possible synthetic parameters), because there is no other source of information where the parameters could be derived from. It is also not i.g. possible to derive which parameters are synthetic and which are not, so ArchUnit does not attempt this at all at the moment.
Resolves: #404Resolves: #373Resolves: #113
In #171 dependencies have been enhanced to check for annotations (see also #136).
What has not been fixed in this PR is the support for annotations for parameters.
When I define the following rule:
Then the following code will produce only a violation for the member, but not for the parameter.
It would be quite helpful if ArchUnit would also consider parameter annotations as a dependency (the types of parameters are correctly considered a dependency).
The text was updated successfully, but these errors were encountered: