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 classFoomight call a methodBar.target(). But ifBaris missing from the import (i.e. the bytecode ofBar.classhas not been scanned together withFoo.class), there will not be aJavaMethodrepresentingBar.target(). So even though we can derive anAccessTargetthat isBar.target()fromFoo'sbytecode (including method name and parameters), we cannot associate anyJavaMethodwith 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 interfacesAandBboth declare a methodtarget(), interfaceCextends both, and some third party callsC.target(). For further elaboration refer to the documentation ofresolve(). In particularresolve()attempts to find matchingJavaMembersfor the respectiveAccessTarget.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAccessTarget.CodeUnitCallTargetRepresents anAccessTargetwhere the target is a code unit.static classAccessTarget.ConstructorCallTargetstatic classAccessTarget.FieldAccessTargetRepresents anAccessTargetwhere the target is a field.static classAccessTarget.Functionsstatic classAccessTarget.MethodCallTargetRepresents anCodeUnitCallTargetwhere the target is a method.static classAccessTarget.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 booleanequals(java.lang.Object obj)java.lang.StringgetFullName()java.lang.StringgetName()JavaClassgetOwner()inthashCode()booleanisAnnotatedWith(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.booleanisAnnotatedWith(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.booleanisAnnotatedWith(java.lang.String annotationTypeName)booleanisMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)booleanisMetaAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)booleanisMetaAnnotatedWith(java.lang.String annotationTypeName)abstract java.util.Set<? extends JavaMember>resolve()Tries to resolve the targeted members (methods, fields or constructors).java.lang.StringtoString()
-
-
-
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:
getFullNamein 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:
hashCodein 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:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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:
isAnnotatedWithin 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:
isAnnotatedWithin 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:
isAnnotatedWithin 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:
isMetaAnnotatedWithin interfaceCanBeAnnotated
-
isMetaAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isMetaAnnotatedWith(java.lang.String annotationTypeName)
- Specified by:
isMetaAnnotatedWithin interfaceCanBeAnnotated
-
isMetaAnnotatedWith
@PublicAPI(usage=ACCESS) public boolean isMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)
- Specified by:
isMetaAnnotatedWithin interfaceCanBeAnnotated
-
-