Package com.tngtech.archunit.core.domain
Class AccessTarget
- java.lang.Object
-
- com.tngtech.archunit.core.domain.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 aJavaAccess
. 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 methodFoo.origin()
of some imported classFoo
might call a methodBar.target()
. But ifBar
is missing from the import (i.e. the bytecode ofBar.class
has not been scanned together withFoo.class
), there will not be aJavaMethod
representingBar.target()
. So even though we can derive anAccessTarget
that isBar.target()
fromFoo's
bytecode (including method name and parameters), we cannot associate anyJavaMethod
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 singleJavaMethod
. I.e. some diamond scenarios, where two interfacesA
andB
both declare a methodtarget()
, interfaceC
extends both, and some third party callsC.target()
. For further elaboration refer to the documentation ofresolve()
. In particularresolve()
attempts to find matchingJavaMembers
for the respectiveAccessTarget
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AccessTarget.CodeUnitCallTarget
Represents anAccessTarget
where the target is a code unit.static class
AccessTarget.ConstructorCallTarget
static class
AccessTarget.FieldAccessTarget
Represents anAccessTarget
where the target is a field.static class
AccessTarget.Functions
static class
AccessTarget.MethodCallTarget
Represents aAccessTarget.CodeUnitCallTarget
where the target is a method.static class
AccessTarget.Predicates
-
Nested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.CanBeAnnotated
CanBeAnnotated.Utils
-
Nested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.HasName
HasName.AndFullName
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
getFullName()
java.lang.String
getName()
JavaClass
getOwner()
int
hashCode()
boolean
isAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate)
Returns true, if one of the resolved targets is annotated with an annotation matching the predicate.
NOTE: If the target was not imported, this method will always return false.boolean
isAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true, if one of the resolved targets is annotated with the given annotation type.
NOTE: If the target was not imported, this method will always return false.boolean
isAnnotatedWith(java.lang.String annotationTypeName)
boolean
isMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate)
boolean
isMetaAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
boolean
isMetaAnnotatedWith(java.lang.String annotationTypeName)
abstract java.util.Set<? extends JavaMember>
resolve()
Tries to resolve the targeted members (methods, fields or constructors).java.lang.String
toString()
-
-
-
Method Detail
-
getName
@PublicAPI(usage=ACCESS) public java.lang.String getName()
-
getOwner
@PublicAPI(usage=ACCESS) public JavaClass getOwner()
-
getFullName
@PublicAPI(usage=ACCESS) public java.lang.String getFullName()
- Specified by:
getFullName
in interfaceHasName.AndFullName
- Returns:
- The full name of this
AccessTarget
, i.e. a string containing${declaringClass}.${name}
for a field and${declaringClass}.${name}(${parameterTypes})
for a code unit
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
resolve
@PublicAPI(usage=ACCESS) public abstract java.util.Set<? extends JavaMember> resolve()
Tries to resolve the targeted members (methods, fields or constructors). In most cases this will be a single element, if the target was imported, or an empty set, if the target was not imported. However, forMethodCallTargets
, there can be multiple possible targets. For further information refer toAccessTarget
.- Returns:
- Set of all members that match the call target
- See Also:
AccessTarget.MethodCallTarget.resolve()
,AccessTarget.FieldAccessTarget.resolve()
,AccessTarget.ConstructorCallTarget.resolve()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns true, if one of the resolved targets is annotated with the given annotation type.
NOTE: If the target was not imported, this method will always return false.- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
- Parameters:
annotationType
- The type of the annotation to check for- Returns:
- true if one of the resolved targets is annotated with the given type
-
isAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isAnnotatedWith(java.lang.String annotationTypeName)
- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
- See Also:
isAnnotatedWith(Class)
-
isAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate)
Returns true, if one of the resolved targets is annotated with an annotation matching the predicate.
NOTE: If the target was not imported, this method will always return false.- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
- Parameters:
predicate
- Qualifies matching annotations- Returns:
- true if one of the resolved targets is annotated with an annotation matching the predicate
-
isMetaAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isMetaAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
isMetaAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isMetaAnnotatedWith(java.lang.String annotationTypeName)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
isMetaAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation<?>> predicate)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
-