Skip to content

Java 어노테이션 처리를 KSP로 매핑하기 위한 참조

프로그램 요소

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

타입

KSP는 명시적인 타입 분석을 요구하므로, Java의 일부 기능은 KSType과 분석 전 해당 요소들로만 수행될 수 있습니다.

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

기타

JavaKSP의 해당 기능참고
NameKSName
ElementKindClassKind / FunctionKind
ModifierModifier
NestingKindClassKind / FunctionKind
AnnotationValueVisitor
ElementVisitorKSVisitor
AnnotatedConstructKSAnnotated
TypeVisitor
TypeKindKSBuiltIns일부는 빌트인에서 찾을 수 있으며, 그렇지 않은 경우 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에서만 사용할 수 있습니다. 타입 인수를 제공해야 합니다.
getAnnotation구현 예정
getAnnotationMirrorsksDeclaration.annotations
getEnclosedElementsksDeclarationContainer.declarations
getEnclosingElementsksDeclaration.parentDeclaration
getKind타입 확인 후 ClassKind 또는 FunctionKind에 따라 캐스팅
getModifiersksDeclaration.modifiers
getSimpleNameksDeclaration.simpleName

ExecutableElement

JavaKSP 대응
getDefaultValue구현 예정
getParametersksFunctionDeclaration.parameters
getReceiverTypeksFunctionDeclaration.parentDeclaration
getReturnTypeksFunctionDeclaration.returnType
getSimpleNameksFunctionDeclaration.simpleName
getThrownTypesKotlin에서 필요 없음
getTypeParametersksFunctionDeclaration.typeParameters
isDefault상위 선언이 인터페이스인지 확인
isVarArgsksFunctionDeclaration.parameters.any { it.isVarArg }

Parameterizable

JavaKSP 대응
getTypeParametersksFunctionDeclaration.typeParameters

QualifiedNameable

JavaKSP 대응
getQualifiedNameksDeclaration.qualifiedName

TypeElement

JavaKSP 대응
getEnclosedElementsksClassDeclaration.declarations
getEnclosingElementksClassDeclaration.parentDeclaration
getInterfaces
kotlin
// 분석 없이도 가능해야 함
ksClassDeclaration.superTypes
    .map { it.resolve() }
    .filter { (it?.declaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE }
getNestingKind`KSClassDeclaration.parentDeclaration`와 `inner` 한정자를 확인하세요.
getQualifiedNameksClassDeclaration.qualifiedName
getSimpleNameksClassDeclaration.simpleName
getSuperclass
kotlin
// 분석 없이도 가능해야 함
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

NOTE

함수를 위한 KSTypeFunctionN<R, T1, T2, ..., TN> 계열로 표현되는 시그니처일 뿐입니다.

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 대응
getKind원시 타입, Unit 타입에 대해서는 KSBuiltIns의 타입들과 비교하고, 그렇지 않은 경우 선언된 타입들과 비교합니다.

TypeVariable

JavaKSP 대응
asElementksType.declaration
getLowerBound결정 예정. 캡처가 제공되고 명시적인 바운드 검사가 필요한 경우에만 필요합니다.
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상수 값은 있지만 표현식은 없습니다.
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컨텍스트에 따라 KSType.markNullable이 유용할 수 있습니다.
getPrimitiveType필요 없음, KSBuiltins를 확인하세요.
getWildcardTypeKSTypeArgument가 예상되는 곳에 Variance를 사용하세요.
isAssignableksType.isAssignableFrom
isSameTypeksType.equals
isSubsignaturefunctionTypeA == functionTypeB / functionTypeA == functionTypeB.starProjection()
isSubtypeksType.isAssignableFrom
unboxedType필요 없음