[Analysis API] Collect designations only for autonomous declarations

Parameters, type parameters, and property accessors are not
self-sufficient declarations (their resolution depends on resolution
of their parent), so a proper designation path cannot be computed
for them.

Without a designation path, 'ContextCollector' performs analysis of the
whole file, which is inefficient.
This commit is contained in:
Yan Zhulanow
2023-12-20 00:39:05 +09:00
committed by Space Team
parent 4a2f11b2f5
commit bed73fd650
20 changed files with 282 additions and 53 deletions
@@ -14,7 +14,7 @@ Tower Data Context:
Element 6
Scope: FirNestedClassifierScopeWithSubstitution
Classifiers:
FirRegularClassSymbol public final class Nested : R|kotlin/Any|
FirRegularClassSymbol public? final? class Nested : R|kotlin/Any|
Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any|
Element 7
Scope: FirLocalScope
@@ -22,20 +22,20 @@ Tower Data Context:
FirValueParameterSymbol name: R|kotlin/String| = String(name)
FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter_initializerExpression.kt
public open [ResolvedTo(ANNOTATION_ARGUMENTS)] class Base : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base| {
super<R|kotlin/Any|>()
public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|test/Base| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Nested : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base.Nested| {
super<R|kotlin/Any|>()
public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| {
LAZY_super<R|kotlin/Any|>
}
}
public final [ResolvedTo(BODY_RESOLVE)] val fromBase: R|kotlin/String| = String()
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String|
public final [ResolvedTo(STATUS)] val fromBase: R|kotlin/String| = LAZY_EXPRESSION
public [ResolvedTo(STATUS)] get(): R|kotlin/String|
}
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Child : R|test/Base| {
@@ -14,7 +14,7 @@ Tower Data Context:
Element 6
Scope: FirNestedClassifierScopeWithSubstitution
Classifiers:
FirRegularClassSymbol public final class Nested : R|kotlin/Any|
FirRegularClassSymbol public? final? class Nested : R|kotlin/Any|
Static scope owner symbol: FirRegularClassSymbol public open class Base : R|kotlin/Any|
Element 7
Scope: FirLocalScope
@@ -22,14 +22,14 @@ Tower Data Context:
FirValueParameterSymbol name: R|kotlin/String|
FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter_typeRef.kt
public open [ResolvedTo(ANNOTATION_ARGUMENTS)] class Base : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base| {
super<R|kotlin/Any|>()
public open [ResolvedTo(STATUS)] class Base : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|test/Base| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Nested : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Base.Nested| {
super<R|kotlin/Any|>()
public? final? [ResolvedTo(RAW_FIR)] class Nested : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor(): R|test/Base.Nested| {
LAZY_super<R|kotlin/Any|>
}
}
@@ -0,0 +1,4 @@
class Foo {
fun foo(<expr>abc: Int</expr>) {}
fun other() {}
}
@@ -0,0 +1,34 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
Element 7
Scope: FirLocalScope
Properties:
FirValueParameterSymbol abc: R|kotlin/Int|
FILE: [ResolvedTo(IMPORTS)] parameter.kt
public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|Foo| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun foo([ResolvedTo(BODY_RESOLVE)] abc: R|kotlin/Int|): R|kotlin/Unit| {
}
public final [ResolvedTo(STATUS)] fun other(): R|kotlin/Unit| { LAZY_BLOCK }
}
@@ -0,0 +1,4 @@
class Foo<expr>(
val a: String = "foo"
val b: Int = a.length
)</expr>
@@ -0,0 +1,31 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
FILE: [ResolvedTo(IMPORTS)] primaryConstructor.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] a: R|kotlin/String| = String(foo), [ResolvedTo(BODY_RESOLVE)] b: R|kotlin/Int| = R|<local>/a|.R|kotlin/String.length|): R|Foo| {
super<R|kotlin/Any|>()
}
public final [ResolvedTo(STATUS)] val a: R|kotlin/String| = R|<local>/a|
public [ResolvedTo(STATUS)] get(): R|kotlin/String|
public final [ResolvedTo(STATUS)] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(STATUS)] get(): R|kotlin/Int|
}
@@ -1,5 +1,5 @@
class Foo(
val a: String = "foo"
val b: Int = <expr>a.length</expr>,
val c: Long = (a.length - 1).toLong()
a: String = "foo",
b: Int = <expr>a.length</expr>,
c: Long = (a.length - 1).toLong()
)
@@ -12,23 +12,16 @@ Tower Data Context:
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
Scope: FirLocalScope
Properties:
FirValueParameterSymbol a: R|kotlin/String| = String(foo)
FirValueParameterSymbol b: R|kotlin/Int| = R|<local>/a|.R|kotlin/String.length|
FirValueParameterSymbol c: R|kotlin/Long| = R|<local>/a|.R|kotlin/String.length|.R|kotlin/Int.minus|(Int(1)).R|kotlin/Int.toLong|()
FILE: [ResolvedTo(IMPORTS)] primaryConstructorParameter.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(ANNOTATION_ARGUMENTS)] constructor([ResolvedTo(ANNOTATION_ARGUMENTS)] a: R|kotlin/String| = LAZY_EXPRESSION, [ResolvedTo(ANNOTATION_ARGUMENTS)] b: R|kotlin/Int| = LAZY_EXPRESSION, [ResolvedTo(ANNOTATION_ARGUMENTS)] c: R|kotlin/Long| = LAZY_EXPRESSION): R|Foo| {
LAZY_super<R|kotlin/Any|>
public [ResolvedTo(BODY_RESOLVE)] constructor([ResolvedTo(BODY_RESOLVE)] a: R|kotlin/String| = String(foo), [ResolvedTo(BODY_RESOLVE)] b: R|kotlin/Int| = R|<local>/a|.R|kotlin/String.length|, [ResolvedTo(BODY_RESOLVE)] c: R|kotlin/Long| = R|<local>/a|.R|kotlin/String.length|.R|kotlin/Int.minus|(Int(1)).R|kotlin/Int.toLong|()): R|Foo| {
super<R|kotlin/Any|>()
}
public final [ResolvedTo(STATUS)] val a: R|kotlin/String| = R|<local>/a|
public [ResolvedTo(STATUS)] get(): R|kotlin/String|
public final [ResolvedTo(BODY_RESOLVE)] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] val c: R|kotlin/Long| = R|<local>/c|
public [ResolvedTo(STATUS)] get(): R|kotlin/Long|
}
@@ -0,0 +1,5 @@
class Foo(
val a: String = "foo"
val b: Int = <expr>a.length</expr>,
val c: Long = (a.length - 1).toLong()
)
@@ -0,0 +1,34 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
FILE: [ResolvedTo(IMPORTS)] primaryConstructorProperty.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(ANNOTATION_ARGUMENTS)] constructor([ResolvedTo(ANNOTATION_ARGUMENTS)] a: R|kotlin/String| = LAZY_EXPRESSION, [ResolvedTo(ANNOTATION_ARGUMENTS)] b: R|kotlin/Int| = LAZY_EXPRESSION, [ResolvedTo(ANNOTATION_ARGUMENTS)] c: R|kotlin/Long| = LAZY_EXPRESSION): R|Foo| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(STATUS)] val a: R|kotlin/String| = R|<local>/a|
public [ResolvedTo(STATUS)] get(): R|kotlin/String|
public final [ResolvedTo(BODY_RESOLVE)] val b: R|kotlin/Int| = R|<local>/b|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int|
public final [ResolvedTo(STATUS)] val c: R|kotlin/Long| = R|<local>/c|
public [ResolvedTo(STATUS)] get(): R|kotlin/Long|
}
@@ -0,0 +1,4 @@
class Foo {
val x: Int
<expr>get() = 42</expr>
}
@@ -0,0 +1,34 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
Element 7
Scope: FirLocalScope
Properties:
FirBackingFieldSymbol private <explicit backing field>: R|kotlin/Int|
FILE: [ResolvedTo(IMPORTS)] propertyAccessor.kt
public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|Foo| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] val x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| {
^ Int(42)
}
}
@@ -0,0 +1,4 @@
class Foo {
fun <<expr>T</expr>> foo(obj: T) {}
fun other() {}
}
@@ -0,0 +1,34 @@
Tower Data Context:
Element 0
Scope: FirDefaultStarImportingScope
Element 1
Scope: FirExplicitStarImportingScope
Element 2
Scope: FirDefaultSimpleImportingScope
Element 3
Scope: FirDefaultSimpleImportingScope
Element 4
Scope: FirPackageMemberScope
Element 5
Scope: FirExplicitSimpleImportingScope
Element 6
Implicit receiver:
FirRegularClassSymbol public final class Foo : R|kotlin/Any|
Type: Foo
Element 7
Scope: FirMemberTypeParameterScope
Classifiers:
FirTypeParameterSymbol T
FILE: [ResolvedTo(IMPORTS)] typeParameter.kt
public final [ResolvedTo(STATUS)] class Foo : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|Foo| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun <[ResolvedTo(BODY_RESOLVE)] T> foo([ResolvedTo(BODY_RESOLVE)] obj: R|T|): R|kotlin/Unit| {
}
public final [ResolvedTo(STATUS)] fun other(): R|kotlin/Unit| { LAZY_BLOCK }
}
@@ -29,12 +29,12 @@ Tower Data Context:
FirTypeParameterSymbol T : R|MyParam|
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromInner_typeBound.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Outer<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam>(): R|test/Outer<MyParam>| {
super<R|kotlin/Any|>()
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer<MyParam>| {
LAZY_super<R|kotlin/Any|>
}
public final inner [ResolvedTo(ANNOTATION_ARGUMENTS)] class Inner<[ResolvedTo(ANNOTATION_ARGUMENTS)] T : R|MyParam|, [ResolvedTo(ANNOTATION_ARGUMENTS)] Outer(MyParam)> : R|kotlin/Any| {
public final inner [ResolvedTo(ANNOTATION_ARGUMENTS)] class Inner<[ResolvedTo(ANNOTATION_ARGUMENTS)] T : R|MyParam|, [ResolvedTo(STATUS)] Outer(MyParam)> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] test/Outer<MyParam>.constructor<[ResolvedTo(ANNOTATION_ARGUMENTS)] T : R|MyParam|>(): R|test/Outer.Inner<T, MyParam>| {
super<R|kotlin/Any|>()
}
@@ -35,14 +35,14 @@ Tower Data Context:
FirValueParameterSymbol p: R|MyParam|
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromInner_typeRefInMember.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Outer<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam>(): R|test/Outer<MyParam>| {
super<R|kotlin/Any|>()
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer<MyParam>| {
LAZY_super<R|kotlin/Any|>
}
public final inner [ResolvedTo(ANNOTATION_ARGUMENTS)] class Inner<[ResolvedTo(ANNOTATION_ARGUMENTS)] Outer(MyParam)> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] test/Outer<MyParam>.constructor(): R|test/Outer.Inner<MyParam>| {
super<R|kotlin/Any|>()
public final inner [ResolvedTo(STATUS)] class Inner<[ResolvedTo(STATUS)] Outer(MyParam)> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] test/Outer<MyParam>.constructor(): R|test/Outer.Inner<MyParam>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun member([ResolvedTo(BODY_RESOLVE)] p: R|MyParam|): R|kotlin/Unit| {
@@ -29,9 +29,9 @@ Tower Data Context:
FirTypeParameterSymbol T : <ERROR TYPE REF: Symbol not found for MyParam>
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeBound.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Outer<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam>(): R|test/Outer<MyParam>| {
super<R|kotlin/Any|>()
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer<MyParam>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Nested<[ResolvedTo(ANNOTATION_ARGUMENTS)] T : <ERROR TYPE REF: Symbol not found for MyParam>> : R|kotlin/Any| {
@@ -25,14 +25,14 @@ Tower Data Context:
FirValueParameterSymbol p: <ERROR TYPE REF: Symbol not found for MyParam>
FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeRefInMember.kt
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Outer<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(ANNOTATION_ARGUMENTS)] MyParam>(): R|test/Outer<MyParam>| {
super<R|kotlin/Any|>()
public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer<MyParam>| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] class Nested : R|kotlin/Any| {
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Outer.Nested| {
super<R|kotlin/Any|>()
public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| {
public [ResolvedTo(STATUS)] constructor(): R|test/Outer.Nested| {
LAZY_super<R|kotlin/Any|>
}
public final [ResolvedTo(BODY_RESOLVE)] fun member([ResolvedTo(BODY_RESOLVE)] p: <ERROR TYPE REF: Symbol not found for MyParam>): R|kotlin/Unit| {