diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirReferenceShortener.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirReferenceShortener.kt index 25481e837e3..9260e2f6bf6 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirReferenceShortener.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirReferenceShortener.kt @@ -51,11 +51,11 @@ import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.transformers.PackageResolutionResult import org.jetbrains.kotlin.fir.resolve.transformers.resolveToPackageOrClass import org.jetbrains.kotlin.fir.scopes.FirScope +import org.jetbrains.kotlin.fir.scopes.FirTypeParameterScope import org.jetbrains.kotlin.fir.scopes.getFunctions import org.jetbrains.kotlin.fir.scopes.getProperties import org.jetbrains.kotlin.fir.scopes.impl.* import org.jetbrains.kotlin.fir.scopes.processClassifiersByName -import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* @@ -262,9 +262,9 @@ private class FirShorteningContext(val analysisSession: KtFirAnalysisSession) { private val firSession: FirSession get() = firResolveSession.useSiteFirSession - class ClassifierCandidate(val scope: FirScope, val availableSymbol: AvailableSymbol>) + class ClassifierCandidate(val scope: FirScope, val availableSymbol: AvailableSymbol>) - fun findFirstClassifierInScopesByName(positionScopes: List, targetClassName: Name): AvailableSymbol>? = + fun findFirstClassifierInScopesByName(positionScopes: List, targetClassName: Name): AvailableSymbol>? = positionScopes.firstNotNullOfOrNull { scope -> findFirstClassifierSymbolByName(scope, targetClassName) } fun findClassifiersInScopesByName(scopes: List, targetClassName: Name): List = @@ -274,8 +274,8 @@ private class FirShorteningContext(val analysisSession: KtFirAnalysisSession) { ClassifierCandidate(scope, classifierSymbol) } - private fun findFirstClassifierSymbolByName(scope: FirScope, targetClassName: Name): AvailableSymbol>? { - val classifierSymbol = scope.findFirstClassifierByName(targetClassName) as? FirClassLikeSymbol<*> ?: return null + private fun findFirstClassifierSymbolByName(scope: FirScope, targetClassName: Name): AvailableSymbol>? { + val classifierSymbol = scope.findFirstClassifierByName(targetClassName) ?: return null return AvailableSymbol(classifierSymbol, ImportKind.fromScope(scope)) } @@ -560,6 +560,8 @@ private class ElementsToShortenCollector( ) } + private val FirClassifierSymbol<*>.classIdIfExists: ClassId? get() = (this as? FirClassLikeSymbol<*>)?.classId + /** * Returns true if the class symbol has a type parameter that is supposed to be provided for its parent class. * @@ -670,6 +672,7 @@ private class ElementsToShortenCollector( Local(1), ClassUseSite(2), NestedClassifier(2), + TypeParameter(2), ExplicitSimpleImporting(3), PackageMember(4), Unclassified(5), @@ -681,6 +684,7 @@ private class ElementsToShortenCollector( is FirLocalScope -> Local is FirClassUseSiteMemberScope -> ClassUseSite is FirNestedClassifierScope -> NestedClassifier + is FirTypeParameterScope -> TypeParameter is FirNestedClassifierScopeWithSubstitution -> originalScope.toPartialOrder() is FirExplicitSimpleImportingScope -> ExplicitSimpleImporting is FirPackageMemberScope -> PackageMember @@ -746,7 +750,7 @@ private class ElementsToShortenCollector( val name = classId.shortClassName val availableClassifiers = shorteningContext.findClassifiersInScopesByName(scopes, name) - val matchingAvailableSymbol = availableClassifiers.firstOrNull { it.availableSymbol.symbol.classId == classId } + val matchingAvailableSymbol = availableClassifiers.firstOrNull { it.availableSymbol.symbol.classIdIfExists == classId } val scopeForClass = matchingAvailableSymbol?.scope ?: return false if (availableClassifiers.map { it.scope }.hasScopeCloserThan(scopeForClass, element)) return false @@ -803,7 +807,7 @@ private class ElementsToShortenCollector( ) } // The class with name `classId.shortClassName` happens to be the same class referenced by this qualified access. - availableClassifier.symbol.classId == classId -> { + availableClassifier.symbol.classIdIfExists == classId -> { // Respect caller's request to use star import, if it's not already star-imported. return when { availableClassifier.importKind == ImportKind.EXPLICIT && importAllInParent -> { @@ -838,7 +842,7 @@ private class ElementsToShortenCollector( } private fun importedClassifierOverwritesAvailableClassifier( - availableClassifier: AvailableSymbol>, + availableClassifier: AvailableSymbol>, importAllInParent: Boolean ): Boolean { val importKindFromOption = if (importAllInParent) ImportKind.STAR else ImportKind.EXPLICIT @@ -868,7 +872,7 @@ private class ElementsToShortenCollector( val positionScopes = shorteningContext.findScopesAtPosition(expression, getNamesToImport(), contextProvider) ?: return val availableClassifier = shorteningContext.findFirstClassifierInScopesByName(positionScopes, shortClassName) ?: return when { - availableClassifier.symbol.classId == classToImport -> return + availableClassifier.symbol.classIdIfExists == classToImport -> return importedClassifierOverwritesAvailableClassifier(availableClassifier, importAllInParent) -> { importAffectsUsages = true } diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerated.java index f03da067af8..ff23be4666d 100644 --- a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerated.java +++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerated.java @@ -71,4 +71,14 @@ public class FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerat } } } + + @Nested + @TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters") + @TestDataPath("$PROJECT_ROOT") + public class TypeParameters { + @Test + public void testAllFilesPresentInTypeParameters() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters"), Pattern.compile("^(.+)\\.kts$"), null, true); + } + } } diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java index c0ecbd7e08b..7b1eb97af68 100644 --- a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java +++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/references/FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java @@ -755,4 +755,38 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext } } } + + @Nested + @TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters") + @TestDataPath("$PROJECT_ROOT") + public class TypeParameters { + @Test + public void testAllFilesPresentInTypeParameters() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("functionTypeParameterVsType.kt") + public void testFunctionTypeParameterVsType() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.kt"); + } + + @Test + @TestMetadata("typeParameterVsNestedType.kt") + public void testTypeParameterVsNestedType() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.kt"); + } + + @Test + @TestMetadata("typeParameterVsType_conflict.kt") + public void testTypeParameterVsType_conflict() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.kt"); + } + + @Test + @TestMetadata("typeParameterVsType_noConflict.kt") + public void testTypeParameterVsType_noConflict() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.kt"); + } + } } diff --git a/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/references/FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/references/FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java index 9c06d81948b..c7734164a98 100644 --- a/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/references/FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java +++ b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/references/FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenerated.java @@ -755,4 +755,38 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera } } } + + @Nested + @TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters") + @TestDataPath("$PROJECT_ROOT") + public class TypeParameters { + @Test + public void testAllFilesPresentInTypeParameters() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("functionTypeParameterVsType.kt") + public void testFunctionTypeParameterVsType() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.kt"); + } + + @Test + @TestMetadata("typeParameterVsNestedType.kt") + public void testTypeParameterVsNestedType() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.kt"); + } + + @Test + @TestMetadata("typeParameterVsType_conflict.kt") + public void testTypeParameterVsType_conflict() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.kt"); + } + + @Test + @TestMetadata("typeParameterVsType_noConflict.kt") + public void testTypeParameterVsType_noConflict() throws Exception { + runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.kt"); + } + } } diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.kt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.kt new file mode 100644 index 00000000000..9fd26a021cf --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.kt @@ -0,0 +1,10 @@ +package test + +interface MyType + + +context(test.MyType) +fun test.MyType.test(p: test.MyType) { + val a: test.MyType +} + \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.txt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.txt new file mode 100644 index 00000000000..c1c6a0d92d6 --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/functionTypeParameterVsType.txt @@ -0,0 +1,8 @@ +Before shortening: context(test.MyType) +fun test.MyType.test(p: test.MyType) { + val a: test.MyType +} +with DO_NOT_SHORTEN: +with SHORTEN_IF_ALREADY_IMPORTED: +with SHORTEN_AND_IMPORT: +with SHORTEN_AND_STAR_IMPORT: diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.kt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.kt new file mode 100644 index 00000000000..f2fd08477d0 --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.kt @@ -0,0 +1,14 @@ +package test + + +open class Base() + +class MyClass { + + interface MyType + + + context(MyClass.MyType) + class Nested : Base() + +} diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.txt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.txt new file mode 100644 index 00000000000..6aab3973618 --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsNestedType.txt @@ -0,0 +1,15 @@ +Before shortening: context(MyClass.MyType) + class Nested : Base() +with DO_NOT_SHORTEN: +with SHORTEN_IF_ALREADY_IMPORTED: +[type] MyClass.MyType +[type] MyClass.MyType +[type] MyClass.MyType +with SHORTEN_AND_IMPORT: +[type] MyClass.MyType +[type] MyClass.MyType +[type] MyClass.MyType +with SHORTEN_AND_STAR_IMPORT: +[type] MyClass.MyType +[type] MyClass.MyType +[type] MyClass.MyType diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.kt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.kt new file mode 100644 index 00000000000..dd6abb84790 --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.kt @@ -0,0 +1,10 @@ +package test + +interface MyType + +open class Base() + + +context(test.MyType) +class MyClass : Base() + \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.txt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.txt new file mode 100644 index 00000000000..5bea1c447fe --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_conflict.txt @@ -0,0 +1,6 @@ +Before shortening: context(test.MyType) +class MyClass : Base() +with DO_NOT_SHORTEN: +with SHORTEN_IF_ALREADY_IMPORTED: +with SHORTEN_AND_IMPORT: +with SHORTEN_AND_STAR_IMPORT: diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.kt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.kt new file mode 100644 index 00000000000..ed9854cab0b --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.kt @@ -0,0 +1,13 @@ +package test + +interface MyType + +open class Base() + +class MyClass { + // TODO this test has an error, MyType should not be resolved here. See KT-61959 + + context(test.MyType) + class Nested : Base() + +} diff --git a/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.txt b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.txt new file mode 100644 index 00000000000..6e5e8d6050e --- /dev/null +++ b/analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters/typeParameterVsType_noConflict.txt @@ -0,0 +1,6 @@ +Before shortening: context(test.MyType) + class Nested : Base() +with DO_NOT_SHORTEN: +with SHORTEN_IF_ALREADY_IMPORTED: +with SHORTEN_AND_IMPORT: +with SHORTEN_AND_STAR_IMPORT: diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt index 854874982e8..1a15b595dc9 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/util/ContextCollector.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.fir.types.typeContext import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf +import org.jetbrains.kotlin.util.PrivateForInline import org.jetbrains.kotlin.utils.yieldIfNotNull object ContextCollector { @@ -358,10 +359,13 @@ private class ContextCollectorVisitor( * Processing those parts before adding the implicit receiver of the class * to the [context] allows to not collect incorrect contexts for them later on. */ + @OptIn(PrivateForInline::class) private fun Processor.processClassHeader(regularClass: FirRegularClass) { - processList(regularClass.contextReceivers) - processList(regularClass.typeParameters) - processList(regularClass.superTypeRefs) + context.withTypeParametersOf(regularClass) { + processList(regularClass.contextReceivers) + processList(regularClass.typeParameters) + processList(regularClass.superTypeRefs) + } } override fun visitConstructor(constructor: FirConstructor) = withProcessor { diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.kt new file mode 100644 index 00000000000..4b2ef413377 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.kt @@ -0,0 +1,4 @@ +package test + +context(MyParam) +class Outer \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.txt new file mode 100644 index 00000000000..fa2ef567cde --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.txt @@ -0,0 +1,28 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromContextReceiver.kt + context(R|MyParam|) + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.kt new file mode 100644 index 00000000000..8d4d7e42a6c --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.kt @@ -0,0 +1,5 @@ +package test + +class Outer { + inner class InnerMyParam> +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.txt new file mode 100644 index 00000000000..06a891d9995 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.txt @@ -0,0 +1,46 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + Element 8 + Scope: FirNestedClassifierScopeImpl + Classifiers: + FirRegularClassSymbol public final inner class Inner : R|kotlin/Any| + Element 9 + Implicit receiver: + FirRegularClassSymbol public final class Outer : R|kotlin/Any| + Type: test/Outer + Element 10 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol T : R|MyParam| + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromInner_typeBound.kt + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super() + } + + public final inner [ResolvedTo(STATUS)] class Inner<[ResolvedTo(STATUS)] T : R|MyParam|, [ResolvedTo(STATUS)] Outer(MyParam)> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] test/Outer.constructor<[ResolvedTo(STATUS)] T : R|MyParam|>(): R|test/Outer.Inner| { + super() + } + + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.kt new file mode 100644 index 00000000000..47d0b976f17 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.kt @@ -0,0 +1,7 @@ +package test + +class Outer { + inner class Inner { + fun member(p: MyParam) {} + } +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.txt new file mode 100644 index 00000000000..bea92c81f00 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.txt @@ -0,0 +1,55 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + Element 8 + Scope: FirNestedClassifierScopeImpl + Classifiers: + FirRegularClassSymbol public final inner class Inner : R|kotlin/Any| + Element 9 + Implicit receiver: + FirRegularClassSymbol public final class Outer : R|kotlin/Any| + Type: test/Outer + Element 10 + Scope: FirMemberTypeParameterScope + Element 11 + Implicit receiver: + FirRegularClassSymbol public final inner class Inner : R|kotlin/Any| + Type: test/Outer.Inner + Element 12 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol p: R|MyParam| + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromInner_typeRefInMember.kt + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super() + } + + public final inner [ResolvedTo(STATUS)] class Inner<[ResolvedTo(STATUS)] Outer(MyParam)> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] test/Outer.constructor(): R|test/Outer.Inner| { + super() + } + + public final [ResolvedTo(BODY_RESOLVE)] fun member([ResolvedTo(BODY_RESOLVE)] p: R|MyParam|): R|kotlin/Unit| { + } + + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.kt new file mode 100644 index 00000000000..fe045ddd678 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.kt @@ -0,0 +1,6 @@ +package test + +class Outer { + // TODO this test has an error, MyParam should not be resolved here. See KT-61959 + class NestedMyParam> +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.txt new file mode 100644 index 00000000000..a7c0d55e504 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.txt @@ -0,0 +1,46 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + Element 8 + Scope: FirNestedClassifierScopeImpl + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Element 9 + Implicit receiver: + FirRegularClassSymbol public final class Outer : R|kotlin/Any| + Type: test/Outer + Element 10 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol T : R|MyParam| + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeBound.kt + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super() + } + + public final [ResolvedTo(STATUS)] class Nested<[ResolvedTo(STATUS)] T : R|MyParam|> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] T : R|MyParam|>(): R|test/Outer.Nested| { + super() + } + + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.kt new file mode 100644 index 00000000000..d408077dd03 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.kt @@ -0,0 +1,7 @@ +package test + +class Outer { + class Nested { + fun member(p: MyParam) {} + } +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.txt new file mode 100644 index 00000000000..f03b2b5b048 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.txt @@ -0,0 +1,45 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirNestedClassifierScopeImpl + Classifiers: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Element 8 + Implicit receiver: + FirRegularClassSymbol public final class Nested : R|kotlin/Any| + Type: test/Outer.Nested + Element 9 + Scope: FirLocalScope + Properties: + FirValueParameterSymbol p: + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromNested_typeRefInMember.kt + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super() + } + + public final [ResolvedTo(STATUS)] class Nested : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor(): R|test/Outer.Nested| { + super() + } + + public final [ResolvedTo(BODY_RESOLVE)] fun member([ResolvedTo(BODY_RESOLVE)] p: ): R|kotlin/Unit| { + } + + } + + } \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.kt new file mode 100644 index 00000000000..47b8b5205d0 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.kt @@ -0,0 +1,5 @@ +package test + +open class Base + +class Outer : Base<MyParam>() \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.txt new file mode 100644 index 00000000000..74c6bc69e6e --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.txt @@ -0,0 +1,33 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromSuperType.kt + public open [ResolvedTo(STATUS)] class Base<[ResolvedTo(STATUS)] T> : R|kotlin/Any| { + public [ResolvedTo(STATUS)] constructor<[ResolvedTo(STATUS)] T>(): R|test/Base| { + LAZY_super + } + + } + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam> : R|test/Base| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam>(): R|test/Outer| { + super|>() + } + + } diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.kt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.kt new file mode 100644 index 00000000000..929550b9421 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.kt @@ -0,0 +1,3 @@ +package test + +class OuterMyParam> \ No newline at end of file diff --git a/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.txt b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.txt new file mode 100644 index 00000000000..71f0cd96e18 --- /dev/null +++ b/analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.txt @@ -0,0 +1,28 @@ +Tower Data Context: + Element 0 + Scope: FirDefaultStarImportingScope + Element 1 + Scope: FirDefaultSimpleImportingScope + Element 2 + Scope: FirExplicitStarImportingScope + Element 3 + Scope: FirDefaultSimpleImportingScope + Element 4 + Scope: FirDefaultSimpleImportingScope + Element 5 + Scope: FirPackageMemberScope + Element 6 + Scope: FirExplicitSimpleImportingScope + Element 7 + Scope: FirMemberTypeParameterScope + Classifiers: + FirTypeParameterSymbol MyParam + FirTypeParameterSymbol Other : R|MyParam| + +FILE: [ResolvedTo(IMPORTS)] declaredInClass_fromTypeBound.kt + public final [ResolvedTo(STATUS)] class Outer<[ResolvedTo(STATUS)] MyParam, [ResolvedTo(STATUS)] Other : R|MyParam|> : R|kotlin/Any| { + public [ResolvedTo(BODY_RESOLVE)] constructor<[ResolvedTo(STATUS)] MyParam, [ResolvedTo(STATUS)] Other : R|MyParam|>(): R|test/Outer| { + super() + } + + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java index 6f00e5ab543..24378fb5ceb 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorScriptTestGenerated.java @@ -71,4 +71,14 @@ public class ContextCollectorScriptTestGenerated extends AbstractContextCollecto KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector/smartCasts"), Pattern.compile("^(.+)\\.(kts)$"), null, true); } } + + @Nested + @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/typeParameters") + @TestDataPath("$PROJECT_ROOT") + public class TypeParameters { + @Test + public void testAllFilesPresentInTypeParameters() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector/typeParameters"), Pattern.compile("^(.+)\\.(kts)$"), null, true); + } + } } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java index 340f03eb00a..8aa3d504a9d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/ContextCollectorSourceTestGenerated.java @@ -293,4 +293,56 @@ public class ContextCollectorSourceTestGenerated extends AbstractContextCollecto runTest("analysis/low-level-api-fir/testdata/contextCollector/smartCasts/when.kt"); } } + + @Nested + @TestMetadata("analysis/low-level-api-fir/testdata/contextCollector/typeParameters") + @TestDataPath("$PROJECT_ROOT") + public class TypeParameters { + @Test + public void testAllFilesPresentInTypeParameters() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/low-level-api-fir/testdata/contextCollector/typeParameters"), Pattern.compile("^(.+)\\.(kt)$"), null, true); + } + + @Test + @TestMetadata("declaredInClass_fromContextReceiver.kt") + public void testDeclaredInClass_fromContextReceiver() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromContextReceiver.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromInner_typeBound.kt") + public void testDeclaredInClass_fromInner_typeBound() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeBound.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromInner_typeRefInMember.kt") + public void testDeclaredInClass_fromInner_typeRefInMember() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromInner_typeRefInMember.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromNested_typeBound.kt") + public void testDeclaredInClass_fromNested_typeBound() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeBound.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromNested_typeRefInMember.kt") + public void testDeclaredInClass_fromNested_typeRefInMember() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromNested_typeRefInMember.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromSuperType.kt") + public void testDeclaredInClass_fromSuperType() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromSuperType.kt"); + } + + @Test + @TestMetadata("declaredInClass_fromTypeBound.kt") + public void testDeclaredInClass_fromTypeBound() throws Exception { + runTest("analysis/low-level-api-fir/testdata/contextCollector/typeParameters/declaredInClass_fromTypeBound.kt"); + } + } }