KTIJ-26024 [Analysis API] Add more tests for nested cases of reference shortening in class header

Account for `FirNestedClassifierScopeWithSubstitution` in the reference
shortener
This commit is contained in:
Roman Golyshev
2023-06-28 17:16:42 +02:00
committed by Space Team
parent 4adda42206
commit ab149e1053
25 changed files with 330 additions and 1 deletions
@@ -470,13 +470,19 @@ private class ElementsToShortenCollector(
private fun FirScope.correspondingClassIdIfExists(): ClassId = when (this) {
is FirNestedClassifierScope -> klass.classId
is FirNestedClassifierScopeWithSubstitution -> originalScope.correspondingClassIdIfExists()
is FirClassUseSiteMemberScope -> classId
else -> error("FirScope `$this` is expected to be one of FirNestedClassifierScope and FirClassUseSiteMemberScope to get ClassId")
}
private fun ClassId.idWithoutCompanion() = if (shortClassName == SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT) outerClassId else this
private fun FirScope.isScopeForClass() = this is FirNestedClassifierScope || this is FirClassUseSiteMemberScope
private fun FirScope.isScopeForClass(): Boolean = when {
this is FirNestedClassifierScope -> true
this is FirNestedClassifierScopeWithSubstitution -> originalScope.isScopeForClass()
this is FirClassUseSiteMemberScope -> true
else -> false
}
/**
* Assuming that both this [FirScope] and [another] are [FirNestedClassifierScope] or [FirClassUseSiteMemberScope] and both of them
@@ -569,6 +575,7 @@ private class ElementsToShortenCollector(
is FirLocalScope -> Local
is FirClassUseSiteMemberScope -> ClassUseSite
is FirNestedClassifierScope -> NestedClassifier
is FirNestedClassifierScopeWithSubstitution -> originalScope.toPartialOrder()
is FirExplicitSimpleImportingScope -> ExplicitSimpleImporting
is FirPackageMemberScope -> PackageMember
else -> Unclassified
@@ -466,30 +466,60 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnClass.kt");
}
@Test
@TestMetadata("annotationOnClass_nested.kt")
public void testAnnotationOnClass_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnClass_nested.kt");
}
@Test
@TestMetadata("annotationOnConstructor.kt")
public void testAnnotationOnConstructor() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnConstructor.kt");
}
@Test
@TestMetadata("annotationOnConstructor_nested.kt")
public void testAnnotationOnConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnConstructor_nested.kt");
}
@Test
@TestMetadata("annotationOnParameter.kt")
public void testAnnotationOnParameter() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnParameter.kt");
}
@Test
@TestMetadata("annotationOnParameter_nested.kt")
public void testAnnotationOnParameter_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnParameter_nested.kt");
}
@Test
@TestMetadata("contextReceiver.kt")
public void testContextReceiver() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/contextReceiver.kt");
}
@Test
@TestMetadata("contextReceiver_nested.kt")
public void testContextReceiver_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/contextReceiver_nested.kt");
}
@Test
@TestMetadata("primaryConstructorParameter.kt")
public void testPrimaryConstructorParameter() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/primaryConstructorParameter.kt");
}
@Test
@TestMetadata("primaryConstructorParameter_nested.kt")
public void testPrimaryConstructorParameter_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/primaryConstructorParameter_nested.kt");
}
@Test
@TestMetadata("superType.kt")
public void testSuperType() throws Exception {
@@ -508,23 +538,59 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_nested.kt")
public void testSuperTypeConstructorArgument_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested.kt")
public void testSuperTypeConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeDelegation.kt");
}
@Test
@TestMetadata("superTypeDelegation_nested.kt")
public void testSuperTypeDelegation_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeDelegation_nested.kt");
}
@Test
@TestMetadata("superTypeTypeArguments.kt")
public void testSuperTypeTypeArguments() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeTypeArguments.kt");
}
@Test
@TestMetadata("superTypeTypeArguments_nested.kt")
public void testSuperTypeTypeArguments_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeTypeArguments_nested.kt");
}
@Test
@TestMetadata("superType_nested.kt")
public void testSuperType_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superType_nested.kt");
}
@Test
@TestMetadata("typeBound.kt")
public void testTypeBound() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/typeBound.kt");
}
@Test
@TestMetadata("typeBound_nested.kt")
public void testTypeBound_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/typeBound_nested.kt");
}
}
}
}
@@ -466,30 +466,60 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnClass.kt");
}
@Test
@TestMetadata("annotationOnClass_nested.kt")
public void testAnnotationOnClass_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnClass_nested.kt");
}
@Test
@TestMetadata("annotationOnConstructor.kt")
public void testAnnotationOnConstructor() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnConstructor.kt");
}
@Test
@TestMetadata("annotationOnConstructor_nested.kt")
public void testAnnotationOnConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnConstructor_nested.kt");
}
@Test
@TestMetadata("annotationOnParameter.kt")
public void testAnnotationOnParameter() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnParameter.kt");
}
@Test
@TestMetadata("annotationOnParameter_nested.kt")
public void testAnnotationOnParameter_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/annotationOnParameter_nested.kt");
}
@Test
@TestMetadata("contextReceiver.kt")
public void testContextReceiver() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/contextReceiver.kt");
}
@Test
@TestMetadata("contextReceiver_nested.kt")
public void testContextReceiver_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/contextReceiver_nested.kt");
}
@Test
@TestMetadata("primaryConstructorParameter.kt")
public void testPrimaryConstructorParameter() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/primaryConstructorParameter.kt");
}
@Test
@TestMetadata("primaryConstructorParameter_nested.kt")
public void testPrimaryConstructorParameter_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/primaryConstructorParameter_nested.kt");
}
@Test
@TestMetadata("superType.kt")
public void testSuperType() throws Exception {
@@ -508,23 +538,59 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument.kt");
}
@Test
@TestMetadata("superTypeConstructorArgument_nested.kt")
public void testSuperTypeConstructorArgument_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructorArgument_nested.kt");
}
@Test
@TestMetadata("superTypeConstructor_nested.kt")
public void testSuperTypeConstructor_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeConstructor_nested.kt");
}
@Test
@TestMetadata("superTypeDelegation.kt")
public void testSuperTypeDelegation() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeDelegation.kt");
}
@Test
@TestMetadata("superTypeDelegation_nested.kt")
public void testSuperTypeDelegation_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeDelegation_nested.kt");
}
@Test
@TestMetadata("superTypeTypeArguments.kt")
public void testSuperTypeTypeArguments() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeTypeArguments.kt");
}
@Test
@TestMetadata("superTypeTypeArguments_nested.kt")
public void testSuperTypeTypeArguments_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superTypeTypeArguments_nested.kt");
}
@Test
@TestMetadata("superType_nested.kt")
public void testSuperType_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/superType_nested.kt");
}
@Test
@TestMetadata("typeBound.kt")
public void testTypeBound() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/typeBound.kt");
}
@Test
@TestMetadata("typeBound_nested.kt")
public void testTypeBound_nested() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/nestedClasses/classHeaderPositions/typeBound_nested.kt");
}
}
}
}
@@ -0,0 +1,11 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
annotation class Ann
<expr>@Outer.Ann</expr>
class Foo : Outer()
}
@@ -0,0 +1,8 @@
Before shortening: @Outer.Ann
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Ann
with SHORTEN_AND_IMPORT:
[type] Outer.Ann
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Ann
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
annotation class Ann
class Foo <expr>@Outer.Ann</expr> constructor() : Outer()
}
@@ -0,0 +1,8 @@
Before shortening: @Outer.Ann
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Ann
with SHORTEN_AND_IMPORT:
[type] Outer.Ann
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Ann
@@ -0,0 +1,8 @@
// FILE: main.kt
abstract class Outer {
annotation class Ann
class Foo(<expr>@Outer.Ann</expr> val p: Any) : Outer()
}
@@ -0,0 +1,8 @@
Before shortening: @Outer.Ann
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Ann
with SHORTEN_AND_IMPORT:
[type] Outer.Ann
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Ann
@@ -0,0 +1,9 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
context(<expr>Outer.Nested</expr>)
class Foo : Outer.Nested()
}
@@ -0,0 +1,8 @@
Before shortening: Outer.Nested
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
class Foo(<expr>val param: Outer.Nested = Outer.Nested()</expr>) : Outer.Nested()
}
@@ -0,0 +1,11 @@
Before shortening: val param: Outer.Nested = Outer.Nested()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
[qualifier] Outer.Nested()
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
[qualifier] Outer.Nested()
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
[qualifier] Outer.Nested()
@@ -0,0 +1,10 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested(a: Any) : Outer()
class OtherNested
class Foo : Outer.Nested(<expr>Outer.OtherNested()</expr>)
}
@@ -0,0 +1,8 @@
Before shortening: Outer.OtherNested()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_IMPORT:
[qualifier] Outer.OtherNested()
with SHORTEN_AND_STAR_IMPORT:
[qualifier] Outer.OtherNested()
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
<expr>class Foo : Outer.Nested()</expr>
}
@@ -0,0 +1,8 @@
Before shortening: class Foo : Outer.Nested()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
@@ -0,0 +1,11 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer(), Marker
interface class Marker
class MarkerImpl() : Marker
class Foo : Outer.Nested(), <expr>Outer.Marker by Outer.MarkerImpl()</expr>
}
@@ -0,0 +1,11 @@
Before shortening: Outer.Marker by Outer.MarkerImpl()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Marker
[qualifier] Outer.MarkerImpl()
with SHORTEN_AND_IMPORT:
[type] Outer.Marker
[qualifier] Outer.MarkerImpl()
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Marker
[qualifier] Outer.MarkerImpl()
@@ -0,0 +1,9 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested<T> : Outer()
class OtherNested
class Foo : <expr>Outer.Nested<Outer.OtherNested></expr> { constructor(): super() }
}
@@ -0,0 +1,11 @@
Before shortening: Outer.Nested<Outer.OtherNested>
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested<Outer.OtherNested>
[type] Outer.OtherNested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested<Outer.OtherNested>
[type] Outer.OtherNested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested<Outer.OtherNested>
[type] Outer.OtherNested
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
<expr>class Foo : Outer.Nested { constructor(): super() }</expr>
}
@@ -0,0 +1,8 @@
Before shortening: class Foo : Outer.Nested { constructor(): super() }
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested
@@ -0,0 +1,7 @@
// FILE: main.kt
abstract class Outer {
abstract class Nested : Outer()
class Foo<T : <expr>Outer.Nested</expr>> : Outer.Nested()
}
@@ -0,0 +1,8 @@
Before shortening: Outer.Nested
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[type] Outer.Nested
with SHORTEN_AND_IMPORT:
[type] Outer.Nested
with SHORTEN_AND_STAR_IMPORT:
[type] Outer.Nested