UNPKG

arch-unit-ts

Version:
49 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MethodConditions = void 0; const ArchCondition_1 = require("../ArchCondition"); const SimpleConditionEvent_1 = require("../SimpleConditionEvent"); class MethodConditions { static beDecoratedWith(decorator) { return new MethodDecoratedWithCondition(decorator); } static beAsync() { return new AsyncMethodCondition(); } static beDeclaredInClassThat(classPredicate) { return new DeclaredInClassCondition(classPredicate); } } exports.MethodConditions = MethodConditions; class MethodDecoratedWithCondition extends ArchCondition_1.ArchCondition { decorator; constructor(decorator) { super(`be decorated with @${decorator}`); this.decorator = decorator; } check(method, events) { const satisfied = method.isDecoratedWith(this.decorator); events.add(new SimpleConditionEvent_1.SimpleConditionEvent(`${method.methodName} in ${method.declaringClass.getSimpleName()} ${satisfied ? 'is' : 'is not'} decorated with @${this.decorator} in ${method.declaringClass.getPath().get()}`, !satisfied)); } } class AsyncMethodCondition extends ArchCondition_1.ArchCondition { constructor() { super('be async'); } check(method, events) { const satisfied = method.isAsync(); events.add(new SimpleConditionEvent_1.SimpleConditionEvent(`${method.methodName} in ${method.declaringClass.getSimpleName()} ${satisfied ? 'is' : 'is not'} async in ${method.declaringClass.getPath().get()}`, !satisfied)); } } class DeclaredInClassCondition extends ArchCondition_1.ArchCondition { classPredicate; constructor(classPredicate) { super(`be declared in classes that ${classPredicate.description}`); this.classPredicate = classPredicate; } check(method, events) { const satisfied = this.classPredicate.test(method.declaringClass); events.add(new SimpleConditionEvent_1.SimpleConditionEvent(`${method.methodName} in ${method.declaringClass.getSimpleName()} ${satisfied ? 'is' : 'is not'} declared in class that ${this.classPredicate.description} in ${method.declaringClass.getPath().get()}`, !satisfied)); } } //# sourceMappingURL=MethodConditions.js.map