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
Nested ClassesModifier and TypeClassDescriptionstatic final classPredefinedfunctionsto 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.PredicatesNested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.CanBeAnnotated
CanBeAnnotated.UtilsNested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.HasName
HasName.AndFullName, HasName.UtilsNested 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:
getRawTypein interfaceHasType- Returns:
- The raw type of this object. This is effectively the same as calling
HasType.getType().toErasure(). E.g. given aJavaParameterizedTypejava.util.List<String>the raw type (i.e. type erasure) would be theJavaClassjava.util.List. - See Also:
-
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:
resolveMemberin classAccessTarget- Returns:
- The field that matches this target, or
Optional.empty()if no matching field was imported. - See Also:
-
getDescription
- Specified by:
getDescriptionin interfaceHasDescription
-