@@ -120,9 +120,9 @@ private static void allBeanPostProcessorBeanMethodsShouldBeStaticAndNotCausePrem
120
120
.stream ()
121
121
.filter (notAnnotatedWithLazy )
122
122
.filter ((parameter ) -> notOfASafeType .test (parameter .getRawType ()))
123
- .forEach ((parameter ) -> events . add ( SimpleConditionEvent . violated ( parameter ,
123
+ .forEach ((parameter ) -> addViolation ( events , parameter ,
124
124
parameter .getDescription () + " will cause eager initialization as it is "
125
- + notAnnotatedWithLazy .getDescription () + " and is " + notOfASafeType .getDescription ()))) ;
125
+ + notAnnotatedWithLazy .getDescription () + " and is " + notOfASafeType .getDescription ()));
126
126
}
127
127
128
128
private static ArchRule allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveOnlyInjectEnvironment () {
@@ -140,7 +140,7 @@ private static ArchCondition<JavaMethod> onlyInjectEnvironment() {
140
140
141
141
private static void onlyInjectEnvironment (JavaMethod item , ConditionEvents events ) {
142
142
if (item .getParameters ().stream ().anyMatch (ArchitectureRules ::isNotEnvironment )) {
143
- events . add ( SimpleConditionEvent . violated ( item , item .getDescription () + " should only inject Environment" ) );
143
+ addViolation ( events , item , item .getDescription () + " should only inject Environment" );
144
144
}
145
145
}
146
146
@@ -208,8 +208,8 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
208
208
if (!properties .containsKey ("type" ) && !properties .containsKey ("name" )) {
209
209
conditionalAnnotation .get ("value" ).ifPresent ((value ) -> {
210
210
if (containsOnlySingleType ((JavaType []) value , item .getReturnType ())) {
211
- events . add ( SimpleConditionEvent . violated ( item , conditionalAnnotation .getDescription ()
212
- + " should not specify only a value that is the same as the method's return type" )) ;
211
+ addViolation ( events , item , conditionalAnnotation .getDescription ()
212
+ + " should not specify only a value that is the same as the method's return type" );
213
213
}
214
214
});
215
215
}
@@ -237,8 +237,8 @@ private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(Jav
237
237
if (properties .size () == 1 && item .getParameterTypes ().size () == 1 ) {
238
238
enumSourceAnnotation .get ("value" ).ifPresent ((value ) -> {
239
239
if (value .equals (item .getParameterTypes ().get (0 ))) {
240
- events . add ( SimpleConditionEvent . violated ( item , enumSourceAnnotation .getDescription ()
241
- + " should not specify only a value that is the same as the method's parameter type" )) ;
240
+ addViolation ( events , item , enumSourceAnnotation .getDescription ()
241
+ + " should not specify only a value that is the same as the method's parameter type" );
242
242
}
243
243
});
244
244
}
@@ -297,6 +297,10 @@ public void check(T item, ConditionEvents events) {
297
297
};
298
298
}
299
299
300
+ private static void addViolation (ConditionEvents events , Object correspondingObject , String message ) {
301
+ events .add (SimpleConditionEvent .violated (correspondingObject , message ));
302
+ }
303
+
300
304
private static String shouldUse (String string ) {
301
305
return string + " should be used instead" ;
302
306
}
0 commit comments