Javaのアノテーション処理からKSPへのリファレンス
プログラム要素
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 |
型
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 | N/A | Kotlinはcatchブロックごとに1つの型しか持ちません。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 | いくつかは組み込み型で見つけられます。それ以外はDeclaredType のためにKSClassDeclaration を確認してください。 |
ElementFilter | Collection.filterIsInstance | |
ElementKindVisitor | KSVisitor | |
ElementScanner | KSTopDownVisitor | |
SimpleAnnotationValueVisitor | KSPでは不要 | |
SimpleElementVisitor | KSVisitor | |
SimpleTypeVisitor | ||
TypeKindVisitor | ||
Types | Resolver / utils | utils の一部はシンボルインターフェースにも統合されています。 |
Elements | Resolver / utils |
詳細
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
NOTE
関数の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 Specificationを参照 |
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 | 不要 |