Interface ClassResolver

All Known Implementing Classes:
ClassResolverFromClasspath, SelectedClassResolverFromClasspath

@PublicAPI(usage=INHERITANCE) public interface ClassResolver
The ClassFileImporter will use the configured ClassResolver, to determine how to resolve further dependencies.

For example, if you import the package com.foo.bar, and some class com.foo.bar.FooBar calls a method of com.other.Dependency, the ClassResolver will decide how this dependency should be treated, i.e. should the class tried to be located somehow, e.g. on the classpath, or should instead a stub with the respective type name be created.

Before any call of tryResolve(String), ArchUnit will always call setClassUriImporter(ClassUriImporter) and supply a respective ClassUriImporter. Thus the job of ClassResolver is just, to resolve the correct URI, where to locate the class. The ClassUriImporter can then import any given URI as a JavaClass.
  • Method Details

    • setClassUriImporter

      void setClassUriImporter(ClassResolver.ClassUriImporter classUriImporter)
      Always called BEFORE tryResolve(String).
      Parameters:
      classUriImporter - to import a JavaClass from any supplied URI
    • tryResolve

      Optional<JavaClass> tryResolve(String typeName)
      ArchUnit will call this method, to resolve any missing JavaClasses, needed to build the class graph (i.e. targets of method calls, field accesses, super classes, interfaces, ...)
      Parameters:
      typeName - The type name to resolve as JavaClass
      Returns:
      Optional.of(resolvedClass), if the JavaClass could be successfully imported, otherwise Optional.absent()