Skip to content

Commit

Permalink
Revert "Fix compilation"
Browse files Browse the repository at this point in the history
This reverts commit 981fb70.
  • Loading branch information
ting-yuan committed Oct 25, 2023
1 parent 3c7111f commit 145eb96
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,6 @@ 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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,6 @@ class ResolverImpl(
if (declaration.isAbstract)
modifiers.add(Modifier.ABSTRACT)
}
is KSTypeAlias, is KSTypeParameter -> Unit
}
}
Origin.KOTLIN_LIB, Origin.JAVA_LIB -> {
Expand All @@ -1209,7 +1208,6 @@ class ResolverImpl(
if (declaration.jvmAccessFlag and Opcodes.ACC_SYNCHRONIZED != 0)
modifiers.add(Modifier.JAVA_SYNCHRONIZED)
}
is KSClassDeclaration, is KSTypeAlias, is KSTypeParameter -> Unit
}
}
else -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ 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 {

open /*override*/ val origin by lazy {
override val origin by lazy {
descriptor.origin
}

open /*override*/ val containingFile: KSFile? = null
override val containingFile: KSFile? = null

open /*override*/ val location: Location = NonExistLocation
override val location: Location = NonExistLocation

open /*override*/ val annotations: Sequence<KSAnnotation> by lazy {
descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this as KSDeclaration) }
.memoized()
override val annotations: Sequence<KSAnnotation> by lazy {
descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this) }.memoized()
}

