1 /* 2 * Copyright 2020 Google LLC 3 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package com.google.devtools.ksp.symbol 18 19 /** 20 * Models class-like declarations, including class, interface and object. 21 */ 22 interface KSClassDeclaration : KSDeclaration, KSDeclarationContainer { 23 24 /** 25 * The Kind of the class declaration. 26 */ 27 val classKind: ClassKind 28 29 /** 30 * Primary constructor of a class, secondary constructors can be obtained by filtering [declarations]. 31 */ 32 val primaryConstructor: KSFunctionDeclaration? 33 34 /** 35 * Sequence of supertypes of this class, containing both super class and implemented interfaces. 36 */ 37 val superTypes: Sequence<KSTypeReference> 38 39 /** 40 * Determine whether this class declaration is a companion object. 41 * @see [https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.html#companion-objects] 42 */ 43 val isCompanionObject: Boolean 44 45 /** 46 * @return a sequence of sealed subclasses of this class, if any. 47 * Calling [getSealedSubclasses] requires type resolution which is expensive and should be avoided if possible. 48 */ getSealedSubclassesnull49 fun getSealedSubclasses(): Sequence<KSClassDeclaration> 50 51 /** 52 * Get all member functions of a class declaration, including declared and inherited. 53 * @return Sequence of function declarations from the class members. 54 * Calling [getAllFunctions] requires type resolution which is expensive and should be avoided if possible. 55 */ 56 fun getAllFunctions(): Sequence<KSFunctionDeclaration> 57 58 /** 59 * Get all member properties of a class declaration, including declared and inherited. 60 * @return Sequence of properties declarations from the class members. 61 * Calling [getAllProperties] requires type resolution which is expensive and should be avoided if possible. 62 */ 63 fun getAllProperties(): Sequence<KSPropertyDeclaration> 64 65 /** 66 * Create a type by applying a list of type arguments to this class' type parameters. 67 * @param typeArguments List of Type arguments to be applied. 68 * @return A type constructed from this class declaration with type parameters substituted with the type arguments. 69 */ 70 fun asType(typeArguments: List<KSTypeArgument>): KSType 71 72 /** 73 * If this is a generic class, return the type where the type argument is applied with star projection at use-site. 74 * @return A type with all type parameters applied with star projection. 75 */ 76 fun asStarProjectedType(): KSType 77 } 78