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
I am trying to create a custom arch unit rule to validate if method parameters have a final modifier. However, JavaParameter class does not seems to have a getModifiers method like JavaMethod class. Is this achievable with current ArchUnit API ?
I'm using ArchUnit 1.2.1 version.
This is a code sample of what I'm trying to achieve.
public void check(JavaMethod method, ConditionEvents events) {
boolean allParametersAreFinal = true;
for (JavaParameter parameter : method.getParameters()) {
if (!parameter.getModifiers().contains(JavaModifier.FINAL)) { // <---------- Something like this ?
allParametersAreFinal = false;
events.add(SimpleConditionEvent.violated(method,
String.format("Parameter %s of method %s is not final",
parameter.getOwner().getFullName(), method.getSourceCodeLocation())));
}
}
if (allParametersAreFinal) {
events.add(SimpleConditionEvent.satisfied(method,
"Parameters of method " + method.getFullName() + " are final"));
}
}
}
The text was updated successfully, but these errors were encountered:
I fear that final method parameters might just exist in the Java language, but and in the byte code/JVM.
(I'm saying "might" because I don't know much about the JVM specification...)
I've just observed that for the simple example
classC {
voidmethod(intp1, finalintp2) {
}
}
javap does not show any difference between the parameters p1 and p2 in the byte code:
I am trying to create a custom arch unit rule to validate if method parameters have a final modifier. However, JavaParameter class does not seems to have a getModifiers method like JavaMethod class. Is this achievable with current ArchUnit API ?
I'm using ArchUnit 1.2.1 version.
This is a code sample of what I'm trying to achieve.
The text was updated successfully, but these errors were encountered: