-
public interface ResolverResolver provides SymbolProcessor with access to compiler details such as Symbols.
-
-
Method Summary
Modifier and Type Method Description abstract Sequence<KSFile>getNewFiles()Get all new files in the module / compilation unit. abstract Sequence<KSFile>getAllFiles()Get all files in the module / compilation unit. abstract Sequence<KSAnnotated>getSymbolsWithAnnotation(String annotationName, Boolean inDepth)Get all symbols with specified annotation. abstract KSClassDeclarationgetClassDeclarationByName(KSName name)Find a class in the compilation classpath for the given name. abstract Sequence<KSFunctionDeclaration>getFunctionDeclarationsByName(KSName name, Boolean includeTopLevel)Find functions in the compilation classpath for the given name. abstract KSPropertyDeclarationgetPropertyDeclarationByName(KSName name, Boolean includeTopLevel)Find a property in the compilation classpath for the given name. abstract KSTypeArgumentgetTypeArgument(KSTypeReference typeRef, Variance variance)Compose a type argument out of a type reference and a variance abstract KSNamegetKSNameFromString(String name)Get a KSName from a String. abstract KSTypeReferencecreateKSTypeReferenceFromKSType(KSType type)Create a KSTypeReference from a KSType abstract StringmapToJvmSignature(KSDeclaration declaration)map a declaration to jvm signature. abstract Booleanoverrides(KSDeclaration overrider, KSDeclaration overridee)abstract Booleanoverrides(KSDeclaration overrider, KSDeclaration overridee, KSClassDeclaration containingClass)abstract StringgetJvmName(KSFunctionDeclaration declaration)Returns the jvm name of the given function. abstract StringgetJvmName(KSPropertyAccessor accessor)Returns the jvm name of the given property accessor. abstract StringgetOwnerJvmClassName(KSPropertyDeclaration declaration)Returns the binary class name of the owner class in JVM for the given KSPropertyDeclaration. abstract StringgetOwnerJvmClassName(KSFunctionDeclaration declaration)Returns the binary class name of the owner class in JVM for the given KSFunctionDeclaration. abstract Sequence<KSType>getJvmCheckedException(KSFunctionDeclaration function)Returns checked exceptions declared in a function's header. abstract Sequence<KSType>getJvmCheckedException(KSPropertyAccessor accessor)Returns checked exceptions declared in a property accessor's header. abstract Sequence<KSDeclaration>getDeclarationsFromPackage(String packageName)Returns declarations with the given package name. abstract KSNamemapJavaNameToKotlin(KSName javaName)Returns the corresponding Kotlin class with the given Java class. abstract KSNamemapKotlinNameToJava(KSName kotlinName)Returns the corresponding Java class with the given Kotlin class. abstract Sequence<KSDeclaration>getDeclarationsInSourceOrder(KSDeclarationContainer container)Same as KSDeclarationContainer.declarations, but sorted by declaration order in the source. abstract Set<Modifier>effectiveJavaModifiers(KSDeclaration declaration)Returns a set of effective Java modifiers, if declaration is being / was generated to Java bytecode. abstract KSTypeReferencegetJavaWildcard(KSTypeReference reference)Compute the corresponding Java wildcard, from the given reference. abstract BooleanisJavaRawType(KSType type)Tests a type if it was declared as legacy "raw" type in Java - a type with its type arguments fully omitted. abstract KSBuiltInsgetBuiltIns()Provides built in types for convenience. -
-
Method Detail
-
getNewFiles
abstract Sequence<KSFile> getNewFiles()
Get all new files in the module / compilation unit.
-
getAllFiles
abstract Sequence<KSFile> getAllFiles()
Get all files in the module / compilation unit.
-
getSymbolsWithAnnotation
abstract Sequence<KSAnnotated> getSymbolsWithAnnotation(String annotationName, Boolean inDepth)
Get all symbols with specified annotation. Note that in multiple round processing, only symbols from deferred symbols of last round and symbols from newly generated files will be returned in this function.
- Parameters:
annotationName- is the fully qualified name of the annotation; using '.' as separator.inDepth- whether to check symbols in depth, i.e.
-
getClassDeclarationByName
abstract KSClassDeclaration getClassDeclarationByName(KSName name)
Find a class in the compilation classpath for the given name.
This returns the exact platform class when given a platform name. Note that java.lang.String isn't compatible with kotlin.String in the type system. Therefore, processors need to use mapJavaNameToKotlin() and mapKotlinNameToJava() explicitly to find the corresponding class names before calling getClassDeclarationByName if type checking is needed for the classes loaded by this.
This behavior is limited to getClassDeclarationByName; When processors get a class or type from a Java source file, the conversion is done automatically. E.g., a java.lang.String in a Java source file is loaded as kotlin.String in KSP.
- Parameters:
name- fully qualified name of the class to be loaded; using '.' as separator.
-
getFunctionDeclarationsByName
abstract Sequence<KSFunctionDeclaration> getFunctionDeclarationsByName(KSName name, Boolean includeTopLevel)
Find functions in the compilation classpath for the given name.
- Parameters:
name- fully qualified name of the function to be loaded; using '.' as separator.includeTopLevel- a boolean value indicate if top level functions should be searched.
-
getPropertyDeclarationByName
abstract KSPropertyDeclaration getPropertyDeclarationByName(KSName name, Boolean includeTopLevel)
Find a property in the compilation classpath for the given name.
- Parameters:
name- fully qualified name of the property to be loaded; using '.' as separator.includeTopLevel- a boolean value indicate if top level properties should be searched.
-
getTypeArgument
abstract KSTypeArgument getTypeArgument(KSTypeReference typeRef, Variance variance)
Compose a type argument out of a type reference and a variance
- Parameters:
typeRef- a type reference to be used in type argumentvariance- specifies a use-site variance
-
getKSNameFromString
abstract KSName getKSNameFromString(String name)
Get a KSName from a String.
-
createKSTypeReferenceFromKSType
abstract KSTypeReference createKSTypeReferenceFromKSType(KSType type)
Create a KSTypeReference from a KSType
-
mapToJvmSignature
abstract String mapToJvmSignature(KSDeclaration declaration)
map a declaration to jvm signature. This function might fail due to resolution error, in case of error, null is returned. Resolution error could be caused by bad code that could not be resolved by compiler, or KSP bugs. If you believe your code is correct, please file a bug at https://github.com/google/ksp/issues/new
-
overrides
abstract Boolean overrides(KSDeclaration overrider, KSDeclaration overridee)
- Parameters:
overrider- the candidate overriding declaration being checked.overridee- the candidate overridden declaration being checked.
-
overrides
abstract Boolean overrides(KSDeclaration overrider, KSDeclaration overridee, KSClassDeclaration containingClass)
- Parameters:
overrider- the candidate overriding declaration being checked.overridee- the candidate overridden declaration being checked.containingClass- the containing class of candidate overriding and overridden declaration being checked.
-
getJvmName
abstract String getJvmName(KSFunctionDeclaration declaration)
Returns the jvm name of the given function. This function might fail due to resolution error, in case of error, null is returned. Resolution error could be caused by bad code that could not be resolved by compiler, or KSP bugs. If you believe your code is correct, please file a bug at https://github.com/google/ksp/issues/new
The jvm name of a function might depend on the Kotlin Compiler version hence it is not guaranteed to be compatible between different compiler versions except for the rules outlined in the Java interoperability documentation: https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html.
If the declaration is annotated with JvmName, that name will be returned from this function.
Note that this might be different from the name declared in the Kotlin source code in two cases: a) If the function receives or returns an inline class, its name will be mangled according to https://kotlinlang.org/docs/reference/inline-classes.html#mangling. b) If the function is declared as internal, it will include a suffix with the module name.
NOTE: As inline classes are an experimental feature, the result of this function might change based on the kotlin version used in the project.
-
getJvmName
abstract String getJvmName(KSPropertyAccessor accessor)
Returns the jvm name of the given property accessor. This function might fail due to resolution error, in case of error, null is returned. Resolution error could be caused by bad code that could not be resolved by compiler, or KSP bugs. If you believe your code is correct, please file a bug at https://github.com/google/ksp/issues/new
The jvm name of an accessor might depend on the Kotlin Compiler version hence it is not guaranteed to be compatible between different compiler versions except for the rules outlined in the Java interoperability documentation: https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html.
If the accessor is annotated with JvmName, that name will be returned from this function.
By default, this name will match the name calculated according to https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#properties. Note that the result of this function might be different from that name in two cases: a) If the property's type is an internal class, accessor's name will be mangled according to https://kotlinlang.org/docs/reference/inline-classes.html#mangling. b) If the function is declared as internal, it will include a suffix with the module name.
NOTE: As inline classes are an experimental feature, the result of this function might change based on the kotlin version used in the project. see: https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#properties
-
getOwnerJvmClassName
abstract String getOwnerJvmClassName(KSPropertyDeclaration declaration)
Returns the binary class name of the owner class in JVM for the given KSPropertyDeclaration.
For properties declared in classes / interfaces; this value is the binary class name of the declaring class.
For top level properties, this is the binary class name of the synthetic class that is generated for the Kotlin file. see: https://kotlinlang.org/docs/java-to-kotlin-interop.html#package-level-functions
Note that, for properties declared in companion objects, the returned owner class will be the Companion class. see: https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-methods
-
getOwnerJvmClassName
abstract String getOwnerJvmClassName(KSFunctionDeclaration declaration)
Returns the binary class name of the owner class in JVM for the given KSFunctionDeclaration.
For functions declared in classes / interfaces; this value is the binary class name of the declaring class.
For top level functions, this is the binary class name of the synthetic class that is generated for the Kotlin file. see: https://kotlinlang.org/docs/java-to-kotlin-interop.html#package-level-functions
Note that, for functions declared in companion objects, the returned owner class will be the Companion class. see: https://kotlinlang.org/docs/java-to-kotlin-interop.html#static-methods
-
getJvmCheckedException
abstract Sequence<KSType> getJvmCheckedException(KSFunctionDeclaration function)
Returns checked exceptions declared in a function's header.
-
getJvmCheckedException
abstract Sequence<KSType> getJvmCheckedException(KSPropertyAccessor accessor)
Returns checked exceptions declared in a property accessor's header.
-
getDeclarationsFromPackage
abstract Sequence<KSDeclaration> getDeclarationsFromPackage(String packageName)
Returns declarations with the given package name.
- Parameters:
packageName- the package name to look up.
-
mapJavaNameToKotlin
abstract KSName mapJavaNameToKotlin(KSName javaName)
Returns the corresponding Kotlin class with the given Java class.
E.g. java.lang.String -> kotlin.String java.lang.Integer -> kotlin.Int java.util.List -> kotlin.List java.util.Map.Entry -> kotlin.Map.Entry java.lang.Void -> null
- Parameters:
javaName- a Java class name
-
mapKotlinNameToJava
abstract KSName mapKotlinNameToJava(KSName kotlinName)
Returns the corresponding Java class with the given Kotlin class.
E.g. kotlin.Throwable -> java.lang.Throwable kotlin.Int -> java.lang.Integer kotlin.Nothing -> java.lang.Void kotlin.IntArray -> null
- Parameters:
kotlinName- a Java class name
-
getDeclarationsInSourceOrder
abstract Sequence<KSDeclaration> getDeclarationsInSourceOrder(KSDeclarationContainer container)
Same as KSDeclarationContainer.declarations, but sorted by declaration order in the source.
Note that this is SLOW. AVOID IF POSSIBLE.
-
effectiveJavaModifiers
abstract Set<Modifier> effectiveJavaModifiers(KSDeclaration declaration)
Returns a set of effective Java modifiers, if declaration is being / was generated to Java bytecode.
-
getJavaWildcard
abstract KSTypeReference getJavaWildcard(KSTypeReference reference)
Compute the corresponding Java wildcard, from the given reference.
- Parameters:
reference- the reference to the type usage
-
isJavaRawType
abstract Boolean isJavaRawType(KSType type)
Tests a type if it was declared as legacy "raw" type in Java - a type with its type arguments fully omitted.
- Parameters:
type- a type to check.
-
getBuiltIns
abstract KSBuiltIns getBuiltIns()
Provides built in types for convenience. For example, KSBuiltins.anyType is the KSType instance for class 'kotlin.Any'.
-
-
-
-