Skip to content

Java 어노테이션 프로세싱에서 KSP 참조로

프로그램 요소

JavaKSP의 상응하는 기능참고
AnnotationMirrorKSAnnotation
AnnotationValueKSValueArguments
ElementKSDeclaration / KSDeclarationContainer
ExecutableElementKSFunctionDeclaration
PackageElementKSFileKSP는 패키지를 프로그램 요소로 모델링하지 않습니다.
ParameterizableKSDeclaration
QualifiedNameableKSDeclaration
TypeElementKSClassDeclaration
TypeParameterElementKSTypeParameter
VariableElementKSValueParameter / KSPropertyDeclaration

타입

KSP는 명시적인 타입 해석(type resolution)을 요구하므로, Java의 일부 기능은 KSType 및 해석 전의 상응하는 요소들에 의해서만 수행될 수 있습니다.

JavaKSP의 상응하는 기능참고
ArrayTypeKSBuiltIns.arrayType
DeclaredTypeKSType / KSClassifierReference
ErrorTypeKSType.isError
ExecutableTypeKSType / KSCallableReference
IntersectionTypeKSType / KSTypeParameter
NoTypeKSType.isErrorKSP에서는 해당 없음
NullTypeKSP에서는 해당 없음
PrimitiveTypeKSBuiltInsJava의 primitive 타입과 정확히 같지는 않습니다.
ReferenceTypeKSTypeReference
TypeMirrorKSType
TypeVariableKSTypeParameter
UnionTypeN/AKotlin은 catch 블록당 하나의 타입만 가집니다. UnionType은 Java 어노테이션 프로세서로도 관찰할 수 없습니다.
WildcardTypeKSType / KSTypeArgument

기타

JavaKSP의 상응하는 기능참고
NameKSName
ElementKindClassKind / FunctionKind
ModifierModifier
NestingKindClassKind / FunctionKind
AnnotationValueVisitor
ElementVisitorKSVisitor
AnnotatedConstructKSAnnotated
TypeVisitor
TypeKindKSBuiltIns일부는 빌트인(built-in)에서 찾을 수 있으며, 그렇지 않으면 DeclaredType에 대해 KSClassDeclaration을 확인하십시오.
ElementFilterCollection.filterIsInstance
ElementKindVisitorKSVisitor
ElementScannerKSTopDownVisitor
SimpleAnnotationValueVisitorKSP에서는 필요하지 않습니다.
SimpleElementVisitorKSVisitor
SimpleTypeVisitor
TypeKindVisitor
TypesResolver / utils일부 유틸리티(utils)는 심볼 인터페이스에 통합되어 있습니다.
ElementsResolver / utils

상세 내용

Java 어노테이션 프로세싱 API의 기능들이 KSP에 의해 어떻게 수행될 수 있는지 확인하십시오.

AnnotationMirror

JavaKSP 상응 항목
getAnnotationTypeksAnnotation.annotationType
getElementValuesksAnnotation.arguments

AnnotationValue

JavaKSP 상응 항목
getValueksValueArgument.value

Element

JavaKSP 상응 항목
asTypeksClassDeclaration.asType(...)KSClassDeclaration에만 사용 가능합니다. 타입 인자(type arguments)를 제공해야 합니다.
getAnnotation구현 예정
getAnnotationMirrorsksDeclaration.annotations
getEnclosedElementsksDeclarationContainer.declarations
getEnclosingElementsksDeclaration.parentDeclaration
getKindClassKind 또는 FunctionKind에 따라 타입 검사 및 캐스팅(casting)을 수행합니다.
getModifiersksDeclaration.modifiers
getSimpleNameksDeclaration.simpleName

ExecutableElement

JavaKSP 상응 항목
getDefaultValue구현 예정
getParametersksFunctionDeclaration.parameters
getReceiverTypeksFunctionDeclaration.parentDeclaration
getReturnTypeksFunctionDeclaration.returnType
getSimpleNameksFunctionDeclaration.simpleName
getThrownTypesKotlin에서는 필요하지 않습니다.
getTypeParametersksFunctionDeclaration.typeParameters
isDefault부모 선언(parent declaration)이 인터페이스인지 확인합니다.
isVarArgsksFunctionDeclaration.parameters.any { it.isVarArg }

Parameterizable

JavaKSP 상응 항목
getTypeParametersksFunctionDeclaration.typeParameters

QualifiedNameable

JavaKSP 상응 항목
getQualifiedNameksDeclaration.qualifiedName

TypeElement

JavaKSP 상응 항목
getEnclosedElementsksClassDeclaration.declarations
getEnclosingElementksClassDeclaration.parentDeclaration
getInterfaces
kotlin
// 해석(resolution) 없이도 수행할 수 있어야 합니다.
ksClassDeclaration.superTypes
    .map { it.resolve() }
    .filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE }
