В KSP пакеты не моделируются как элементы программы
Parameterizable
KSDeclaration
QualifiedNameable
KSDeclaration
TypeElement
KSClassDeclaration
TypeParameterElement
KSTypeParameter
VariableElement
KSValueParameter/KSPropertyDeclaration
Типы
KSP требует явного разрешения типов, поэтому некоторые функциональности в Java могут быть выполнены только с помощью KSType и соответствующих элементов до разрешения.
Java
Аналогичный элемент в KSP
Примечания
ArrayType
KSBuiltIns.arrayType
DeclaredType
KSType/KSClassifierReference
ErrorType
KSType.isError
ExecutableType
KSType/KSCallableReference
IntersectionType
KSType/KSTypeParameter
NoType
KSType.isError
Отсутствует в KSP
NullType
Отсутствует в KSP
PrimitiveType
KSBuiltIns
Не совсем совпадает с примитивным типом в Java
ReferenceType
KSTypeReference
TypeMirror
KSType
TypeVariable
KSTypeParameter
UnionType
Отсутствует
В Kotlin только один тип на блок catch. UnionType также не наблюдается даже обработчиками аннотаций Java
WildcardType
KSType/KSTypeArgument
Разное
Java
Аналогичный элемент в KSP
Примечания
Name
KSName
ElementKind
ClassKind/FunctionKind
Modifier
Modifier
NestingKind
ClassKind/FunctionKind
AnnotationValueVisitor
ElementVisitor
KSVisitor
AnnotatedConstruct
KSAnnotated
TypeVisitor
TypeKind
KSBuiltIns
Некоторые можно найти в встроенных функциях, в противном случае проверьте KSClassDeclaration для DeclaredType
ElementFilter
Collection.filterIsInstance
ElementKindVisitor
KSVisitor
ElementScanner
KSTopDownVisitor
SimpleAnnotationValueVisitor
Не требуется в KSP
SimpleElementVisitor
KSVisitor
SimpleTypeVisitor
TypeKindVisitor
Types
Resolver/utils
Некоторые из utils также интегрированы в интерфейсы символов
Elements
Resolver/utils
Детали
Посмотрите, как функциональность API обработки аннотаций Java может быть реализована с помощью KSP.
AnnotationMirror
Java
Эквивалент KSP
getAnnotationType
ksAnnotation.annotationType
getElementValues
ksAnnotation.arguments
AnnotationValue
Java
Эквивалент KSP
getValue
ksValueArgument.value
Элемент
Java
Эквивалент KSP
asType
ksClassDeclaration.asType(...) доступен только для KSClassDeclaration. Необходимо указать аргументы типа.
getAnnotation
Подлежит реализации
getAnnotationMirrors
ksDeclaration.annotations
getEnclosedElements
ksDeclarationContainer.declarations
getEnclosingElements
ksDeclaration.parentDeclaration
getKind
Проверка типа и приведение, следуя ClassKind или FunctionKind
getModifiers
ksDeclaration.modifiers
getSimpleName
ksDeclaration.simpleName
ExecutableElement
Java
Эквивалент KSP
getDefaultValue
Подлежит реализации
getParameters
ksFunctionDeclaration.parameters
getReceiverType
ksFunctionDeclaration.parentDeclaration
getReturnType
ksFunctionDeclaration.returnType
getSimpleName
ksFunctionDeclaration.simpleName
getThrownTypes
Не требуется в Kotlin
getTypeParameters
ksFunctionDeclaration.typeParameters
isDefault
Проверьте, является ли родительское объявление интерфейсом или нет
// Should be able to do without resolution
ksClassDeclaration.superTypes
.map { it.resolve() }
.filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE }
getNestingKind
Проверить модификатор KSClassDeclaration.parentDeclaration и inner
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 }