use of com.tngtech.archunit.lang.ConditionEvents in project sirius-components by eclipse-sirius.
the class AbstractImmutableTests method notHaveSetters.
private ArchCondition<JavaClass> notHaveSetters() {
return new // $NON-NLS-1$
ArchCondition<>(// $NON-NLS-1$
"not have setters") {
@Override
public void check(JavaClass javaClass, ConditionEvents events) {
// @formatter:off
long settersCount = javaClass.getMethods().stream().filter(// $NON-NLS-1$
javaMethod -> javaMethod.getName().startsWith("set")).count();
// @formatter:on
boolean isConditionSatisfied = settersCount == 0;
// $NON-NLS-1$
String message = "The class does not have any setters";
if (!isConditionSatisfied) {
// $NON-NLS-1$//$NON-NLS-2$
message = "The class " + javaClass.getName() + " does have setters";
}
events.add(new SimpleConditionEvent(javaClass, isConditionSatisfied, message));
}
};
}
use of com.tngtech.archunit.lang.ConditionEvents in project flink-mirror by flink-ci.
the class Conditions method haveLeafExceptionTypes.
/**
* Tests leaf exception types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafExceptionTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf exception types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
final List<JavaClass> leafArgumentTypes = method.getExceptionTypes().stream().flatMap(argumentType -> getLeafTypes(argumentType).stream()).collect(Collectors.toList());
for (JavaClass leafType : leafArgumentTypes) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Exception leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
use of com.tngtech.archunit.lang.ConditionEvents in project flink-mirror by flink-ci.
the class Conditions method haveLeafReturnTypes.
/**
* Tests leaf return types of a method against the given predicate.
*
* <p>See {@link #haveLeafTypes(DescribedPredicate)} for details.
*/
public static ArchCondition<JavaMethod> haveLeafReturnTypes(DescribedPredicate<JavaClass> typePredicate) {
return new ArchCondition<JavaMethod>("have leaf return types" + typePredicate.getDescription()) {
@Override
public void check(JavaMethod method, ConditionEvents events) {
for (JavaClass leafType : getLeafTypes(method.getReturnType())) {
if (!isJavaClass(leafType)) {
continue;
}
if (!typePredicate.apply(leafType)) {
final String message = String.format("%s: Returned leaf type %s does not satisfy: %s", method.getFullName(), leafType.getName(), typePredicate.getDescription());
events.add(SimpleConditionEvent.violated(method, message));
}
}
}
};
}
Aggregations