getNestingKindKSClassDeclaration.parentDeclarationinner 변경자(modifier)를 확인합니다.
getQualifiedNameksClassDeclaration.qualifiedName
getSimpleNameksClassDeclaration.simpleName
getSuperclass
kotlin
// 해석(resolution) 없이도 수행할 수 있어야 합니다.
ksClassDeclaration.superTypes
    .map { it.resolve() }
    .filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.CLASS }
getTypeParametersksClassDeclaration.typeParameters

TypeParameterElement

JavaKSP 상응 항목
getBoundsksTypeParameter.bounds
getEnclosingElementksTypeParameter.parentDeclaration
getGenericElementksTypeParameter.parentDeclaration

VariableElement

JavaKSP 상응 항목
getConstantValue구현 예정
getEnclosingElementksValueParameter.parentDeclaration
getSimpleNameksValueParameter.simpleName

ArrayType

JavaKSP 상응 항목
getComponentTypeksType.arguments.first()

DeclaredType

JavaKSP 상응 항목
asElementksType.declaration
getEnclosingTypeksType.declaration.parentDeclaration
getTypeArgumentsksType.arguments

ExecutableType

함수에 대한 KSTypeFunctionN<R, T1, T2, ..., TN> 계열로 표현되는 시그니처(signature)일 뿐입니다.

JavaKSP 상응 항목
getParameterTypesksType.declaration.typeParameters, ksFunctionDeclaration.parameters.map { it.type }
getReceiverTypeksFunctionDeclaration.parentDeclaration.asType(...)
getReturnTypeksType.declaration.typeParameters.last()
getThrownTypesKotlin에서는 필요하지 않습니다.
getTypeVariablesksFunctionDeclaration.typeParameters

IntersectionType

JavaKSP 상응 항목
getBoundsksTypeParameter.bounds

TypeMirror

JavaKSP 상응 항목
getKindprimitive 타입 및 Unit 타입에 대해서는 KSBuiltIns의 타입과 비교하고, 그렇지 않으면 선언된 타입(declared types)을 확인합니다.

TypeVariable

JavaKSP 상응 항목
asElementksType.declaration
getLowerBound미정. 캡처(capture)가 제공되고 명시적인 바운드(bound) 검사가 필요한 경우에만 필요합니다.
getUpperBoundksTypeParameter.bounds

WildcardType

JavaKSP 상응 항목
getExtendsBound
kotlin
if (ksTypeArgument.variance == Variance.COVARIANT) ksTypeArgument.type else null
getSuperBound
kotlin
if (ksTypeArgument.variance == Variance.CONTRAVARIANT) ksTypeArgument.type else null

Elements

JavaKSP 상응 항목
getAllAnnotationMirrorsKSDeclarations.annotations
getAllMembersgetAllFunctions, getAllProperties는 구현 예정입니다.
getBinaryName미정, Java Specification을 참조하십시오.
getConstantExpression상수 값(constant value)은 있지만 표현식(expression)은 없습니다.
getDocComment구현 예정
getElementValuesWithDefaults구현 예정
getNameresolver.getKSNameFromString
getPackageElement패키지는 지원되지 않지만, 패키지 정보를 검색할 수는 있습니다. KSP에서는 패키지에 대한 작업이 불가능합니다.
getPackageOf패키지는 지원되지 않습니다.
getTypeElementResolver.getClassDeclarationByName
hides구현 예정
isDeprecated
kotlin
KsDeclaration.annotations.any { 
    it.annotationType.resolve()!!.declaration.qualifiedName!!.asString() == Deprecated::class.qualifiedName
}
overridesKSFunctionDeclaration.overrides / KSPropertyDeclaration.overrides (해당 클래스의 멤버 함수)
printElementsKSP는 대부분의 클래스에 기본 toString() 구현을 가지고 있습니다.

Types

JavaKSP 상응 항목
asElementksType.declaration
asMemberOfresolver.asMemberOf
boxedClass필요하지 않습니다.
capture미정
containsKSType.isAssignableFrom
directSuperTypes(ksType.declaration as KSClassDeclaration).superTypes
erasureksType.starProjection()
getArrayTypeksBuiltIns.arrayType.replace(...)
getDeclaredTypeksClassDeclaration.asType
getNoTypeksBuiltIns.nothingType / null
getNullType컨텍스트(context)에 따라 KSType.markNullable이 유용할 수 있습니다.
getPrimitiveType필요하지 않습니다. KSBuiltins를 확인하십시오.
getWildcardTypeKSTypeArgument를 예상하는 곳에서는 Variance를 사용하십시오.
isAssignableksType.isAssignableFrom
isSameTypeksType.equals
isSubsignaturefunctionTypeA == functionTypeB / functionTypeA == functionTypeB.starProjection()
isSubtypeksType.isAssignableFrom
unboxedType필요하지 않습니다.