@@ -127,9 +127,9 @@ private static void allBeanPostProcessorBeanMethodsShouldBeStaticAndNotCausePrem
127
127
.stream ()
128
128
.filter (notAnnotatedWithLazy )
129
129
.filter ((parameter ) -> notOfASafeType .test (parameter .getRawType ()))
130
- .forEach ((parameter ) -> events . add ( SimpleConditionEvent . violated ( parameter ,
130
+ .forEach ((parameter ) -> addViolation ( events , parameter ,
131
131
parameter .getDescription () + " will cause eager initialization as it is "
132
- + notAnnotatedWithLazy .getDescription () + " and is " + notOfASafeType .getDescription ()))) ;
132
+ + notAnnotatedWithLazy .getDescription () + " and is " + notOfASafeType .getDescription ()));
133
133
}
134
134
135
135
private static DescribedPredicate <JavaClass > notAnnotatedWithRoleInfrastructure () {
@@ -154,7 +154,7 @@ private static ArchCondition<JavaMethod> onlyInjectEnvironment() {
154
154
155
155
private static void onlyInjectEnvironment (JavaMethod item , ConditionEvents events ) {
156
156
if (item .getParameters ().stream ().anyMatch (ArchitectureRules ::isNotEnvironment )) {
157
- events . add ( SimpleConditionEvent . violated ( item , item .getDescription () + " should only inject Environment" ) );
157
+ addViolation ( events , item , item .getDescription () + " should only inject Environment" );
158
158
}
159
159
}
160
160
@@ -222,8 +222,8 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
222
222
if (!properties .containsKey ("type" ) && !properties .containsKey ("name" )) {
223
223
conditionalAnnotation .get ("value" ).ifPresent ((value ) -> {
224
224
if (containsOnlySingleType ((JavaType []) value , item .getReturnType ())) {
225
- events . add ( SimpleConditionEvent . violated ( item , conditionalAnnotation .getDescription ()
226
- + " should not specify only a value that is the same as the method's return type" )) ;
225
+ addViolation ( events , item , conditionalAnnotation .getDescription ()
226
+ + " should not specify only a value that is the same as the method's return type" );
227
227
}
228
228
});
229
229
}
@@ -251,8 +251,8 @@ private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(Jav
251
251
if (properties .size () == 1 && item .getParameterTypes ().size () == 1 ) {
252
252
enumSourceAnnotation .get ("value" ).ifPresent ((value ) -> {
253
253
if (value .equals (item .getParameterTypes ().get (0 ))) {
254
- events . add ( SimpleConditionEvent . violated ( item , enumSourceAnnotation .getDescription ()
255
- + " should not specify only a value that is the same as the method's parameter type" )) ;
254
+ addViolation ( events , item , enumSourceAnnotation .getDescription ()
255
+ + " should not specify only a value that is the same as the method's parameter type" );
256
256
}
257
257
});
258
258
}
@@ -285,8 +285,8 @@ private static void notSpecifyOnlyPrefixAttributeOfConfigurationProperties(HasAn
285
285
.getAnnotationOfType ("org.springframework.boot.context.properties.ConfigurationProperties" );
286
286
Map <String , Object > properties = configurationPropertiesAnnotation .getProperties ();
287
287
if (properties .size () == 1 && properties .containsKey ("prefix" )) {
288
- events . add ( SimpleConditionEvent . violated ( item , configurationPropertiesAnnotation .getDescription ()
289
- + " should specify implicit 'value' attribute other than explicit 'prefix' attribute" )) ;
288
+ addViolation ( events , item , configurationPropertiesAnnotation .getDescription ()
289
+ + " should specify implicit 'value' attribute other than explicit 'prefix' attribute" );
290
290
}
291
291
}
292
292
@@ -354,6 +354,10 @@ public void check(T item, ConditionEvents events) {
354
354
};
355
355
}
356
356
357
+ private static void addViolation (ConditionEvents events , Object correspondingObject , String message ) {
358
+ events .add (SimpleConditionEvent .violated (correspondingObject , message ));
359
+ }
360
+
357
361
private static String shouldUse (String string ) {
358
362
return string + " should be used instead" ;
359
363
}
0 commit comments