# KSP 示例程序 ## 得到所有成员函数 ```KOTLIN fun KSClassDeclaration.getDeclaredFunctions(): Sequence = declarations.filterIsInstance() ``` ## 检查一个类或函数是否为 local ```KOTLIN fun KSDeclaration.isLocal(): Boolean = parentDeclaration != null && parentDeclaration !is KSClassDeclaration ``` ## 查找类型别名指向的实际的类或接口声明 ```KOTLIN fun KSTypeAlias.findActualType(): KSClassDeclaration { val resolvedType = this.type.resolve().declaration return if (resolvedType is KSTypeAlias) { resolvedType.findActualType() } else { resolvedType as KSClassDeclaration } } ``` ## 在源代码文件的注解中查找被压制(Suppressed)的名称 ```KOTLIN // @file:kotlin.Suppress("Example1", "Example2") fun KSFile.suppressedNames(): Sequence = annotations .filter { it.shortName.asString() == "Suppress" && it.annotationType.resolve().declaration.qualifiedName?.asString() == "kotlin.Suppress" }.flatMap { it.arguments.flatMap { (it.value as Array).toList() } } ```