Class AccessTarget

  • All Implemented Interfaces:
    CanBeAnnotated, HasName, HasName.AndFullName, HasOwner<JavaClass>
    Direct Known Subclasses:
    AccessTarget.CodeUnitCallTarget, AccessTarget.FieldAccessTarget

    public abstract class AccessTarget
    extends java.lang.Object
    implements HasName.AndFullName, CanBeAnnotated, HasOwner<JavaClass>
    Represents the target of a JavaAccess. ArchUnit distinguishes between an 'access target' and a concrete field/method/constructor, because the bytecode does not allow a 1-to-1 association here.

    For one part, the target might be missing from the import, e.g. some method Foo.origin() of some imported class Foo might call a method Bar.target(). But if Bar is missing from the import (i.e. the bytecode of Bar.class has not been scanned together with Foo.class), there will not be a JavaMethod representing Bar.target(). So even though we can derive an AccessTarget that is Bar.target() from Foo's bytecode (including method name and parameters), we cannot associate any JavaMethod with that target.

    For the other part, even if all the participating classes are imported, there are still situations, where the respective access target cannot be associated with one single JavaMethod. I.e. some diamond scenarios, where two interfaces A and B both declare a method target(), interface C extends both, and some third party calls C.target(). For further elaboration refer to the documentation of resolve(). In particular resolve() attempts to find matching JavaMembers for the respective AccessTarget.