Package com.tngtech.archunit.core.domain
Class JavaCodeUnit
java.lang.Object
com.tngtech.archunit.core.domain.JavaMember
com.tngtech.archunit.core.domain.JavaCodeUnit
- All Implemented Interfaces:
HasDescription
,CanBeAnnotated
,HasAnnotations<JavaMember>
,HasDescriptor
,HasModifiers
,HasName
,HasName.AndFullName
,HasOwner<JavaClass>
,HasParameterTypes
,HasReturnType
,HasSourceCodeLocation
,HasThrowsClause<JavaCodeUnit>
,HasTypeParameters<JavaCodeUnit>
- Direct Known Subclasses:
JavaConstructor
,JavaMethod
,JavaStaticInitializer
@PublicAPI(usage=ACCESS)
public abstract class JavaCodeUnit
extends JavaMember
implements HasParameterTypes, HasReturnType, HasTypeParameters<JavaCodeUnit>, HasThrowsClause<JavaCodeUnit>
Represents a unit of code containing accesses to other units of code. A unit of code can be
- a method
- a constructor
- a static initializer
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Predefinedfunctions
to transformJavaCodeUnit
.static final class
Predefinedpredicates
targetingJavaCodeUnit
.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
-
Method Summary
Modifier and TypeMethodDescriptionSet<JavaAccess<?>>
JavaAnnotation<? extends JavaCodeUnit>
getAnnotationOfType
(String typeName) Set<? extends JavaAnnotation<? extends JavaCodeUnit>>
abstract ThrowsClause<? extends JavaCodeUnit>
List<? extends JavaTypeVariable<? extends JavaCodeUnit>>
boolean
boolean
isMethod()
Optional<? extends JavaAnnotation<? extends JavaCodeUnit>>
tryGetAnnotationOfType
(String typeName) Methods inherited from class com.tngtech.archunit.core.domain.JavaMember
getAccessesToSelf, getAnnotationOfType, getDescriptor, getModifiers, getName, getOwner, getReverseDependencies, getSourceCodeLocation, isAnnotatedWith, isAnnotatedWith, isAnnotatedWith, isMetaAnnotatedWith, isMetaAnnotatedWith, isMetaAnnotatedWith, reflect, toString, tryGetAnnotationOfType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.tngtech.archunit.base.HasDescription
getDescription
-
Method Details
-
getFullName
- Specified by:
getFullName
in interfaceHasName.AndFullName
- Returns:
- The full name of this
JavaCodeUnit
, i.e. a string containing${declaringClass}.${name}(${parameterTypes})
-
getRawParameterTypes
- Specified by:
getRawParameterTypes
in interfaceHasParameterTypes
- Returns:
- the raw parameter types of this
JavaCodeUnit
. On the contrary togetParameterTypes()
these will always beJavaClass
and thus not containing any parameterization/generic information. Note that the raw parameter types can contain synthetic parameters added by the compiler. E.g. for inner class constructors that receive the outer class as synthetic parameter or enum constructors that receive enum name and ordinal as synthetic parameters. There is no guarantee about the number of synthetic parameters, nor if they are appended or prepended, as e.g. local classes will append all local variables from the outer scope that are referenced as additional synthetic constructor parameters. - See Also:
-
getParameterTypes
- Specified by:
getParameterTypes
in interfaceHasParameterTypes
- Returns:
- the (possibly generic) parameter types of this
JavaCodeUnit
. This could for example be aJavaTypeVariable
or aJavaParameterizedType
, but also simply aJavaClass
.
Note that if the method has a generic signature (e.g. declaring a parameterized type) then on the contrary togetRawParameterTypes()
these types will be parsed from the signature encoded in the bytecode, i.e. they will not contain synthetic parameters added by the compiler. However, if there is no generic signature, then this information can also not be parsed from the signature. In this case the parameter types will be equal to the raw parameter types and by that can also contain synthetic parameters. - See Also:
-
getParameters
- Returns:
- the
parameters
of thisJavaCodeUnit
. On the contrary to the Reflection API this will only contain the parameters from the signature and not synthetic parameters, if the signature is generic. In these casesgetParameters()
.size()
will always be equal togetParameterTypes()
.size()
, but not necessarily togetRawParameterTypes()
.size()
in case the compiler adds synthetic parameters.
Note that for non-generic method signaturesgetParameters()
actually contains the raw parameter types and thus can also contain synthetic parameters. Unfortunately there is no way at the moment to distinguish synthetic parameters from non-synthetic parameters in these cases. - See Also:
-
getThrowsClause
- Specified by:
getThrowsClause
in interfaceHasThrowsClause<JavaCodeUnit>
-
getExceptionTypes
- Returns:
- The types thrown by this method, similar to
Method.getExceptionTypes()
-
getReturnType
- Specified by:
getReturnType
in interfaceHasReturnType
-
getRawReturnType
- Specified by:
getRawReturnType
in interfaceHasReturnType
-
getFieldAccesses
-
getCallsOfSelf
-
getMethodCallsFromSelf
-
getConstructorCallsFromSelf
-
getMethodReferencesFromSelf
-
getConstructorReferencesFromSelf
-
getReferencedClassObjects
-
getInstanceofChecks
-
getTryCatchBlocks
-
getCallsFromSelf
-
getCodeUnitReferencesFromSelf
-
getAccessesFromSelf
-
isConstructor
-
isMethod
-
getAnnotations
- Specified by:
getAnnotations
in interfaceHasAnnotations<JavaMember>
- Overrides:
getAnnotations
in classJavaMember
-
getAnnotationOfType
- Specified by:
getAnnotationOfType
in interfaceHasAnnotations<JavaMember>
- Overrides:
getAnnotationOfType
in classJavaMember
- Parameters:
typeName
- The fully qualified class name of theAnnotation
type to retrieve.- Returns:
- The
JavaAnnotation
matching the given type. Will throw anIllegalArgumentException
if no matchingAnnotation
is present. - See Also:
-
tryGetAnnotationOfType
public Optional<? extends JavaAnnotation<? extends JavaCodeUnit>> tryGetAnnotationOfType(String typeName) - Specified by:
tryGetAnnotationOfType
in interfaceHasAnnotations<JavaMember>
- Overrides:
tryGetAnnotationOfType
in classJavaMember
- Parameters:
typeName
- The fully qualified class name of theAnnotation
type to retrieve.- Returns:
- The
JavaAnnotation
matching the given type orOptional.empty()
if there is noAnnotation
with the respective annotation type. - See Also:
-
getTypeParameters
@PublicAPI(usage=ACCESS) public List<? extends JavaTypeVariable<? extends JavaCodeUnit>> getTypeParameters()- Specified by:
getTypeParameters
in interfaceHasTypeParameters<JavaCodeUnit>
- Returns:
- the type parameters of this object, e.g. for any generic method
this would return the<A, B> B someMethod(A a) {..}
JavaTypeVariables
[A, B]
.
If this object is non-generic, e.g. a method
an empty list will be returned.void someMethod() {..}
-
getParameterAnnotations
-