Package 

Interface KSFunctionDeclaration

  • All Implemented Interfaces:
    com.google.devtools.ksp.symbol.KSAnnotated , com.google.devtools.ksp.symbol.KSDeclaration , com.google.devtools.ksp.symbol.KSDeclarationContainer , com.google.devtools.ksp.symbol.KSExpectActual , com.google.devtools.ksp.symbol.KSModifierListOwner , com.google.devtools.ksp.symbol.KSNode

    
    public interface KSFunctionDeclaration
     implements KSDeclaration, KSDeclarationContainer
                        

    A function definition

    Dispatch receiver can be obtained through parentDeclaration.

    To obtain the function signature where type arguments are resolved as member of a given KSType, use Resolver.asMemberOf.

    • Method Detail

      • findOverridee

         abstract KSDeclaration findOverridee()

        Find the closest overridee of this function, if overriding.

        For the following input:

        abstract class A {
          open fun x() {}
          open fun y() {}
        }
        abstract class B : A() {
          override open fun x() {}
        }
        abstract class C : B() {
          override open fun x() {}
          override open fun y() {}
        }

        Calling findOverridee on C.x will return B.x. Calling findOverridee on C.y will return A.y.

        When there are multiple super interfaces implementing the function, the closest declaration to the current containing declaration is selected. If they are in the same level, the function of the first specified interface (in source) will be returned.

      • asMemberOf

         abstract KSFunction asMemberOf(KSType containing)

        Returns the type of the function when it is viewed as member of the containing type.

        For instance, for the following input:

        interface Base<T> {
          fun f(t:T?):T
        }
        val foo: Base<Int>
        val bar: Base<String>

        When f() is viewed as member of foo, this method will return a KSFunction where the KSFunction.returnType is Int and the parameter t is of type Int?. When f() is viewed as member of bar, this method will return a KSFunction where the KSFunction.returnType is String and the parameter t is of type String?.

        If the function has type parameters, they'll not be resolved and can be read from KSFunction.typeParameters.

        If the substitution fails (e.g. if containing is an error type, a KSFunction with KSFunction.isErrortrue is returned.

        Parameters:
        containing - The type that contains function.
      • getSimpleName

         abstract KSName getSimpleName()

        Simple name of this declaration, usually the name identifier at the declaration site.

      • getQualifiedName

         abstract KSName getQualifiedName()

        Fully qualified name of this declaration, might not exist for some declarations like local declarations.

      • getPackageName

         abstract KSName getPackageName()

        The name of the package at which this declaration is declared.

      • getParentDeclaration

         abstract KSDeclaration getParentDeclaration()

        Parent declaration of this declaration, i.e. the declaration that directly contains this declaration. File is not a declaration, so this property will be null for top level declarations.

      • getContainingFile

         abstract KSFile getContainingFile()

        The containing source file of this declaration, can be null if symbol does not come from a source file, i.e. from a class file.