KSP requires explicit type resolution, so some functionalities in Java can only be carried out by KSType and the corresponding elements before resolution.
Java
Closest facility in KSP
Notes
ArrayType
KSBuiltIns.arrayType
DeclaredType
KSType/KSClassifierReference
ErrorType
KSType.isError
ExecutableType
KSType/KSCallableReference
IntersectionType
KSType/KSTypeParameter
NoType
KSType.isError
N/A in KSP
NullType
N/A in KSP
PrimitiveType
KSBuiltIns
Not exactly same as primitive type in Java
ReferenceType
KSTypeReference
TypeMirror
KSType
TypeVariable
KSTypeParameter
UnionType
N/A
Kotlin has only one type per catch block. UnionType is also not observable by even Java annotation processors
WildcardType
KSType/KSTypeArgument
Misc
Java
Closest facility in KSP
Notes
Name
KSName
ElementKind
ClassKind/FunctionKind
Modifier
Modifier
NestingKind
ClassKind/FunctionKind
AnnotationValueVisitor
ElementVisitor
KSVisitor
AnnotatedConstruct
KSAnnotated
TypeVisitor
TypeKind
KSBuiltIns
Some can be found in builtins, otherwise check KSClassDeclaration for DeclaredType
ElementFilter
Collection.filterIsInstance
ElementKindVisitor
KSVisitor
ElementScanner
KSTopDownVisitor
SimpleAnnotationValueVisitor
Not needed in KSP
SimpleElementVisitor
KSVisitor
SimpleTypeVisitor
TypeKindVisitor
Types
Resolver/utils
Some of the utils are also integrated into symbol interfaces
Elements
Resolver/utils
Details
See how functionalities of Java annotation processing API can be carried out by KSP.
AnnotationMirror
Java
KSP equivalent
getAnnotationType
ksAnnotation.annotationType
getElementValues
ksAnnotation.arguments
AnnotationValue
Java
KSP equivalent
getValue
ksValueArgument.value
Element
Java
KSP equivalent
asType
ksClassDeclaration.asType(...) is available for KSClassDeclaration only. Type arguments need to be supplied.
getAnnotation
To be implemented
getAnnotationMirrors
ksDeclaration.annotations
getEnclosedElements
ksDeclarationContainer.declarations
getEnclosingElements
ksDeclaration.parentDeclaration
getKind
Type check and cast following ClassKind or FunctionKind
getModifiers
ksDeclaration.modifiers
getSimpleName
ksDeclaration.simpleName
ExecutableElement
Java
KSP equivalent
getDefaultValue
To be implemented
getParameters
ksFunctionDeclaration.parameters
getReceiverType
ksFunctionDeclaration.parentDeclaration
getReturnType
ksFunctionDeclaration.returnType
getSimpleName
ksFunctionDeclaration.simpleName
getThrownTypes
Not needed in Kotlin
getTypeParameters
ksFunctionDeclaration.typeParameters
isDefault
Check whether parent declaration is an interface or not
// Should be able to do without resolution
ksClassDeclaration.superTypes
.map { it.resolve() }
.filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE }
getNestingKind
Check KSClassDeclaration.parentDeclaration and inner modifier
getQualifiedName
ksClassDeclaration.qualifiedName
getSimpleName
ksClassDeclaration.simpleName
getSuperclass
// Should be able to do without resolution
ksClassDeclaration.superTypes
.map { it.resolve() }
.filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.CLASS }