Package com.tngtech.archunit.core.domain
Class JavaClass
- java.lang.Object
-
- com.tngtech.archunit.core.domain.JavaClass
-
- All Implemented Interfaces:
CanBeAnnotated
,HasAnnotations
,HasModifiers
,HasName
public class JavaClass extends java.lang.Object implements HasName, HasAnnotations, HasModifiers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JavaClass.Functions
static class
JavaClass.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 Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Set<JavaAccess<?>>
getAccessesFromSelf()
java.util.Set<JavaAccess<?>>
getAccessesToSelf()
java.util.Set<JavaAccess<?>>
getAllAccessesFromSelf()
java.util.Set<JavaClass>
getAllClassesSelfIsAssignableTo()
java.util.Set<JavaConstructor>
getAllConstructors()
java.util.Set<JavaField>
getAllFields()
java.util.Set<JavaClass>
getAllInterfaces()
java.util.Set<JavaMember>
getAllMembers()
java.util.Set<JavaMethod>
getAllMethods()
java.util.Set<JavaClass>
getAllSubClasses()
java.util.List<JavaClass>
getAllSuperClasses()
<A extends java.lang.annotation.Annotation>
AgetAnnotationOfType(java.lang.Class<A> type)
JavaAnnotation
getAnnotationOfType(java.lang.String typeName)
java.util.Set<JavaAnnotation>
getAnnotations()
java.util.Set<JavaCall<?>>
getCallsFromSelf()
Returns all calls of this class to methods or constructors.java.util.List<JavaClass>
getClassHierarchy()
java.util.Set<JavaCodeUnit>
getCodeUnits()
JavaCodeUnit
getCodeUnitWithParameterTypeNames(java.lang.String name, java.lang.String... parameters)
Same asgetCodeUnitWithParameterTypes(String, Class[])
, but with parameter signature specified as full class namesJavaCodeUnit
getCodeUnitWithParameterTypeNames(java.lang.String name, java.util.List<java.lang.String> parameters)
JavaCodeUnit
getCodeUnitWithParameterTypes(java.lang.String name, java.lang.Class<?>... parameters)
JavaCodeUnit
getCodeUnitWithParameterTypes(java.lang.String name, java.util.List<java.lang.Class<?>> parameters)
JavaConstructor
getConstructor(java.lang.Class<?>... parameters)
java.util.Set<JavaConstructorCall>
getConstructorCallsFromSelf()
java.util.Set<JavaConstructorCall>
getConstructorCallsToSelf()
java.util.Set<JavaConstructor>
getConstructors()
java.util.Set<JavaConstructor>
getConstructorsWithParameterTypeOfSelf()
java.util.Set<Dependency>
getDirectDependencies()
Deprecated.UsegetDirectDependenciesFromSelf()
insteadjava.util.Set<Dependency>
getDirectDependenciesFromSelf()
Returns all dependencies originating directly from this class (i.e.java.util.Set<Dependency>
getDirectDependenciesToSelf()
LikegetDirectDependenciesFromSelf()
, but instead returns all dependencies where this class is target.Optional<JavaClass>
getEnclosingClass()
JavaField
getField(java.lang.String name)
java.util.Set<JavaFieldAccess>
getFieldAccessesFromSelf()
java.util.Set<JavaFieldAccess>
getFieldAccessesToSelf()
java.util.Set<JavaField>
getFields()
java.util.Set<JavaField>
getFieldsWithTypeOfSelf()
java.util.Set<JavaClass>
getInterfaces()
java.util.Set<JavaMember>
getMembers()
JavaMethod
getMethod(java.lang.String name, java.lang.Class<?>... parameters)
java.util.Set<JavaMethodCall>
getMethodCallsFromSelf()
java.util.Set<JavaMethodCall>
getMethodCallsToSelf()
java.util.Set<JavaMethod>
getMethods()
java.util.Set<JavaMethod>
getMethodsWithParameterTypeOfSelf()
java.util.Set<JavaMethod>
getMethodsWithReturnTypeOfSelf()
java.util.Set<JavaModifier>
getModifiers()
java.lang.String
getName()
java.lang.String
getPackage()
Deprecated.java.lang.String
getPackageName()
java.lang.String
getSimpleName()
Optional<Source>
getSource()
Optional<JavaStaticInitializer>
getStaticInitializer()
java.util.Set<JavaClass>
getSubClasses()
Optional<JavaClass>
getSuperClass()
boolean
isAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)
boolean
isAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
boolean
isAnnotatedWith(java.lang.String annotationTypeName)
boolean
isAnonymous()
boolean
isAssignableFrom(DescribedPredicate<? super JavaClass> predicate)
boolean
isAssignableFrom(java.lang.Class<?> type)
boolean
isAssignableFrom(java.lang.String typeName)
boolean
isAssignableTo(DescribedPredicate<? super JavaClass> predicate)
boolean
isAssignableTo(java.lang.Class<?> type)
boolean
isAssignableTo(java.lang.String typeName)
boolean
isEnum()
boolean
isEquivalentTo(java.lang.Class<?> clazz)
boolean
isInnerClass()
boolean
isInterface()
boolean
isMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)
boolean
isMetaAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> type)
boolean
isMetaAnnotatedWith(java.lang.String typeName)
boolean
isPrimitive()
static java.util.List<java.lang.String>
namesOf(java.lang.Class<?>... paramTypes)
static java.util.List<java.lang.String>
namesOf(java.util.List<java.lang.Class<?>> paramTypes)
java.lang.Class<?>
reflect()
Resolves the respectiveClass
from the classpath.
NOTE: This method will throw an exception, if the respectiveClass
or any of its dependencies can't be found on the classpath.java.lang.String
toString()
<A extends java.lang.annotation.Annotation>
Optional<A>tryGetAnnotationOfType(java.lang.Class<A> type)
Optional<JavaAnnotation>
tryGetAnnotationOfType(java.lang.String typeName)
Same astryGetAnnotationOfType(Class)
, but takes the type name.Optional<JavaField>
tryGetField(java.lang.String name)
Optional<JavaMethod>
tryGetMethod(java.lang.String name, java.lang.Class<?>... parameters)
-
-
-
Method Detail
-
getSource
@PublicAPI(usage=ACCESS) public Optional<Source> getSource()
-
getSimpleName
@PublicAPI(usage=ACCESS) public java.lang.String getSimpleName()
-
getPackage
@Deprecated @PublicAPI(usage=ACCESS) public java.lang.String getPackage()
Deprecated.Please usegetPackageName()
instead. This name was chosen poorly since a method 'getPackage' should have returned an object, not a mere String. This method will be refactored in a future release to return an object.
-
getPackageName
@PublicAPI(usage=ACCESS) public java.lang.String getPackageName()
-
isPrimitive
@PublicAPI(usage=ACCESS) public boolean isPrimitive()
-
isInterface
@PublicAPI(usage=ACCESS) public boolean isInterface()
-
isEnum
@PublicAPI(usage=ACCESS) public boolean isEnum()
-
isInnerClass
@PublicAPI(usage=ACCESS) public boolean isInnerClass()
-
getModifiers
public java.util.Set<JavaModifier> getModifiers()
- Specified by:
getModifiers
in interfaceHasModifiers
-
isAnnotatedWith
public boolean isAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
-
isAnnotatedWith
public boolean isAnnotatedWith(java.lang.String annotationTypeName)
- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
-
isAnnotatedWith
public boolean isAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)
- Specified by:
isAnnotatedWith
in interfaceCanBeAnnotated
-
isMetaAnnotatedWith
public boolean isMetaAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> type)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
isMetaAnnotatedWith
public boolean isMetaAnnotatedWith(java.lang.String typeName)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
isMetaAnnotatedWith
public boolean isMetaAnnotatedWith(DescribedPredicate<? super JavaAnnotation> predicate)
- Specified by:
isMetaAnnotatedWith
in interfaceCanBeAnnotated
-
getAnnotationOfType
public <A extends java.lang.annotation.Annotation> A getAnnotationOfType(java.lang.Class<A> type)
- Specified by:
getAnnotationOfType
in interfaceHasAnnotations
- Parameters:
type
- A given annotation type to matchJavaAnnotations
against- Returns:
- An
Annotation
of the given annotation type - Throws:
java.lang.IllegalArgumentException
- if the class is note annotated with the given type- See Also:
isAnnotatedWith(Class)
,tryGetAnnotationOfType(Class)
-
getAnnotationOfType
public JavaAnnotation getAnnotationOfType(java.lang.String typeName)
- Specified by:
getAnnotationOfType
in interfaceHasAnnotations
-
getAnnotations
public java.util.Set<JavaAnnotation> getAnnotations()
- Specified by:
getAnnotations
in interfaceHasAnnotations
-
tryGetAnnotationOfType
public <A extends java.lang.annotation.Annotation> Optional<A> tryGetAnnotationOfType(java.lang.Class<A> type)
- Specified by:
tryGetAnnotationOfType
in interfaceHasAnnotations
- Parameters:
type
- A given annotation type to matchJavaAnnotations
against- Returns:
- An
Optional
containing anAnnotation
of the given annotation type, if this class is annotated with the given type, otherwise Optional.absent() - See Also:
isAnnotatedWith(Class)
,getAnnotationOfType(Class)
-
tryGetAnnotationOfType
public Optional<JavaAnnotation> tryGetAnnotationOfType(java.lang.String typeName)
Same astryGetAnnotationOfType(Class)
, but takes the type name.- Specified by:
tryGetAnnotationOfType
in interfaceHasAnnotations
-
getSuperClass
@PublicAPI(usage=ACCESS) public Optional<JavaClass> getSuperClass()
-
getClassHierarchy
@PublicAPI(usage=ACCESS) public java.util.List<JavaClass> getClassHierarchy()
- Returns:
- The complete class hierarchy, i.e. the class itself and the result of
getAllSuperClasses()
-
getAllSuperClasses
@PublicAPI(usage=ACCESS) public java.util.List<JavaClass> getAllSuperClasses()
- Returns:
- All super classes sorted ascending by distance in the class hierarchy, i.e. first the direct super class, then the super class of the super class and so on. Includes Object.class in the result.
-
getSubClasses
@PublicAPI(usage=ACCESS) public java.util.Set<JavaClass> getSubClasses()
-
getInterfaces
@PublicAPI(usage=ACCESS) public java.util.Set<JavaClass> getInterfaces()
-
getAllInterfaces
@PublicAPI(usage=ACCESS) public java.util.Set<JavaClass> getAllInterfaces()
-
getAllClassesSelfIsAssignableTo
@PublicAPI(usage=ACCESS) public java.util.Set<JavaClass> getAllClassesSelfIsAssignableTo()
- Returns:
- All classes, this class is assignable to, in particular
- self
- superclasses this class extends
- interfaces this class implements
-
getEnclosingClass
@PublicAPI(usage=ACCESS) public Optional<JavaClass> getEnclosingClass()
-
getAllSubClasses
@PublicAPI(usage=ACCESS) public java.util.Set<JavaClass> getAllSubClasses()
-
getMembers
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMember> getMembers()
-
getAllMembers
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMember> getAllMembers()
-
getFields
@PublicAPI(usage=ACCESS) public java.util.Set<JavaField> getFields()
-
getAllFields
@PublicAPI(usage=ACCESS) public java.util.Set<JavaField> getAllFields()
-
getField
@PublicAPI(usage=ACCESS) public JavaField getField(java.lang.String name)
-
tryGetField
@PublicAPI(usage=ACCESS) public Optional<JavaField> tryGetField(java.lang.String name)
-
getCodeUnits
@PublicAPI(usage=ACCESS) public java.util.Set<JavaCodeUnit> getCodeUnits()
-
getCodeUnitWithParameterTypes
@PublicAPI(usage=ACCESS) public JavaCodeUnit getCodeUnitWithParameterTypes(java.lang.String name, java.lang.Class<?>... parameters)
- Parameters:
name
- The name of the code unit, can be a method name, but alsoCONSTRUCTOR_NAME
orSTATIC_INITIALIZER_NAME
parameters
- The parameter signature of the method specified asClass
Objects- Returns:
- A code unit (method, constructor or static initializer) with the given signature
-
getCodeUnitWithParameterTypeNames
@PublicAPI(usage=ACCESS) public JavaCodeUnit getCodeUnitWithParameterTypeNames(java.lang.String name, java.lang.String... parameters)
Same asgetCodeUnitWithParameterTypes(String, Class[])
, but with parameter signature specified as full class names
-
getCodeUnitWithParameterTypes
@PublicAPI(usage=ACCESS) public JavaCodeUnit getCodeUnitWithParameterTypes(java.lang.String name, java.util.List<java.lang.Class<?>> parameters)
-
getCodeUnitWithParameterTypeNames
@PublicAPI(usage=ACCESS) public JavaCodeUnit getCodeUnitWithParameterTypeNames(java.lang.String name, java.util.List<java.lang.String> parameters)
-
getMethod
@PublicAPI(usage=ACCESS) public JavaMethod getMethod(java.lang.String name, java.lang.Class<?>... parameters)
-
tryGetMethod
@PublicAPI(usage=ACCESS) public Optional<JavaMethod> tryGetMethod(java.lang.String name, java.lang.Class<?>... parameters)
-
getMethods
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethod> getMethods()
-
getAllMethods
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethod> getAllMethods()
-
getConstructor
@PublicAPI(usage=ACCESS) public JavaConstructor getConstructor(java.lang.Class<?>... parameters)
-
getConstructors
@PublicAPI(usage=ACCESS) public java.util.Set<JavaConstructor> getConstructors()
-
getAllConstructors
@PublicAPI(usage=ACCESS) public java.util.Set<JavaConstructor> getAllConstructors()
-
getStaticInitializer
@PublicAPI(usage=ACCESS) public Optional<JavaStaticInitializer> getStaticInitializer()
-
getAccessesFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaAccess<?>> getAccessesFromSelf()
-
getAllAccessesFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaAccess<?>> getAllAccessesFromSelf()
- Returns:
- Set of all
JavaAccess
in the class hierarchy, as opposed to the accesses this class directly performs.
-
getFieldAccessesFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaFieldAccess> getFieldAccessesFromSelf()
-
getCallsFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaCall<?>> getCallsFromSelf()
Returns all calls of this class to methods or constructors.
-
getMethodCallsFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethodCall> getMethodCallsFromSelf()
-
getConstructorCallsFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaConstructorCall> getConstructorCallsFromSelf()
-
getDirectDependencies
@Deprecated @PublicAPI(usage=ACCESS) public java.util.Set<Dependency> getDirectDependencies()
Deprecated.UsegetDirectDependenciesFromSelf()
instead
-
getDirectDependenciesFromSelf
@PublicAPI(usage=ACCESS) public java.util.Set<Dependency> getDirectDependenciesFromSelf()
Returns all dependencies originating directly from this class (i.e. not just from a superclass), where a dependency can be- field access
- method call
- constructor call
- extending a class
- implementing an interface
- Returns:
- All dependencies originating directly from this class (i.e. where this class is the origin)
-
getDirectDependenciesToSelf
@PublicAPI(usage=ACCESS) public java.util.Set<Dependency> getDirectDependenciesToSelf()
LikegetDirectDependenciesFromSelf()
, but instead returns all dependencies where this class is target.- Returns:
- Dependencies where this class is the target.
-
getFieldAccessesToSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaFieldAccess> getFieldAccessesToSelf()
-
getMethodCallsToSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethodCall> getMethodCallsToSelf()
-
getConstructorCallsToSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaConstructorCall> getConstructorCallsToSelf()
-
getAccessesToSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaAccess<?>> getAccessesToSelf()
-
getFieldsWithTypeOfSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaField> getFieldsWithTypeOfSelf()
- Returns:
- Fields of all imported classes that have the type of this class.
-
getMethodsWithParameterTypeOfSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethod> getMethodsWithParameterTypeOfSelf()
- Returns:
- Methods of all imported classes that have a parameter type of this class.
-
getMethodsWithReturnTypeOfSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaMethod> getMethodsWithReturnTypeOfSelf()
- Returns:
- Methods of all imported classes that have a return type of this class.
-
getConstructorsWithParameterTypeOfSelf
@PublicAPI(usage=ACCESS) public java.util.Set<JavaConstructor> getConstructorsWithParameterTypeOfSelf()
- Returns:
- Constructors of all imported classes that have a parameter type of this class.
-
isEquivalentTo
@PublicAPI(usage=ACCESS) public boolean isEquivalentTo(java.lang.Class<?> clazz)
- Parameters:
clazz
- An arbitrary type- Returns:
- true, if this
JavaClass
represents the same class as the suppliedClass
, otherwise false
-
isAssignableFrom
@PublicAPI(usage=ACCESS) public boolean isAssignableFrom(java.lang.Class<?> type)
-
isAssignableFrom
@PublicAPI(usage=ACCESS) public boolean isAssignableFrom(java.lang.String typeName)
-
isAssignableFrom
@PublicAPI(usage=ACCESS) public boolean isAssignableFrom(DescribedPredicate<? super JavaClass> predicate)
-
isAssignableTo
@PublicAPI(usage=ACCESS) public boolean isAssignableTo(java.lang.Class<?> type)
-
isAssignableTo
@PublicAPI(usage=ACCESS) public boolean isAssignableTo(java.lang.String typeName)
-
isAssignableTo
@PublicAPI(usage=ACCESS) public boolean isAssignableTo(DescribedPredicate<? super JavaClass> predicate)
-
reflect
@PublicAPI(usage=ACCESS) public java.lang.Class<?> reflect()
Resolves the respectiveClass
from the classpath.
NOTE: This method will throw an exception, if the respectiveClass
or any of its dependencies can't be found on the classpath.- Returns:
- The
Class
equivalent to thisJavaClass
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
namesOf
@PublicAPI(usage=ACCESS) public static java.util.List<java.lang.String> namesOf(java.lang.Class<?>... paramTypes)
-
namesOf
@PublicAPI(usage=ACCESS) public static java.util.List<java.lang.String> namesOf(java.util.List<java.lang.Class<?>> paramTypes)
-
isAnonymous
@PublicAPI(usage=ACCESS) public boolean isAnonymous()
-
-