use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassesShouldEvaluator method on.
Set<JavaClass> on(Class<?>... toCheck) {
JavaClasses classes = importClasses(toCheck);
List<String> relevantFailures = getRelevantFailures(classes);
return classes.stream().filter(clazz -> anyLineMatches(relevantFailures, clazz)).collect(toSet());
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ImportTestUtils method simulateImport.
private static JavaClass simulateImport(Class<?> owner, ImportedTestClasses importedClasses) {
JavaClass javaClass = ImportTestUtils.javaClassFor(owner);
importedClasses.register(javaClass);
ImportContext context = simulateImportContext(owner, importedClasses);
DomainObjectCreationContext.completeMembers(javaClass, context);
return javaClass;
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class PublicAPIRules method bePublicAPIForInheritance.
private static ArchCondition<JavaClass> bePublicAPIForInheritance() {
return new ArchCondition<JavaClass>("be public API for inheritance") {
@Override
public void check(JavaClass item, ConditionEvents events) {
boolean satisfied = item.isAnnotatedWith(publicApiForInheritance()) || markedAsPublicAPIForInheritance().test(item);
events.add(new SimpleConditionEvent(item, satisfied, String.format("class %s is %smeant for inheritance", item.getName(), satisfied ? "" : "not ")));
}
};
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class PublicAPIRules method bePubliclyAccessible.
private static ArchCondition<JavaMember> bePubliclyAccessible() {
return new ArchCondition<JavaMember>("be publicly accessible") {
@Override
public void check(JavaMember member, ConditionEvents events) {
boolean declaringClassIsPublic = getAllEnclosingClasses(member).allMatch(c -> c.getModifiers().contains(PUBLIC));
boolean satisfied = member.getModifiers().contains(PUBLIC) && declaringClassIsPublic;
events.add(new SimpleConditionEvent(member, satisfied, String.format("member %s.%s is %sdeclared in public location in %s", member.getOwner().getName(), member.getName(), satisfied ? "" : "not ", member.getSourceCodeLocation())));
}
private Stream<JavaClass> getAllEnclosingClasses(JavaMember member) {
List<JavaClass> enclosingClasses = newArrayList(member.getOwner());
while (getLast(enclosingClasses).getEnclosingClass().isPresent()) {
enclosingClasses.add(getLast(enclosingClasses).getEnclosingClass().get());
}
return enclosingClasses.stream();
}
};
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class PublicAPIRules method beInterfaces.
private static ArchCondition<? super JavaClass> beInterfaces() {
return new ArchCondition<JavaClass>("be interfaces") {
@Override
public void check(JavaClass item, ConditionEvents events) {
boolean satisfied = item.isInterface();
events.add(new SimpleConditionEvent(item, satisfied, String.format("class %s is %sinterface", item.getName(), satisfied ? "" : "no ")));
}
};
}
Aggregations