Package com.tngtech.archunit.core.domain
Class AccessTarget.FieldAccessTarget
java.lang.Object
com.tngtech.archunit.core.domain.AccessTarget
com.tngtech.archunit.core.domain.AccessTarget.FieldAccessTarget
- All Implemented Interfaces:
HasDescription
,CanBeAnnotated
,HasName
,HasName.AndFullName
,HasOwner<JavaClass>
,HasType
- Enclosing class:
- AccessTarget
@PublicAPI(usage=ACCESS)
public static final class AccessTarget.FieldAccessTarget
extends AccessTarget
implements HasType
Represents an
AccessTarget
where the target is a field. For further elaboration about the necessity to distinguish
FieldAccessTarget
from JavaField
, refer to the documentation at AccessTarget
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Predefinedfunctions
to transformAccessTarget.FieldAccessTarget
.Nested classes/interfaces inherited from class com.tngtech.archunit.core.domain.AccessTarget
AccessTarget.CodeUnitAccessTarget, AccessTarget.CodeUnitCallTarget, AccessTarget.CodeUnitReferenceTarget, AccessTarget.ConstructorCallTarget, AccessTarget.ConstructorReferenceTarget, AccessTarget.FieldAccessTarget, AccessTarget.MethodCallTarget, AccessTarget.MethodReferenceTarget, 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, HasName.Utils
Nested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.HasType
HasType.Predicates
-
Method Summary
Modifier and TypeMethodDescriptiongetType()
Attempts to resolve an imported field that has the same type and name as this target.
The result will be the only accessible field that the origin can reach.Methods inherited from class com.tngtech.archunit.core.domain.AccessTarget
equals, getFullName, getName, getOwner, hashCode, isAnnotatedWith, isAnnotatedWith, isAnnotatedWith, isMetaAnnotatedWith, isMetaAnnotatedWith, isMetaAnnotatedWith, toString
-
Method Details
-
getType
-
getRawType
- Specified by:
getRawType
in interfaceHasType
-
resolveMember
Attempts to resolve an imported field that has the same type and name as this target.
The result will be the only accessible field that the origin can reach. I.e. if there are multiple fields with the same type and name in the hierarchy of the target, then the one that is accessible will be picked. This must be unique, otherwise the compiler would force disambiguating by an explicit cast. Consider e.g.
Without the castinterface A { Class<?> value = A.class; } interface B { Class<?> value = B.class; } class C implements A, B { } class X { C c; // ... Class<?> origin() { return ((B) c).value; } }
((B) c)
this code would not compile because the field reference is ambiguous.
Note that the result can still beOptional.empty()
in case the class containing the field has not been imported.- Overrides:
resolveMember
in classAccessTarget
- Returns:
- The field that matches this target, or
Optional.empty()
if no matching field was imported. - See Also:
-
getDescription
- Specified by:
getDescription
in interfaceHasDescription
-