open /*override*/ val parentDeclaration: KSDeclaration? by lazy {
override val parentDeclaration: KSDeclaration? by lazy {
val containingDescriptor = descriptor.parents.first()
when (containingDescriptor) {
is ClassDescriptor -> KSClassDeclarationDescriptorImpl.getCached(containingDescriptor)
Expand All @@ -54,27 +53,27 @@ abstract class KSDeclarationDescriptorImpl(private val descriptor: DeclarationDe
} as KSDeclaration?
}

open /*override*/ val parent: KSNode? by lazy {
override val parent: KSNode? by lazy {
parentDeclaration
}

open /*override*/ val packageName: KSName by lazy {
override val packageName: KSName by lazy {
KSNameImpl.getCached(descriptor.findPackage().fqName.asString())
}

open /*override*/ val qualifiedName: KSName by lazy {
override val qualifiedName: KSName by lazy {
KSNameImpl.getCached(descriptor.fqNameSafe.asString())
}

open /*override*/ val simpleName: KSName by lazy {
override val simpleName: KSName by lazy {
KSNameImpl.getCached(descriptor.name.asString())
}

override fun toString(): String {
return this.simpleName.asString()
}

open /*override*/ val docString: String? = null
override val docString = null
}

val DeclarationDescriptor.origin: Origin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*/ {
open /*override*/ val origin: Origin by lazy {
abstract class KSPropertyAccessorDescriptorImpl(val descriptor: PropertyAccessorDescriptor) : KSPropertyAccessor {
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
Expand All @@ -35,27 +35,26 @@ abstract class KSPropertyAccessorDescriptorImpl(val descriptor: PropertyAccessor
}
}

open /*override*/ val receiver: KSPropertyDeclaration by lazy {
override val receiver: KSPropertyDeclaration by lazy {
descriptor.correspondingProperty.toKSPropertyDeclaration()
}

open /*override*/ val parent: KSNode? by lazy {
override val parent: KSNode? by lazy {
receiver
}

open /*override*/ val location: Location
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
}

open /*override*/ val annotations: Sequence<KSAnnotation> by lazy {
descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this as KSPropertyAccessor) }
.memoized()
override val annotations: Sequence<KSAnnotation> by lazy {
descriptor.annotations.asSequence().map { KSAnnotationDescriptorImpl.getCached(it, this) }.memoized()
}

open /*override*/ val modifiers: Set<Modifier> by lazy {
override val modifiers: Set<Modifier> by lazy {
val modifiers = mutableSetOf<Modifier>()
modifiers.addAll(descriptor.toKSModifiers())
modifiers.addAll(descriptor.toFunctionKSModifiers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*/ {
open /*override*/ val packageName: KSName by lazy {
(this as KSDeclaration).containingFile!!.packageName
abstract class KSDeclarationJavaImpl(private val psi: PsiElement) : KSDeclaration {
override val packageName: KSName by lazy {
this.containingFile!!.packageName
}

override fun toString(): String {
return (this as KSDeclaration).simpleName.asString()
return this.simpleName.asString()
}

open /*override*/ val docString by lazy {
override val docString by lazy {
psi.getDocString()
}

open /*override*/ val parentDeclaration: KSDeclaration? by lazy {
override val parentDeclaration: KSDeclaration? by lazy {
psi.findParentDeclaration()
}

open /*override*/ val parent: KSNode? by lazy {
override val parent: KSNode? by lazy {
psi.findParentAnnotated()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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*/ {
open /*override*/ val origin: Origin = Origin.KOTLIN
abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) : KSDeclaration {
override val origin: Origin = Origin.KOTLIN

open /*override*/ val location: Location by lazy {
override val location: Location by lazy {
ktDeclaration.toLocation()
}

open /*override*/ val simpleName: KSName by lazy {
override val simpleName: KSName by lazy {
KSNameImpl.getCached(ktDeclaration.name!!)
}

open /*override*/ val qualifiedName: KSName? by lazy {
override val qualifiedName: KSName? by lazy {
(ktDeclaration as? KtNamedDeclaration)?.fqName?.let { KSNameImpl.getCached(it.asString()) }
}

open /*override*/ val annotations: Sequence<KSAnnotation> by lazy {
override val annotations: Sequence<KSAnnotation> by lazy {
ktDeclaration.annotationEntries.asSequence().map { KSAnnotationImpl.getCached(it) }.memoized()
}

open /*override*/ val modifiers: Set<Modifier> by lazy {
override val modifiers: Set<Modifier> 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
Expand All @@ -56,25 +56,25 @@ abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) /*: KSDeclara
}
}

open /*override*/ val containingFile: KSFile? by lazy {
override val containingFile: KSFile? by lazy {
KSFileImpl.getCached(ktDeclaration.containingKtFile)
}

open /*override*/ val packageName: KSName by lazy {
override val packageName: KSName by lazy {
this.containingFile!!.packageName
}

open /*override*/ val typeParameters: List<KSTypeParameter> by lazy {
override val typeParameters: List<KSTypeParameter> by lazy {
(ktDeclaration as? KtTypeParameterListOwner)?.let {
it.typeParameters.map { KSTypeParameterImpl.getCached(it) }
} ?: emptyList()
}

open /*override*/ val parentDeclaration: KSDeclaration? by lazy {
override val parentDeclaration: KSDeclaration? by lazy {
ktDeclaration.findParentDeclaration()
}

open /*override*/ val parent: KSNode? by lazy {
override val parent: KSNode? by lazy {
ktDeclaration.findParentAnnotated()
}

Expand All @@ -86,7 +86,7 @@ abstract class KSDeclarationImpl(val ktDeclaration: KtDeclaration) /*: KSDeclara
ktDeclaration.annotationEntries.map { KSAnnotationImpl.getCached(it) }
}

open /*override*/ val docString by lazy {
override val docString by lazy {
ktDeclaration.getDocString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,27 +36,27 @@ abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor
}
}
}
open /*override*/ val receiver: KSPropertyDeclaration by lazy {
override val receiver: KSPropertyDeclaration by lazy {
KSPropertyDeclarationImpl.getCached(ktPropertyAccessor.property as KtProperty)
}
open /*override*/ val annotations: Sequence<KSAnnotation> by lazy {
override val annotations: Sequence<KSAnnotation> by lazy {
ktPropertyAccessor.filterUseSiteTargetAnnotations().map { KSAnnotationImpl.getCached(it) }
.plus((this as KSPropertyAccessor).findAnnotationFromUseSiteTarget())
.plus(this.findAnnotationFromUseSiteTarget())
}

open /*override*/ val parent: KSNode? by lazy {
override val parent: KSNode? by lazy {
receiver
}

open /*override*/ val location: Location by lazy {
override val location: Location by lazy {
ktPropertyAccessor.toLocation()
}

open /*override*/ val modifiers: Set<Modifier> by lazy {
override val modifiers: Set<Modifier> by lazy {
ktPropertyAccessor.toKSModifiers()
}

open /*override*/ val declarations: Sequence<KSDeclaration> by lazy {
override val declarations: Sequence<KSDeclaration> by lazy {
if (!ktPropertyAccessor.hasBlockBody()) {
emptySequence()
} else {
Expand All @@ -65,10 +65,10 @@ abstract class KSPropertyAccessorImpl(val ktPropertyAccessor: KtPropertyAccessor
}
}

open /*override*/ val origin: Origin = Origin.KOTLIN
override val origin: Origin = Origin.KOTLIN

open /*override*/ fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
return visitor.visitPropertyAccessor(this as KSPropertyAccessor, data)
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
return visitor.visitPropertyAccessor(this, data)
}

internal val originalAnnotations: List<KSAnnotation> by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import com.google.devtools.ksp.processing.impl.ResolverImpl
import com.google.devtools.ksp.symbol.*

class KSConstructorSyntheticImpl private constructor(val ksClassDeclaration: KSClassDeclaration) :
KSFunctionDeclaration {
KSFunctionDeclaration,
KSDeclaration
by ksClassDeclaration {
companion object : KSObjectCache<KSClassDeclaration, KSConstructorSyntheticImpl>() {
fun getCached(ksClassDeclaration: KSClassDeclaration) =
KSConstructorSyntheticImpl.cache.getOrPut(ksClassDeclaration) {
Expand All @@ -41,10 +43,6 @@ 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(".<init>") ?: "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*/ {
open /*override*/ val annotations: Sequence<KSAnnotation> by lazy {
(this as KSPropertyAccessor).findAnnotationFromUseSiteTarget()
abstract class KSPropertyAccessorSyntheticImpl(ksPropertyDeclaration: KSPropertyDeclaration) : KSPropertyAccessor {
override val annotations: Sequence<KSAnnotation> by lazy {
this.findAnnotationFromUseSiteTarget()
}

open /*override*/ val location: Location by lazy {
override val location: Location by lazy {
ksPropertyDeclaration.location
}

open /*override*/ val modifiers: Set<Modifier> = emptySet()
override val modifiers: Set<Modifier> = emptySet()

open /*override*/ val origin: Origin = Origin.SYNTHETIC
override val origin: Origin = Origin.SYNTHETIC

open /*override*/ val receiver: KSPropertyDeclaration = ksPropertyDeclaration
override val receiver: KSPropertyDeclaration = ksPropertyDeclaration

open /*override*/ fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
return visitor.visitPropertyAccessor(this as KSPropertyAccessor, data)
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
return visitor.visitPropertyAccessor(this, data)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ internal class DeclarationOrdering(
}

private fun getOrder(decl: KSDeclarationDescriptorImpl): Int {
return declOrdering.getOrPut(decl as KSDeclaration) {
return declOrdering.getOrPut(decl) {
when (decl) {
is KSPropertyDeclarationDescriptorImpl -> {
fieldOrdering[decl.simpleName.asString()]?.let {
Expand Down Expand Up @@ -467,8 +467,7 @@ internal val KSDeclarationContainer.declarationsInSourceOrder: Sequence<KSDeclar
DeclarationOrdering(it)
} ?: return declarations

return (declarations as? Sequence<KSDeclarationDescriptorImpl>)
?.sortedWith(declarationOrdering.comparator) as Sequence<KSDeclaration>?
return (declarations as? Sequence<KSDeclarationDescriptorImpl>)?.sortedWith(declarationOrdering.comparator)
?: declarations
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ class ResolverAAImpl(
if (declaration.isAbstract)
modifiers.add(Modifier.ABSTRACT)
}
is KSTypeAlias, is KSTypeParameter -> Unit
}
}
Origin.KOTLIN_LIB, Origin.JAVA_LIB -> {
Expand All @@ -190,7 +189,6 @@ class ResolverAAImpl(
if (declaration.jvmAccessFlag and Opcodes.ACC_SYNCHRONIZED != 0)
modifiers.add(Modifier.JAVA_SYNCHRONIZED)
}
is KSClassDeclaration, is KSTypeAlias, is KSTypeParameter -> Unit
}
}
else -> Unit
Expand Down
Loading

0 comments on commit 145eb96

Please sign in to comment.