15
15
* limitations under the License.
16
16
*/
17
17
18
+ @file:Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
19
+
18
20
package com.google.devtools.ksp.impl.symbol.kotlin
19
21
20
22
import com.google.devtools.ksp.closestClassDeclaration
@@ -27,15 +29,19 @@ import com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSTypeReferenceResolv
27
29
import com.google.devtools.ksp.impl.symbol.util.BinaryClassInfoCache
28
30
import com.google.devtools.ksp.symbol.*
29
31
import com.intellij.psi.PsiClass
32
+ import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
30
33
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
31
34
import org.jetbrains.kotlin.analysis.api.annotations.annotations
35
+ import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirKotlinPropertySymbol
32
36
import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
33
37
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
34
38
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
35
39
import org.jetbrains.kotlin.descriptors.Modality
36
40
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
37
41
import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
38
42
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
43
+ import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
44
+ import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
39
45
import org.jetbrains.kotlin.psi.KtProperty
40
46
41
47
class KSPropertyDeclarationImpl private constructor(internal val ktPropertySymbol : KtPropertySymbol ) :
@@ -107,13 +113,29 @@ class KSPropertyDeclarationImpl private constructor(internal val ktPropertySymbo
107
113
108
114
override val hasBackingField: Boolean by lazy {
109
115
if (origin == Origin .KOTLIN_LIB || origin == Origin .JAVA_LIB ) {
110
- val fileManager = ResolverAAImpl .instance.javaFileManager
111
- val parentClass = this .findParentOfType<KSClassDeclaration >()
112
- val classId = (parentClass as KSClassDeclarationImpl ).ktClassOrObjectSymbol.classIdIfNonLocal!!
113
- val virtualFileContent = analyze {
114
- (fileManager.findClass(classId, analysisScope) as JavaClassImpl ).virtualFile!! .contentsToByteArray()
116
+ when {
117
+ ktPropertySymbol.receiverParameter != null -> false
118
+ ktPropertySymbol.initializer is KtConstantInitializerValue -> true
119
+ (ktPropertySymbol as ? KtKotlinPropertySymbol )?.isLateInit == true -> true
120
+ ktPropertySymbol.modality == Modality .ABSTRACT -> false
121
+ else -> {
122
+ val classId = when (
123
+ val containerSource =
124
+ (ktPropertySymbol as ? KtFirKotlinPropertySymbol )?.firSymbol?.containerSource
125
+ ) {
126
+ is JvmPackagePartSource -> containerSource.classId
127
+ is KotlinJvmBinarySourceElement -> containerSource.binaryClass.classId
128
+ else -> null
129
+ } ? : return @lazy ktPropertySymbol.hasBackingField
130
+ val fileManager = ResolverAAImpl .instance.javaFileManager
131
+ val virtualFileContent = analyze {
132
+ (fileManager.findClass(classId, analysisScope) as JavaClassImpl )
133
+ .virtualFile!! .contentsToByteArray()
134
+ }
135
+ BinaryClassInfoCache .getCached(classId, virtualFileContent)
136
+ .fieldAccFlags.containsKey(simpleName.asString())
137
+ }
115
138
}
116
- BinaryClassInfoCache .getCached(classId, virtualFileContent).fieldAccFlags.containsKey(simpleName.asString())
117
139
} else {
118
140
ktPropertySymbol.hasBackingField
119
141
}
0 commit comments