Interface Resolver

    • Constructor Detail

    • Method Detail

      • 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 argument
        variance - specifies a use-site variance
      • 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

      • 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
      • 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.
      • getPackageAnnotations

         abstract Sequence<KSAnnotation> getPackageAnnotations(String packageName)

        Returns annotations applied in package-info.java (if applicable) for given package name.

        Parameters:
        packageName - package name to check.
      • getBuiltIns

         abstract KSBuiltIns getBuiltIns()

        Provides built in types for convenience. For example, KSBuiltins.anyType is the KSType instance for class 'kotlin.Any'.