Java アノテーションプロセッシングから KSP へのリファレンス
プログラム要素 (Program elements)
| Java | KSP における最も近い機能 | 備考 |
|---|---|---|
AnnotationMirror | KSAnnotation | |
AnnotationValue | KSValueArguments | |
Element | KSDeclaration / KSDeclarationContainer | |
ExecutableElement | KSFunctionDeclaration | |
PackageElement | KSFile | KSP はパッケージをプログラム要素としてモデル化しません |
Parameterizable | KSDeclaration | |
QualifiedNameable | KSDeclaration | |
TypeElement | KSClassDeclaration | |
TypeParameterElement | KSTypeParameter | |
VariableElement | KSValueParameter / KSPropertyDeclaration |
型 (Types)
KSP では明示的な型解決(type resolution)が必要なため、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 | N/A | Kotlin は catch ブロックごとに 1 つの型しか持ちません。UnionType は Java のアノテーションプロセッサからさえも観測できません |
WildcardType | KSType / KSTypeArgument |
その他 (Misc)
| Java | KSP における最も近い機能 | 備考 |
|---|---|---|
Name | KSName | |
ElementKind | ClassKind / FunctionKind | |
Modifier | Modifier | |
NestingKind | ClassKind / FunctionKind | |
AnnotationValueVisitor | ||
ElementVisitor | KSVisitor | |
AnnotatedConstruct | KSAnnotated | |
TypeVisitor | ||
TypeKind | KSBuiltIns | 一部は builtins にあります。それ以外は DeclaredType について KSClassDeclaration を確認してください |
ElementFilter | Collection.filterIsInstance | |
ElementKindVisitor | KSVisitor | |
ElementScanner | KSTopDownVisitor | |
SimpleAnnotationValueVisitor | KSP では不要です | |
SimpleElementVisitor | KSVisitor | |
SimpleTypeVisitor | ||
TypeKindVisitor | ||
Types | Resolver / utils | utils の一部はシンボルインターフェースにも統合されています |
Elements | Resolver / utils |
詳細 (Details)
Java アノテーションプロセッシング API の機能が KSP でどのように実行されるかを確認してください。
AnnotationMirror
| Java | KSP における同等の機能 |
|---|---|
getAnnotationType | ksAnnotation.annotationType |
getElementValues | ksAnnotation.arguments |
AnnotationValue
| Java | KSP における同等の機能 |
|---|---|
getValue | ksValueArgument.value |
Element
| 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 | 親の宣言がインターフェースかどうかを確認します |
isVarArgs | ksFunctionDeclaration.parameters.any { it.isVarArg } |
Parameterizable
| Java | KSP における同等の機能 |
|---|---|
getTypeParameters | ksFunctionDeclaration.typeParameters |
QualifiedNameable
| Java | KSP における同等の機能 |
|---|---|
getQualifiedName | ksDeclaration.qualifiedName |
TypeElement
| Java | KSP における同等の機能 |
getEnclosedElements | ksClassDeclaration.declarations |
getEnclosingElement | ksClassDeclaration.parentDeclaration |
getInterfaces | kotlin |
getNestingKind | KSClassDeclaration.parentDeclaration と inner 修飾子を確認します |
getQualifiedName | ksClassDeclaration.qualifiedName |
getSimpleName | ksClassDeclaration.simpleName |
getSuperclass | kotlin |
getTypeParameters | ksClassDeclaration.typeParameters |
TypeParameterElement
| Java | KSP における同等の機能 |
|---|---|
getBounds | ksTypeParameter.bounds |
getEnclosingElement | ksTypeParameter.parentDeclaration |
getGenericElement | ksTypeParameter.parentDeclaration |
VariableElement
| Java | KSP における同等の機能 |
|---|---|
getConstantValue | 実装予定 |
getEnclosingElement | ksValueParameter.parentDeclaration |
getSimpleName | ksValueParameter.simpleName |
ArrayType
| Java | KSP における同等の機能 |
|---|---|
getComponentType | ksType.arguments.first() |
DeclaredType
| Java | KSP における同等の機能 |
|---|---|
asElement | ksType.declaration |
getEnclosingType | ksType.declaration.parentDeclaration |
getTypeArguments | ksType.arguments |
ExecutableType
関数の
KSTypeは、FunctionN<R, T1, T2, ..., TN>ファミリによって表される単なるシグネチャです。
| Java | KSP における同等の機能 |
|---|---|
getParameterTypes | ksType.declaration.typeParameters, ksFunctionDeclaration.parameters.map { it.type } |
getReceiverType | ksFunctionDeclaration.parentDeclaration.asType(...) |
getReturnType | ksType.declaration.typeParameters.last() |
getThrownTypes | Kotlin では不要です |
getTypeVariables | ksFunctionDeclaration.typeParameters |
IntersectionType
| Java | KSP における同等の機能 |
|---|---|
getBounds | ksTypeParameter.bounds |
TypeMirror
| Java | KSP における同等の機能 |
|---|---|
getKind | プリミティブ型や Unit 型については KSBuiltIns 内の型と比較し、それ以外は宣言された型と比較します |
TypeVariable
| Java | KSP における同等の機能 |
|---|---|
asElement | ksType.declaration |
getLowerBound | 検討中。キャプチャが提供され、明示的な境界チェックが必要な場合にのみ必要です。 |
getUpperBound | ksTypeParameter.bounds |
WildcardType
| Java | KSP における同等の機能 |
getExtendsBound | kotlin |
getSuperBound | kotlin |
Elements
| Java | KSP における同等の機能 |
getAllAnnotationMirrors | KSDeclarations.annotations |
getAllMembers | getAllFunctions、getAllProperties が実装予定です |
getBinaryName | 検討中。Java 仕様を参照してください |
getConstantExpression | 式ではなく定数値があります |
getDocComment | 実装予定 |
getElementValuesWithDefaults | 実装予定 |
getName | resolver.getKSNameFromString |
getPackageElement | パッケージはサポートされていませんが、パッケージ情報は取得できます。KSP ではパッケージに対する操作は不可能です |
getPackageOf | パッケージはサポートされていません |
getTypeElement | Resolver.getClassDeclarationByName |
hides | 実装予定 |
isDeprecated | kotlin |
overrides | KSFunctionDeclaration.overrides / KSPropertyDeclaration.overrides (各クラスのメンバ関数) |
printElements | KSP はほとんどのクラスで基本的な toString() 実装を持っています |
型の操作 (Types)
| Java | KSP における同等の機能 |
|---|---|
asElement | ksType.declaration |
asMemberOf | resolver.asMemberOf |
boxedClass | 不要です |
capture | 検討中 |
contains | KSType.isAssignableFrom |
directSuperTypes | (ksType.declaration as KSClassDeclaration).superTypes |
erasure | ksType.starProjection() |
getArrayType | ksBuiltIns.arrayType.replace(...) |
getDeclaredType | ksClassDeclaration.asType |
getNoType | ksBuiltIns.nothingType / null |
getNullType | コンテキストによっては KSType.markNullable が役立つ場合があります |
getPrimitiveType | 不要です。KSBuiltins を確認してください |
getWildcardType | KSTypeArgument を期待する場所で Variance を使用します |
isAssignable | ksType.isAssignableFrom |
isSameType | ksType.equals |
isSubsignature | functionTypeA == functionTypeB / functionTypeA == functionTypeB.starProjection() |
isSubtype | ksType.isAssignableFrom |
unboxedType | 不要です |
