В 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
END_OF_DOCUMENT_MARKER
Детали
Посмотрите, как функциональность 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 }