diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt index 53a167a0ae4..3da08f0ff3d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtTypeAliasElementType.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.psi.stubs.elements +import com.intellij.psi.stubs.IndexSink import com.intellij.psi.stubs.StubElement import com.intellij.psi.stubs.StubInputStream import com.intellij.psi.stubs.StubOutputStream @@ -47,4 +48,8 @@ class KtTypeAliasElementType(debugName: String) : val isTopLevel = dataStream.readBoolean() return KotlinTypeAliasStubImpl(KtStubElementTypes.TYPEALIAS, parentStub, name, fqName, isTopLevel) } + + override fun indexStub(stub: KotlinTypeAliasStub, sink: IndexSink) { + StubIndexService.getInstance().indexTypeAlias(stub, sink) + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/StubIndexService.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/StubIndexService.kt index 36fd8bce9a0..dc3d95a78db 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/StubIndexService.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/StubIndexService.kt @@ -35,6 +35,9 @@ open class StubIndexService protected constructor() { open fun indexFunction(stub: KotlinFunctionStub, sink: IndexSink) { } + open fun indexTypeAlias(stub: KotlinTypeAliasStub, sink: IndexSink) { + } + open fun indexObject(stub: KotlinObjectStub, sink: IndexSink) { } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index b639a742dd4..9b0d4d012bc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -480,7 +480,7 @@ class TypeResolver( } override fun boundsViolationInSubstitution(bound: KotlinType, argument: KotlinType, typeParameter: TypeParameterDescriptor) { - TODO() + TODO("boundsViolationInSubstitution") } } @@ -529,9 +529,11 @@ class TypeResolver( "Type alias expansion: result for ${typeAliasExpansion.descriptor} is ${expandedProjection.projectionKind}, should be invariant" } - val abbreviatedType = KotlinTypeImpl.create(annotations, typeAliasExpansion.descriptor.typeConstructor, + val abbreviatedType = KotlinTypeImpl.create(annotations, + typeAliasExpansion.descriptor.typeConstructor, originalProjection.type.isMarkedNullable, - typeAliasExpansion.arguments, MemberScope.Empty) + typeAliasExpansion.arguments, + MemberScope.Empty) return expandedType.withAbbreviatedType(abbreviatedType) } diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt b/compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt new file mode 100644 index 00000000000..fb4a4957dc1 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt @@ -0,0 +1,14 @@ +//ALLOW_AST_ACCESS +package test + +typealias S = String +typealias SS = S +typealias SSS = SS + +val x1: S = "" +val x2: SS = "" +val x3: SSS = "" + +val x4: S? = "" +val x5: SS? = "" +val x6: SSS? = "" diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Basic.txt b/compiler/testData/loadJava/compiledKotlin/typealias/Basic.txt new file mode 100644 index 00000000000..da51d6a3615 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/typealias/Basic.txt @@ -0,0 +1,17 @@ +package test + +public typealias S = kotlin.String +public typealias SS = test.S +public typealias SSS = test.SS +public val x1: test.S [= kotlin.String] = "" + public fun (): test.S [= kotlin.String] +public val x2: test.SS [= kotlin.String] = "" + public fun (): test.SS [= kotlin.String] +public val x3: test.SSS [= kotlin.String] = "" + public fun (): test.SSS [= kotlin.String] +public val x4: test.S? [= kotlin.String?] = "" + public fun (): test.S? [= kotlin.String?] +public val x5: test.SS? [= kotlin.String?] = "" + public fun (): test.SS? [= kotlin.String?] +public val x6: test.SSS? [= kotlin.String?] = "" + public fun (): test.SSS? [= kotlin.String?] diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt b/compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt new file mode 100644 index 00000000000..6ff2a69afc7 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt @@ -0,0 +1,13 @@ +//ALLOW_AST_ACCESS +package test + +typealias L = List +typealias LL = L +typealias LLL = LL + +fun test1(x: L) {} +fun test2(x: LL) {} +fun test3(x: LLL) {} +fun test4(x: L>) {} +fun test5(x: LL>) {} +fun test6(x: LLL>) {} diff --git a/compiler/testData/loadJava/compiledKotlin/typealias/Generic.txt b/compiler/testData/loadJava/compiledKotlin/typealias/Generic.txt new file mode 100644 index 00000000000..9c3b3838fc7 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/typealias/Generic.txt @@ -0,0 +1,11 @@ +package test + +public typealias L = kotlin.collections.List +public typealias LL = test.L +public typealias LLL = test.LL +public fun test1(/*0*/ x: test.L [= kotlin.collections.List]): kotlin.Unit +public fun test2(/*0*/ x: test.LL [= kotlin.collections.List]): kotlin.Unit +public fun test3(/*0*/ x: test.LLL [= kotlin.collections.List]): kotlin.Unit +public fun test4(/*0*/ x: test.L [= kotlin.collections.List]> [= kotlin.collections.List [= kotlin.collections.List]>]): kotlin.Unit +public fun test5(/*0*/ x: test.LL [= kotlin.collections.List]> [= kotlin.collections.List [= kotlin.collections.List]>]): kotlin.Unit +public fun test6(/*0*/ x: test.LLL [= kotlin.collections.List]> [= kotlin.collections.List [= kotlin.collections.List]>]): kotlin.Unit diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/util/RecursiveDescriptorProcessor.java b/compiler/tests-common/org/jetbrains/kotlin/test/util/RecursiveDescriptorProcessor.java index bde8834ed11..b1be75998df 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/util/RecursiveDescriptorProcessor.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/util/RecursiveDescriptorProcessor.java @@ -111,8 +111,8 @@ public class RecursiveDescriptorProcessor { @Override public Boolean visitTypeAliasDescriptor(TypeAliasDescriptor descriptor, D data) { - // TODO typealias - return true; + return applyWorker(descriptor, data) + && visitChildren(descriptor.getDeclaredTypeParameters(), data); } @Override diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index b75730e76da..ef2ebd1655a 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -4796,6 +4796,27 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { } } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/typealias") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Typealias extends AbstractLoadJavaTest { + public void testAllFilesPresentInTypealias() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("Basic.kt") + public void testBasic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt"); + doTestCompiledKotlin(fileName); + } + + @TestMetadata("Generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); + doTestCompiledKotlin(fileName); + } + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java index 299ff978dff..5408c063f7f 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java @@ -3029,6 +3029,27 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith } } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/typealias") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Typealias extends AbstractLoadKotlinWithTypeTableTest { + public void testAllFilesPresentInTypealias() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("Basic.kt") + public void testBasic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt"); + doTest(fileName); + } + + @TestMetadata("Generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index 61db90a077c..776a280fc2d 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -3031,6 +3031,27 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD } } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/typealias") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Typealias extends AbstractJvmRuntimeDescriptorLoaderTest { + public void testAllFilesPresentInTypealias() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("Basic.kt") + public void testBasic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt"); + doTest(fileName); + } + + @TestMetadata("Generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java index 85f8f6c5880..15aa8b34f4a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java @@ -142,6 +142,19 @@ public class IdeStubIndexService extends StubIndexService { } } + @Override + public void indexTypeAlias(KotlinTypeAliasStub stub, IndexSink sink) { + // TODO short name index for type aliases? + + if (stub.isTopLevel()) { + FqName fqName = stub.getFqName(); + if (fqName != null) { + sink.occurrence(KotlinTopLevelTypeAliasFqNameIndex.getInstance().getKey(), fqName.asString()); + sink.occurrence(KotlinTopLevelTypeAliasByPackageIndex.getInstance().getKey(), fqName.parent().asString()); + } + } + } + @Override public void indexProperty(KotlinPropertyStub stub, IndexSink sink) { String name = stub.getName(); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasByPackageIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasByPackageIndex.kt new file mode 100644 index 00000000000..7a9dedcf0b0 --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasByPackageIndex.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.stubindex + +import com.intellij.openapi.project.Project +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.stubs.StringStubIndexExtension +import com.intellij.psi.stubs.StubIndex +import com.intellij.psi.stubs.StubIndexKey +import org.jetbrains.kotlin.psi.KtTypeAlias + +class KotlinTopLevelTypeAliasByPackageIndex : StringStubIndexExtension() { + override fun getKey(): StubIndexKey = KEY + + override fun get(s: String, project: Project, scope: GlobalSearchScope): Collection = + StubIndex.getElements( + KEY, s, project, + KotlinSourceFilterScope.sourcesAndLibraries(scope, project), + KtTypeAlias::class.java) + + companion object { + val KEY = KotlinIndexUtil.createIndexKey(KotlinTopLevelTypeAliasByPackageIndex::class.java) + val INSTANCE = KotlinTopLevelTypeAliasByPackageIndex() + + @JvmStatic fun getInstance() = INSTANCE + } +} \ No newline at end of file diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasFqNameIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasFqNameIndex.kt new file mode 100644 index 00000000000..60f3c61d45d --- /dev/null +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinTopLevelTypeAliasFqNameIndex.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.stubindex + +import com.intellij.openapi.project.Project +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.stubs.StringStubIndexExtension +import com.intellij.psi.stubs.StubIndex +import com.intellij.psi.stubs.StubIndexKey +import org.jetbrains.kotlin.psi.KtTypeAlias + +class KotlinTopLevelTypeAliasFqNameIndex : StringStubIndexExtension() { + override fun getKey(): StubIndexKey = KEY + + override fun get(s: String, project: Project, scope: GlobalSearchScope): Collection = + StubIndex.getElements( + KEY, s, project, + KotlinSourceFilterScope.sourcesAndLibraries(scope, project), + KtTypeAlias::class.java) + + companion object { + val KEY = KotlinIndexUtil.createIndexKey(KotlinTopLevelTypeAliasFqNameIndex::class.java) + val INSTANCE = KotlinTopLevelTypeAliasFqNameIndex() + + @JvmStatic fun getInstance() = INSTANCE + } +} + diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt index bce362b1922..7f4bca6aba0 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/resolve/StubBasedPackageMemberDeclarationProvider.kt @@ -46,6 +46,7 @@ class StubBasedPackageMemberDeclarationProvider( if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) { addFromIndex(KotlinTopLevelClassByPackageIndex.getInstance()) + addFromIndex(KotlinTopLevelTypeAliasByPackageIndex.getInstance()) } if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) { @@ -82,11 +83,12 @@ class StubBasedPackageMemberDeclarationProvider( } override fun getPackageFiles(): Collection { - return PackageIndexUtil.findFilesWithExactPackage(fqName, searchScope, project) + return PackageIndexUtil.findFilesWithExactPackage(fqName, searchScope, project) } - override fun getTypeAliasDeclarations(name: Name): Collection = - emptyList() // TODO stub index for type aliases + override fun getTypeAliasDeclarations(name: Name): Collection { + return KotlinTopLevelTypeAliasFqNameIndex.getInstance().get(childName(name), project, searchScope) + } private fun childName(name: Name): String { return fqName.child(ResolveSessionUtils.safeNameForLazyResolve(name)).asString() diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index bab050db6b1..14912791bff 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -563,6 +563,7 @@ + @@ -570,6 +571,7 @@ + diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java index a7a7289707c..67fdde47850 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java @@ -3029,6 +3029,27 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest { } } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/typealias") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Typealias extends AbstractResolveByStubTest { + public void testAllFilesPresentInTypealias() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/typealias"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("Basic.kt") + public void testBasic() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Basic.kt"); + doTest(fileName); + } + + @TestMetadata("Generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/typealias/Generic.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/loadJava/compiledKotlin/visibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)