From 981fb70528f689c328bf6da3ff91f0d2ab973ca7 Mon Sep 17 00:00:00 2001 From: lukellmann Date: Fri, 22 Sep 2023 17:58:46 +0200 Subject: [PATCH] Fix compilation Abstract implementation classes that inherited from now sealed types have those supertypes removed and replace overridden with open members. Additional casts had to be introduced in a few places. A few when statements had to be made exhaustive (by specifying all cases) because they now operate on subjects with a sealed type. --- .../com/google/devtools/ksp/Incremental.kt | 2 ++ .../ksp/processing/impl/ResolverImpl.kt | 2 ++ .../binary/KSDeclarationDescriptorImpl.kt | 25 +++++++++--------- .../KSPropertyAccessorDescriptorImpl.kt | 17 ++++++------ .../symbol/impl/java/KSDeclarationJavaImpl.kt | 14 +++++----- .../symbol/impl/kotlin/KSDeclarationImpl.kt | 26 +++++++++---------- .../impl/kotlin/KSPropertyAccessorImpl.kt | 22 ++++++++-------- .../synthetic/KSConstructorSyntheticImpl.kt | 8 +++--- .../KSPropertyAccessorSyntheticImpl.kt | 18 ++++++------- .../google/devtools/ksp/symbol/impl/utils.kt | 5 ++-- .../devtools/ksp/impl/ResolverAAImpl.kt | 2 ++ .../kotlin/AbstractKSDeclarationImpl.kt | 26 +++++++++---------- .../symbol/kotlin/KSPropertyAccessorImpl.kt | 22 ++++++++-------- 13 files changed, 100 insertions(+), 89 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/Incremental.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/Incremental.kt index 18bbc51b0b..83f0f41648 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/Incremental.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/Incremental.kt @@ -703,6 +703,8 @@ class IncrementalContext( when (declaration) { is KSPropertyDeclarationJavaImpl -> recordLookupForJavaField(declaration.psi) is KSFunctionDeclarationJavaImpl -> recordLookupForJavaMethod(declaration.psi) + is KSClassDeclaration, is KSFunctionDeclaration, is KSPropertyDeclaration, is KSTypeAlias, + is KSTypeParameter -> Unit } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt index f07b68e633..f79e6914dc 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt @@ -1192,6 +1192,7 @@ class ResolverImpl( if (declaration.isAbstract) modifiers.add(Modifier.ABSTRACT) } + is KSTypeAlias, is KSTypeParameter -> Unit } } Origin.KOTLIN_LIB, Origin.JAVA_LIB -> { @@ -1208,6 +1209,7 @@ class ResolverImpl( if (declaration.jvmAccessFlag and Opcodes.ACC_SYNCHRONIZED != 0) modifiers.add(Modifier.JAVA_SYNCHRONIZED) } + is KSClassDeclaration, is KSTypeAlias, is KSTypeParameter -> Unit } } else -> Unit diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSDeclarationDescriptorImpl.kt index db041b2668..e0e5d6ee17 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSDeclarationDescriptorImpl.kt @@ -30,21 +30,22 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parents import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull -abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDescriptor) : KSDeclaration { +abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDescriptor) /*: KSDeclaration*/ { - override val origin by lazy { + open /*override*/ val origin by lazy { descriptor.origin } - override val containingFile: KSFile? = null + open /*override*/ val containingFile: KSFile? = null - override val location: Location = NonExistLocation + open /*override*/ val location: Location = NonExistLocation - override val annotations: Sequence by lazy { - descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this) }.memoized() + open /*override*/ val annotations: Sequence by lazy { + descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this as KSDeclaration) } + .memoized() } - override val parentDeclaration: KSDeclaration? by lazy { + open /*override*/ val parentDeclaration: KSDeclaration? by lazy { val containingDescriptor = descriptor.parents.first() when (containingDescriptor) { is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(containingDescriptor) @@ -53,19 +54,19 @@ abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDe } as KSDeclaration? } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { parentDeclaration } - override val packageName: KSName by lazy { + open /*override*/ val packageName: KSName by lazy { KSNameImpl.getCached(descriptor.findPackage().fqName.asString()) } - override val qualifiedName: KSName by lazy { + open /*override*/ val qualifiedName: KSName by lazy { KSNameImpl.getCached(descriptor.fqNameSafe.asString()) } - override val simpleName: KSName by lazy { + open /*override*/ val simpleName: KSName by lazy { KSNameImpl.getCached(descriptor.name.asString()) } @@ -73,7 +74,7 @@ abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDe return this.simpleName.asString() } - override val docString = null + open /*override*/ val docString: String? = null } val DeclarationDescriptor.origin: Origin diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt index 99ad99dc06..e51a5d541b 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyAccessorDescriptorImpl.kt @@ -25,8 +25,8 @@ import com.google.devtools.ksp.symbol.impl.toKSPropertyDeclaration import com.google.devtools.ksp.toKSModifiers import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor -abstract class KSPropertyAccessorDescriptorImpl(val descriptor: PropertyAccessorDescriptor) : KSPropertyAccessor { - override val origin: Origin by lazy { +abstract class KSPropertyAccessorDescriptorImpl(val descriptor: PropertyAccessorDescriptor) /*: KSPropertyAccessor*/ { + open /*override*/ val origin: Origin by lazy { when (receiver.origin) { // if receiver is kotlin source, that means we are a synthetic where developer // didn't declare an explicit accessor so we used the descriptor instead @@ -35,26 +35,27 @@ abstract class KSPropertyAccessorDescriptorImpl(val descriptor: PropertyAccessor } } - override val receiver: KSPropertyDeclaration by lazy { + open /*override*/ val receiver: KSPropertyDeclaration by lazy { descriptor.correspondingProperty.toKSPropertyDeclaration() } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { receiver } - override val location: Location + open /*override*/ val location: Location get() { // if receiver is kotlin source, that means `this` is synthetic hence we want the property's location // Otherwise, receiver is also from a .class file where the location will be NoLocation return receiver.location } - override val annotations: Sequence by lazy { - descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this) }.memoized() + open /*override*/ val annotations: Sequence by lazy { + descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this as KSPropertyAccessor) } + .memoized() } - override val modifiers: Set by lazy { + open /*override*/ val modifiers: Set by lazy { val modifiers = mutableSetOf() modifiers.addAll(descriptor.toKSModifiers()) modifiers.addAll(descriptor.toFunctionKSModifiers()) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt index ebdffaccd7..dd23e85afb 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSDeclarationJavaImpl.kt @@ -25,24 +25,24 @@ import com.google.devtools.ksp.symbol.impl.findParentDeclaration import com.google.devtools.ksp.symbol.impl.getDocString import com.intellij.psi.PsiElement -abstract class KSDeclarationJavaImpl(private val psi: PsiElement) : KSDeclaration { - override val packageName: KSName by lazy { - this.containingFile!!.packageName +abstract class KSDeclarationJavaImpl(private val psi: PsiElement) /*: KSDeclaration*/ { + open /*override*/ val packageName: KSName by lazy { + (this as KSDeclaration).containingFile!!.packageName } override fun toString(): String { - return this.simpleName.asString() + return (this as KSDeclaration).simpleName.asString() } - override val docString by lazy { + open /*override*/ val docString by lazy { psi.getDocString() } - override val parentDeclaration: KSDeclaration? by lazy { + open /*override*/ val parentDeclaration: KSDeclaration? by lazy { psi.findParentDeclaration() } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { psi.findParentAnnotated() } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt index b1f2a8499f..c01defae32 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSDeclarationImpl.kt @@ -24,26 +24,26 @@ import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.symbol.impl.* import org.jetbrains.kotlin.psi.* -abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) : KSDeclaration { - override val origin: Origin = Origin.KOTLIN +abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) /*: KSDeclaration*/ { + open /*override*/ val origin: Origin = Origin.KOTLIN - override val location: Location by lazy { + open /*override*/ val location: Location by lazy { ktDeclaration.toLocation() } - override val simpleName: KSName by lazy { + open /*override*/ val simpleName: KSName by lazy { KSNameImpl.getCached(ktDeclaration.name!!) } - override val qualifiedName: KSName? by lazy { + open /*override*/ val qualifiedName: KSName? by lazy { (ktDeclaration as? KtNamedDeclaration)?.fqName?.let { KSNameImpl.getCached(it.asString()) } } - override val annotations: Sequence by lazy { + open /*override*/ val annotations: Sequence by lazy { ktDeclaration.annotationEntries.asSequence().map { KSAnnotationImpl.getCached(it) }.memoized() } - override val modifiers: Set by lazy { + open /*override*/ val modifiers: Set by lazy { // we do not check for JVM_STATIC here intentionally as it actually means static in parent class, // not in this class. // see: https://github.com/google/ksp/issues/378 @@ -56,25 +56,25 @@ abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) : KSDeclarati } } - override val containingFile: KSFile? by lazy { + open /*override*/ val containingFile: KSFile? by lazy { KSFileImpl.getCached(ktDeclaration.containingKtFile) } - override val packageName: KSName by lazy { + open /*override*/ val packageName: KSName by lazy { this.containingFile!!.packageName } - override val typeParameters: List by lazy { + open /*override*/ val typeParameters: List by lazy { (ktDeclaration as? KtTypeParameterListOwner)?.let { it.typeParameters.map { KSTypeParameterImpl.getCached(it) } } ?: emptyList() } - override val parentDeclaration: KSDeclaration? by lazy { + open /*override*/ val parentDeclaration: KSDeclaration? by lazy { ktDeclaration.findParentDeclaration() } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { ktDeclaration.findParentAnnotated() } @@ -86,7 +86,7 @@ abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) : KSDeclarati ktDeclaration.annotationEntries.map { KSAnnotationImpl.getCached(it) } } - override val docString by lazy { + open /*override*/ val docString by lazy { ktDeclaration.getDocString() } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt index 9d57b25d27..79a12a6d0f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyAccessorImpl.kt @@ -26,7 +26,7 @@ import com.google.devtools.ksp.symbol.impl.toLocation import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtPropertyAccessor -abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor) : KSPropertyAccessor { +abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor) /*: KSPropertyAccessor*/ { companion object { fun getCached(ktPropertyAccessor: KtPropertyAccessor): KSPropertyAccessor { return if (ktPropertyAccessor.isGetter) { @@ -36,27 +36,27 @@ abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor } } } - override val receiver: KSPropertyDeclaration by lazy { + open /*override*/ val receiver: KSPropertyDeclaration by lazy { KSPropertyDeclarationImpl.getCached(ktPropertyAccessor.property as KtProperty) } - override val annotations: Sequence by lazy { + open /*override*/ val annotations: Sequence by lazy { ktPropertyAccessor.filterUseSiteTargetAnnotations().map { KSAnnotationImpl.getCached(it) } - .plus(this.findAnnotationFromUseSiteTarget()) + .plus((this as KSPropertyAccessor).findAnnotationFromUseSiteTarget()) } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { receiver } - override val location: Location by lazy { + open /*override*/ val location: Location by lazy { ktPropertyAccessor.toLocation() } - override val modifiers: Set by lazy { + open /*override*/ val modifiers: Set by lazy { ktPropertyAccessor.toKSModifiers() } - override val declarations: Sequence by lazy { + open /*override*/ val declarations: Sequence by lazy { if (!ktPropertyAccessor.hasBlockBody()) { emptySequence() } else { @@ -65,10 +65,10 @@ abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor } } - override val origin: Origin = Origin.KOTLIN + open /*override*/ val origin: Origin = Origin.KOTLIN - override fun accept(visitor: KSVisitor, data: D): R { - return visitor.visitPropertyAccessor(this, data) + open /*override*/ fun accept(visitor: KSVisitor, data: D): R { + return visitor.visitPropertyAccessor(this as KSPropertyAccessor, data) } internal val originalAnnotations: List by lazy { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt index 8f2efd36f7..dc0bd3a47a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt @@ -25,9 +25,7 @@ import com.google.devtools.ksp.processing.impl.ResolverImpl import com.google.devtools.ksp.symbol.* class KSConstructorSyntheticImpl private constructor(val ksClassDeclaration: KSClassDeclaration) : - KSFunctionDeclaration, - KSDeclaration - by ksClassDeclaration { + KSFunctionDeclaration { companion object : KSObjectCache() { fun getCached(ksClassDeclaration: KSClassDeclaration) = KSConstructorSyntheticImpl.cache.getOrPut(ksClassDeclaration) { @@ -43,6 +41,10 @@ class KSConstructorSyntheticImpl private constructor(val ksClassDeclaration: KSC override val functionKind: FunctionKind = FunctionKind.MEMBER + override val docString: String? get() = ksClassDeclaration.docString + + override val packageName: KSName get() = ksClassDeclaration.packageName + override val qualifiedName: KSName? by lazy { KSNameImpl.getCached(ksClassDeclaration.qualifiedName?.asString()?.plus(".") ?: "") } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyAccessorSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyAccessorSyntheticImpl.kt index f6f0ad9fc6..98d5fe5f4a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyAccessorSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyAccessorSyntheticImpl.kt @@ -20,22 +20,22 @@ package com.google.devtools.ksp.symbol.impl.synthetic import com.google.devtools.ksp.processing.impl.findAnnotationFromUseSiteTarget import com.google.devtools.ksp.symbol.* -abstract class KSPropertyAccessorSyntheticImpl(ksPropertyDeclaration: KSPropertyDeclaration) : KSPropertyAccessor { - override val annotations: Sequence by lazy { - this.findAnnotationFromUseSiteTarget() +abstract class KSPropertyAccessorSyntheticImpl(ksPropertyDeclaration: KSPropertyDeclaration) /*: KSPropertyAccessor*/ { + open /*override*/ val annotations: Sequence by lazy { + (this as KSPropertyAccessor).findAnnotationFromUseSiteTarget() } - override val location: Location by lazy { + open /*override*/ val location: Location by lazy { ksPropertyDeclaration.location } - override val modifiers: Set = emptySet() + open /*override*/ val modifiers: Set = emptySet() - override val origin: Origin = Origin.SYNTHETIC + open /*override*/ val origin: Origin = Origin.SYNTHETIC - override val receiver: KSPropertyDeclaration = ksPropertyDeclaration + open /*override*/ val receiver: KSPropertyDeclaration = ksPropertyDeclaration - override fun accept(visitor: KSVisitor, data: D): R { - return visitor.visitPropertyAccessor(this, data) + open /*override*/ fun accept(visitor: KSVisitor, data: D): R { + return visitor.visitPropertyAccessor(this as KSPropertyAccessor, data) } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt index 66de2f9d6a..a926f0fe0c 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt @@ -319,7 +319,7 @@ internal class DeclarationOrdering( } private fun getOrder(decl: KSDeclarationDescriptorImpl): Int { - return declOrdering.getOrPut(decl) { + return declOrdering.getOrPut(decl as KSDeclaration) { when (decl) { is KSPropertyDeclarationDescriptorImpl -> { fieldOrdering[decl.simpleName.asString()]?.let { @@ -467,7 +467,8 @@ internal val KSDeclarationContainer.declarationsInSourceOrder: Sequence)?.sortedWith(declarationOrdering.comparator) + return (declarations as? Sequence) + ?.sortedWith(declarationOrdering.comparator) as Sequence? ?: declarations } diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt index b3b497bea5..496750bd89 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/ResolverAAImpl.kt @@ -169,6 +169,7 @@ class ResolverAAImpl( if (declaration.isAbstract) modifiers.add(Modifier.ABSTRACT) } + is KSTypeAlias, is KSTypeParameter -> Unit } } Origin.KOTLIN_LIB, Origin.JAVA_LIB -> { @@ -189,6 +190,7 @@ class ResolverAAImpl( if (declaration.jvmAccessFlag and Opcodes.ACC_SYNCHRONIZED != 0) modifiers.add(Modifier.JAVA_SYNCHRONIZED) } + is KSClassDeclaration, is KSTypeAlias, is KSTypeParameter -> Unit } } else -> Unit diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt index 9c73650b6f..f42f5b41f9 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/AbstractKSDeclarationImpl.kt @@ -38,24 +38,24 @@ import org.jetbrains.kotlin.analysis.utils.printer.parentOfType import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtModifierListOwner -abstract class AbstractKSDeclarationImpl(val ktDeclarationSymbol: KtDeclarationSymbol) : KSDeclaration, Deferrable { - override val origin: Origin by lazy { +abstract class AbstractKSDeclarationImpl(val ktDeclarationSymbol: KtDeclarationSymbol) : /*KSDeclaration,*/ Deferrable { + open /*override*/ val origin: Origin by lazy { mapAAOrigin(ktDeclarationSymbol) } - override val location: Location by lazy { + open /*override*/ val location: Location by lazy { ktDeclarationSymbol.psi.toLocation() } - override val simpleName: KSName by lazy { + open /*override*/ val simpleName: KSName by lazy { KSNameImpl.getCached((ktDeclarationSymbol as? KtNamedSymbol)?.name?.asString() ?: "") } - override val annotations: Sequence by lazy { + open /*override*/ val annotations: Sequence by lazy { originalAnnotations } - override val modifiers: Set by lazy { + open /*override*/ val modifiers: Set by lazy { if (origin == Origin.JAVA_LIB || origin == Origin.KOTLIN_LIB) { when (ktDeclarationSymbol) { is KtPropertySymbol -> ktDeclarationSymbol.toModifiers() @@ -73,24 +73,24 @@ abstract class AbstractKSDeclarationImpl(val ktDeclarationSymbol: KtDeclarationS } } - override val containingFile: KSFile? by lazy { + open /*override*/ val containingFile: KSFile? by lazy { ktDeclarationSymbol.toContainingFile() } - override val packageName: KSName by lazy { + open /*override*/ val packageName: KSName by lazy { ((containingFile?.packageName ?: ktDeclarationSymbol.getContainingKSSymbol()?.packageName)?.asString() ?: "") .let { KSNameImpl.getCached(it) } } - override val typeParameters: List by lazy { + open /*override*/ val typeParameters: List by lazy { ktDeclarationSymbol.typeParameters.map { KSTypeParameterImpl.getCached(it) } } - override val parentDeclaration: KSDeclaration? by lazy { + open /*override*/ val parentDeclaration: KSDeclaration? by lazy { parent as? KSDeclaration } - override val parent: KSNode? by lazy { + open /*override*/ val parent: KSNode? by lazy { analyze { ktDeclarationSymbol.getContainingSymbol()?.let { ktDeclarationSymbol.getContainingKSSymbol() @@ -104,11 +104,11 @@ abstract class AbstractKSDeclarationImpl(val ktDeclarationSymbol: KtDeclarationS return simpleName.asString() } - override val docString: String? + open /*override*/ val docString: String? get() = ktDeclarationSymbol.toDocString() internal val originalAnnotations = if (ktDeclarationSymbol.psi is KtElement || ktDeclarationSymbol.psi == null) { - ktDeclarationSymbol.annotations(this) + ktDeclarationSymbol.annotations(this as KSDeclaration) } else { (ktDeclarationSymbol.psi as PsiJvmModifiersOwner) .annotations.map { KSAnnotationJavaImpl.getCached(it, this) }.asSequence() diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt index fb5863c85b..443f74bca8 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyAccessorImpl.kt @@ -31,23 +31,23 @@ import org.jetbrains.kotlin.psi.KtPropertyAccessor abstract class KSPropertyAccessorImpl( internal val ktPropertyAccessorSymbol: KtPropertyAccessorSymbol, - override val receiver: KSPropertyDeclaration -) : KSPropertyAccessor, Deferrable { + open /*override*/ val receiver: KSPropertyDeclaration +) : /*KSPropertyAccessor,*/ Deferrable { - override val annotations: Sequence by lazy { + open /*override*/ val annotations: Sequence by lazy { ktPropertyAccessorSymbol.annotations.asSequence() .filter { it.useSiteTarget != AnnotationUseSiteTarget.SETTER_PARAMETER } - .map { KSAnnotationImpl.getCached(it, this) } - .plus(findAnnotationFromUseSiteTarget()) + .map { KSAnnotationImpl.getCached(it, this as KSPropertyAccessor) } + .plus((this as KSPropertyAccessor).findAnnotationFromUseSiteTarget()) } - internal val originalAnnotations = ktPropertyAccessorSymbol.annotations(this) + internal val originalAnnotations = ktPropertyAccessorSymbol.annotations(this as KSPropertyAccessor) - override val location: Location by lazy { + open /*override*/ val location: Location by lazy { ktPropertyAccessorSymbol.psi?.toLocation() ?: NonExistLocation } - override val modifiers: Set by lazy { + open /*override*/ val modifiers: Set by lazy { ((ktPropertyAccessorSymbol.psi as? KtModifierListOwner)?.toKSModifiers() ?: emptySet()).let { if (origin == Origin.SYNTHETIC && (receiver.parentDeclaration as? KSClassDeclaration)?.classKind == ClassKind.INTERFACE @@ -59,7 +59,7 @@ abstract class KSPropertyAccessorImpl( } } - override val origin: Origin by lazy { + open /*override*/ val origin: Origin by lazy { val symbolOrigin = mapAAOrigin(ktPropertyAccessorSymbol) if (symbolOrigin == Origin.KOTLIN && ktPropertyAccessorSymbol.psi == null) { Origin.SYNTHETIC @@ -68,10 +68,10 @@ abstract class KSPropertyAccessorImpl( } } - override val parent: KSNode? + open /*override*/ val parent: KSNode? get() = ktPropertyAccessorSymbol.getContainingKSSymbol() - override val declarations: Sequence by lazy { + open /*override*/ val declarations: Sequence by lazy { val psi = ktPropertyAccessorSymbol.psi as? KtPropertyAccessor ?: return@lazy emptySequence() if (!psi.hasBlockBody()) { emptySequence()