[AA] check symbol pointer restoring without psi anchor

^KT-54311
This commit is contained in:
Dmitrii Gridin
2022-10-20 12:01:10 +02:00
committed by Space Team
parent 636024f676
commit 4bd604f2ed
64 changed files with 177 additions and 19 deletions
@@ -1,11 +1,12 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.api.symbols.pointers
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
public class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: SmartPsiElementPointer<out KtElement>) :
public class KtPsiBasedSymbolPointer<S : KtSymbol> private constructor(private val psiPointer: SmartPsiElementPointer<out KtElement>) :
KtSymbolPointer<S>() {
@Deprecated("Consider using org.jetbrains.kotlin.analysis.api.KtAnalysisSession.restoreSymbol")
override fun restoreSymbol(analysisSession: KtAnalysisSession): S? {
@@ -35,7 +36,7 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: Smart
public companion object {
public fun <S : KtSymbol> createForSymbolFromSource(symbol: S): KtPsiBasedSymbolPointer<S>? {
if (symbol.origin != KtSymbolOrigin.SOURCE) return null
if (disablePsiPointer || symbol.origin != KtSymbolOrigin.SOURCE) return null
val psi = when (val psi = symbol.psi) {
is KtDeclaration -> psi
@@ -46,5 +47,25 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol>(private val psiPointer: Smart
return KtPsiBasedSymbolPointer(psi.createSmartPointer())
}
public fun <S : KtSymbol> createForSymbolFromPsi(ktElement: KtElement): KtPsiBasedSymbolPointer<S>? {
if (disablePsiPointer) return null
return KtPsiBasedSymbolPointer(ktElement.createSmartPointer())
}
@TestOnly
@Synchronized
public fun <T> withDisabledPsiBasedPointers(action: () -> T): T {
disablePsiPointer = true
return try {
action()
} finally {
disablePsiPointer = false
}
}
@Volatile
private var disablePsiPointer: Boolean = false
}
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
enum class E {
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
class Foo
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
class Foo
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
class SomeClass1
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// DO_NOT_CHECK_SYMBOL_RESTORE
package test
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// DO_NOT_CHECK_SYMBOL_RESTORE
package test
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
class SomeClass
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
class SomeClass
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
package test
interface ClassA
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
private val _commonSettingsLazy: A = null = ob<caret>ject : A<Int> {
override fun x() {}
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
private val commonSettingsLazy = o<caret>bject A<LanguageVersionSettings> {
println(x)
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
annotation class ReceiverAnnotation
@Target(AnnotationTarget.TYPE)
annotation class ReceiverTypeAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class PropertyAnnotation
annotation class FieldAnnotation
annotation class GetAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class PropertyAnnotation
annotation class GetAnnotation
annotation class ExplicitGetAnnotation
@@ -9,4 +10,4 @@ annotation class ReceiverTypeAnnotation
@property:PropertyAnnotation
@get:GetAnnotation
val @receiver:ReceiverAnnotation @ReceiverTypeAnnotation Long.x: Int
@ExplicitGetAnnotation ge<caret>t() = 1
@ExplicitGetAnnotation ge<caret>t() = 1
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// WITH_STDLIB
annotation class PropertyAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// PRETTY_RENDERING_MODE: RENDER_SYMBOLS_NESTED
annotation class PropertyAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// WITH_STDLIB
annotation class PropertyAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class ReceiverAnnotation
@Target(AnnotationTarget.TYPE)
annotation class ReceiverTypeAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class PropertyAnnotation
annotation class FieldAnnotation
annotation class GetAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
annotation class Anno(val param1: String, val param2: Int)
@Anno(param1 = "param", 2)
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class AnonymousContainer {
val anonymousObject = object : Runnable {
override fun run() {
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
var p: Int
get() = field
set(value) {
@@ -1,2 +1,3 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
class A {
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class A {
val i: Int
init {
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class A {
val a: Int = 10
fun x() = 10
@@ -1,2 +1,3 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
class A(val a: Int, b: String) {
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
class A() {
constructor(x: Int): this()
constructor(y: Int, z: String) : this(y)
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
import org.jetbrains.annotations.NotNull
class A<@NotNull T, R> {
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
context(kotlin.Int, s@kotlin.String)
class A {
constructor(int: Int) {}
@@ -1,2 +1,3 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
context(Int, s@String)
fun y(){}
@@ -1,2 +1,3 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
context(Int, s@String)
val y get() = 10
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// WITH_STDLIB
class MyColor(val x: Int, val y: Int, val z: Int)
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// WITH_STDLIB
@Deprecated("don't use i")
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
data class P(val x: Int, val y: Int)
fun destruct(): Int {
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class Foo {
val p : dynamic = null
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
enum class X {
Y, Z;
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
enum class Style(val value: String) {
SHEET("foo") {
override val exitAnimation: String
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
var p: Int
field = "test"
get() = field.length
@@ -1 +1,2 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
fun String.foo(): Int = 10
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
fun usage() {
for (loopVariable in 1..10) {}
}
@@ -1 +1,2 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
fun foo(x: Int) {}
@@ -1 +1,2 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
fun <X> foo(x: X) {}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class A {
constructor(i: Int)
}
@@ -1 +1,2 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
fun foo(): Int = 10
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
fun foo() {
val lam1 = { a: Int ->
val b = 1
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// WITH_STDLIB
@JvmField
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
// WITH_STDLIB
class Foo {
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
fun yyy() {
val q = 10
fun aaa() {}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
class A {
fun x(): Int
fun y()
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
class A {
val x: Int = 10
val Int.y get() = this
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class X<T> {
inner class Y<T1>
class Z<T2>
@@ -1,2 +1,3 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
fun x(): Int = 10
fun y() {}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
val x: Int = 10
val Int.y get() = this
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
class X<T>
private typealias Y<Z> = X<Z>
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
@Target(AnnotationTarget.TYPE)
annotation class Anno1
@Target(AnnotationTarget.TYPE)
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
inline fun foo(
inlineParameter: () -> Int,
crossinline crossinlineParameter: () -> Int,
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE_K1
fun primitive(vararg a: Int)
fun nullablePrimitive(vararg b: Float?)
fun nonPrimitive(vararg c: Any)
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class PropertyAnnotation
annotation class FieldAnnotation
annotation class GetAnnotation
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
inline fun <T, R> T.use(block: (T) -> R): R {
return block(this)
}
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
// IGNORE_FE10
package test
@@ -1,3 +1,4 @@
// DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE
annotation class ReceiverAnnotation
@Target(AnnotationTarget.TYPE)
annotation class ReceiverTypeAnnotation