Search in sources :

Example 1 with PublicAPI

use of com.tngtech.archunit.PublicAPI in project ArchUnit by TNG.

the class ProxyRules method directly_call_other_methods_declared_in_the_same_class_that.

/**
 * Returns a condition that matches classes that directly calls other methods
 * declared in the same class that matches the given predicate.
 *
 * <p>
 * For an example, see {@link #directly_call_other_methods_declared_in_the_same_class_that_are_annotated_with(Class)}
 * </p>
 */
@PublicAPI(usage = ACCESS)
public static ArchCondition<JavaClass> directly_call_other_methods_declared_in_the_same_class_that(final DescribedPredicate<? super MethodCallTarget> predicate) {
    return new ArchCondition<JavaClass>("directly call other methods declared in the same class that " + predicate.getDescription()) {

        @Override
        public void check(JavaClass javaClass, ConditionEvents events) {
            for (JavaMethodCall call : javaClass.getMethodCallsFromSelf()) {
                boolean satisfied = call.getOriginOwner().equals(call.getTargetOwner()) && predicate.test(call.getTarget());
                events.add(new SimpleConditionEvent(call, satisfied, call.getDescription()));
            }
        }
    };
}
Also used : SimpleConditionEvent(com.tngtech.archunit.lang.SimpleConditionEvent) JavaClass(com.tngtech.archunit.core.domain.JavaClass) ArchCondition(com.tngtech.archunit.lang.ArchCondition) JavaMethodCall(com.tngtech.archunit.core.domain.JavaMethodCall) ConditionEvents(com.tngtech.archunit.lang.ConditionEvents) PublicAPI(com.tngtech.archunit.PublicAPI)

Aggregations

PublicAPI (com.tngtech.archunit.PublicAPI)1 JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)1 ArchCondition (com.tngtech.archunit.lang.ArchCondition)1 ConditionEvents (com.tngtech.archunit.lang.ConditionEvents)1 SimpleConditionEvent (com.tngtech.archunit.lang.SimpleConditionEvent)1