[Analysis API] rework containing declaration provider
now it should work for non-source declarations
This commit is contained in:
+3
-2
@@ -6,12 +6,13 @@
|
||||
package org.jetbrains.kotlin.analysis.api.components
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtDeclarationSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithKind
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
|
||||
public abstract class KtSymbolContainingDeclarationProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun getContainingDeclaration(symbol: KtSymbol): KtSymbolWithKind?
|
||||
public abstract fun getContainingDeclaration(symbol: KtSymbol): KtDeclarationSymbol?
|
||||
|
||||
public abstract fun getContainingModule(symbol: KtSymbol): KtModule
|
||||
}
|
||||
@@ -23,7 +24,7 @@ public interface KtSymbolContainingDeclarationProviderMixIn : KtAnalysisSessionM
|
||||
* for class members returns containing class
|
||||
* for local declaration returns declaration it was declared it
|
||||
*/
|
||||
public fun KtSymbol.getContainingSymbol(): KtSymbolWithKind? =
|
||||
public fun KtSymbol.getContainingSymbol(): KtDeclarationSymbol? =
|
||||
withValidityAssertion { analysisSession.containingDeclarationProvider.getContainingDeclaration(this) }
|
||||
|
||||
public fun KtSymbol.getContainingModule(): KtModule =
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
||||
public open fun getSymbol(psi: KtDeclaration): KtSymbol = when (psi) {
|
||||
public open fun getSymbol(psi: KtDeclaration): KtDeclarationSymbol = when (psi) {
|
||||
is KtParameter -> getParameterSymbol(psi)
|
||||
is KtNamedFunction -> getFunctionLikeSymbol(psi)
|
||||
is KtConstructor<*> -> getConstructorSymbol(psi)
|
||||
@@ -62,7 +62,7 @@ public abstract class KtSymbolProvider : KtAnalysisSessionComponent() {
|
||||
}
|
||||
|
||||
public interface KtSymbolProviderMixIn : KtAnalysisSessionMixIn {
|
||||
public fun KtDeclaration.getSymbol(): KtSymbol =
|
||||
public fun KtDeclaration.getSymbol(): KtDeclarationSymbol =
|
||||
withValidityAssertion { analysisSession.symbolProvider.getSymbol(this) }
|
||||
|
||||
/**
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
class A {
|
||||
class B {
|
||||
class C {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface D {
|
||||
inner class E {
|
||||
enum class F {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class G {
|
||||
H, I
|
||||
}
|
||||
|
||||
|
||||
fun foo() {
|
||||
class D {
|
||||
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
class X {
|
||||
fun foo() {
|
||||
class U {
|
||||
inner class K {
|
||||
inner class D {
|
||||
fun check() {
|
||||
class F {
|
||||
inner class L
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class T
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
enum class A {
|
||||
B, C;
|
||||
fun d(){}
|
||||
val e: Int = 10
|
||||
}
|
||||
|
||||
class X {
|
||||
private Y {
|
||||
enum class U {
|
||||
UB, UC;
|
||||
fun ud(){}
|
||||
val ue: Int = 10
|
||||
}
|
||||
}
|
||||
|
||||
class P {
|
||||
enum class W {
|
||||
WB, WC;
|
||||
fun wd(){}
|
||||
val we: Int = 10
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
fun a(){}
|
||||
private fun b() {}
|
||||
|
||||
class A {
|
||||
private fun a() {}
|
||||
|
||||
class B {
|
||||
private fun b() {}
|
||||
|
||||
class C {
|
||||
private fun c() {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface D {
|
||||
private fun d() {}
|
||||
inner class E {
|
||||
private fun e() {}
|
||||
enum class F {
|
||||
private fun f() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class G {
|
||||
H, I;
|
||||
|
||||
private fun g() {}
|
||||
}
|
||||
|
||||
|
||||
fun foo() {
|
||||
private fun fooA() {}
|
||||
|
||||
class FooI {
|
||||
private fun m() {}
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
fun x() {
|
||||
val xProperty = 10
|
||||
fun xFunction() = 11
|
||||
typealias xTypealias = 10
|
||||
class XClass<XT> {}
|
||||
enum class XEnum {
|
||||
X_ENUM_ENTRY;
|
||||
|
||||
fun xEnumMember(){}
|
||||
}
|
||||
|
||||
class Y <YT> {
|
||||
val yProperty = 10
|
||||
fun yFunction() = 11
|
||||
typealias yTypealias = 10
|
||||
class YClass<YTT> {}
|
||||
enum class YEnum {
|
||||
Y_ENUM_ENTRY;
|
||||
|
||||
fun yEnumMember(){}
|
||||
|
||||
}
|
||||
init {
|
||||
println("init block in local class")
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
typealias X<XT> = List<X>
|
||||
class A {
|
||||
typealias Y<YS, YV> = Map<YS, YV>
|
||||
|
||||
class B {
|
||||
typealias Q<QS, QV> = MutableMap<QS, QV>
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
typealias L<LS, LV> = Map<LS, LV>
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
interface A {
|
||||
fun <T>foo()
|
||||
}
|
||||
|
||||
interface B {
|
||||
fun <T>foo() {}
|
||||
}
|
||||
|
||||
>class Y<caret> : A, B
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun <T> foo() fromClass Y
|
||||
T from /Y.foo
|
||||
|
||||
fun equals(other: Any?): Boolean fromClass kotlin/Any
|
||||
|
||||
fun hashCode(): Int fromClass kotlin/Any
|
||||
|
||||
fun toString(): String fromClass kotlin/Any
|
||||
|
||||
constructor() fromClass Y
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
abstract class X<T> {
|
||||
fun <S> foo1(t: T): T = t
|
||||
fun <Q> foo2(t: T) {}
|
||||
fun <U> foo3() {}
|
||||
}
|
||||
|
||||
class Y<caret> : X<Int> {}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
fun <S> foo1(t: Int): Int fromClass Y
|
||||
S from /Y.foo1
|
||||
|
||||
fun <Q> foo2(t: Int) fromClass Y
|
||||
Q from /Y.foo2
|
||||
|
||||
fun <U> foo3() fromClass X
|
||||
U from /X.foo3
|
||||
|
||||
fun equals(other: Any?): Boolean fromClass kotlin/Any
|
||||
|
||||
fun hashCode(): Int fromClass kotlin/Any
|
||||
|
||||
fun toString(): String fromClass kotlin/Any
|
||||
|
||||
constructor() fromClass Y
|
||||
Reference in New Issue
Block a user