Revert extension function in IndexUtils and better testing
This commit is contained in:
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.generators.util.KT_OR_KTS
|
|||||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
import org.jetbrains.kotlin.idea.index.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.generators.util.KT_OR_KTS
|
|||||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
import org.jetbrains.kotlin.idea.index.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.generators.util.KT_OR_KTS
|
|||||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
import org.jetbrains.kotlin.idea.index.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.generators.util.KT_OR_KTS
|
|||||||
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
import org.jetbrains.kotlin.generators.util.KT_WITHOUT_DOTS_IN_NAME
|
||||||
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
import org.jetbrains.kotlin.idea.index.AbstractKotlinTypeAliasByExpansionShortNameIndexTest
|
||||||
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest
|
||||||
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
import org.jetbrains.kotlin.idea.actions.AbstractGotoTestOrCodeActionTest
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ fun <TDeclaration : KtCallableDeclaration> indexTopLevelExtension(stub: KotlinCa
|
|||||||
if (stub.isExtension()) {
|
if (stub.isExtension()) {
|
||||||
val declaration = stub.psi
|
val declaration = stub.psi
|
||||||
val containingTypeReference = declaration.receiverTypeReference!!
|
val containingTypeReference = declaration.receiverTypeReference!!
|
||||||
index(containingTypeReference.typeElement, declaration, containingTypeReference) { typeName ->
|
containingTypeReference.typeElement?.index(declaration, containingTypeReference) { typeName ->
|
||||||
val name = declaration.name ?: return@index
|
val name = declaration.name ?: return@index
|
||||||
sink.occurrence(
|
sink.occurrence(
|
||||||
KotlinTopLevelExtensionsByReceiverTypeIndex.INSTANCE.key,
|
KotlinTopLevelExtensionsByReceiverTypeIndex.INSTANCE.key,
|
||||||
@@ -44,38 +44,35 @@ fun indexTypeAliasExpansion(stub: KotlinTypeAliasStub, sink: IndexSink) {
|
|||||||
val declaration = stub.psi
|
val declaration = stub.psi
|
||||||
val typeReference = declaration.getTypeReference() ?: return
|
val typeReference = declaration.getTypeReference() ?: return
|
||||||
val typeElement = typeReference.typeElement ?: return
|
val typeElement = typeReference.typeElement ?: return
|
||||||
index(typeElement, declaration, typeReference) { typeName ->
|
typeElement.index(declaration, typeReference) { typeName ->
|
||||||
sink.occurrence(KotlinTypeAliasByExpansionShortNameIndex.KEY, typeName)
|
sink.occurrence(KotlinTypeAliasByExpansionShortNameIndex.KEY, typeName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun index(
|
private fun KtTypeElement.index(
|
||||||
typeElement: KtTypeElement?,
|
|
||||||
declaration: KtTypeParameterListOwner,
|
declaration: KtTypeParameterListOwner,
|
||||||
containingTypeReference: KtTypeReference,
|
containingTypeReference: KtTypeReference,
|
||||||
occurrence: (String) -> Unit
|
occurrence: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
fun internalIndex(
|
fun KtTypeElement.indexWithVisited(
|
||||||
typeElement: KtTypeElement?,
|
|
||||||
declaration: KtTypeParameterListOwner,
|
declaration: KtTypeParameterListOwner,
|
||||||
containingTypeReference: KtTypeReference,
|
containingTypeReference: KtTypeReference,
|
||||||
visited: MutableSet<KtTypeElement>,
|
visited: MutableSet<KtTypeElement>,
|
||||||
occurrence: (String) -> Unit
|
occurrence: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
if (typeElement == null) return
|
if (this in visited) return
|
||||||
if (typeElement in visited) return
|
|
||||||
|
|
||||||
visited.add(typeElement)
|
visited.add(this)
|
||||||
|
|
||||||
when (typeElement) {
|
when (this) {
|
||||||
is KtUserType -> {
|
is KtUserType -> {
|
||||||
val referenceName = typeElement.referencedName ?: return
|
val referenceName = referencedName ?: return
|
||||||
|
|
||||||
val typeParameter = declaration.typeParameters.firstOrNull { it.name == referenceName }
|
val typeParameter = declaration.typeParameters.firstOrNull { it.name == referenceName }
|
||||||
if (typeParameter != null) {
|
if (typeParameter != null) {
|
||||||
val bound = typeParameter.extendsBound
|
val bound = typeParameter.extendsBound
|
||||||
if (bound != null) {
|
if (bound != null) {
|
||||||
internalIndex(bound.typeElement, declaration, containingTypeReference, visited, occurrence)
|
bound.typeElement?.indexWithVisited(declaration, containingTypeReference, visited, occurrence)
|
||||||
} else {
|
} else {
|
||||||
occurrence("Any")
|
occurrence("Any")
|
||||||
}
|
}
|
||||||
@@ -84,13 +81,13 @@ private fun index(
|
|||||||
|
|
||||||
occurrence(referenceName)
|
occurrence(referenceName)
|
||||||
|
|
||||||
typeElement.aliasImportMap()[referenceName].forEach { occurrence(it) }
|
aliasImportMap()[referenceName].forEach { occurrence(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
is KtNullableType -> internalIndex(typeElement.innerType, declaration, containingTypeReference, visited, occurrence)
|
is KtNullableType -> innerType?.indexWithVisited(declaration, containingTypeReference, visited, occurrence)
|
||||||
|
|
||||||
is KtFunctionType -> {
|
is KtFunctionType -> {
|
||||||
val arity = typeElement.parameters.size + (if (typeElement.receiverTypeReference != null) 1 else 0)
|
val arity = parameters.size + (if (receiverTypeReference != null) 1 else 0)
|
||||||
val suspendPrefix =
|
val suspendPrefix =
|
||||||
if (containingTypeReference.modifierList?.hasModifier(KtTokens.SUSPEND_KEYWORD) == true)
|
if (containingTypeReference.modifierList?.hasModifier(KtTokens.SUSPEND_KEYWORD) == true)
|
||||||
"Suspend"
|
"Suspend"
|
||||||
@@ -101,11 +98,11 @@ private fun index(
|
|||||||
|
|
||||||
is KtDynamicType -> occurrence("Any")
|
is KtDynamicType -> occurrence("Any")
|
||||||
|
|
||||||
else -> error("Unsupported type: $typeElement")
|
else -> error("Unsupported type: $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internalIndex(typeElement, declaration, containingTypeReference, mutableSetOf(), occurrence)
|
indexWithVisited(declaration, containingTypeReference, mutableSetOf(), occurrence)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun indexInternals(stub: KotlinCallableStubBase<*>, sink: IndexSink) {
|
fun indexInternals(stub: KotlinCallableStubBase<*>, sink: IndexSink) {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
//fun <T: T> T.some() {}
|
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea
|
package org.jetbrains.kotlin.idea.index
|
||||||
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinTypeAliasByExpansionShortNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinTypeAliasByExpansionShortNameIndex
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.index
|
||||||
|
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
|
||||||
|
class IndexExceptionTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
|
fun testRecursionInTypeParameters() {
|
||||||
|
myFixture.configureByText("test.kt", "fun <T: T> T.some() {}")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProjectDescriptor(): LightProjectDescriptor = JAVA_LATEST
|
||||||
|
}
|
||||||
+1
-6
@@ -3,7 +3,7 @@
|
|||||||
* that can be found in the license/LICENSE.txt file.
|
* that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea;
|
package org.jetbrains.kotlin.idea.index;
|
||||||
|
|
||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||||
@@ -39,11 +39,6 @@ public class KotlinTypeAliasByExpansionShortNameIndexTestGenerated extends Abstr
|
|||||||
runTest("idea/testData/typealiasExpansionIndex/generics.kt");
|
runTest("idea/testData/typealiasExpansionIndex/generics.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("recursion.kt")
|
|
||||||
public void testRecursion() throws Exception {
|
|
||||||
runTest("idea/testData/typealiasExpansionIndex/recursion.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("simpleType.kt")
|
@TestMetadata("simpleType.kt")
|
||||||
public void testSimpleType() throws Exception {
|
public void testSimpleType() throws Exception {
|
||||||
runTest("idea/testData/typealiasExpansionIndex/simpleType.kt");
|
runTest("idea/testData/typealiasExpansionIndex/simpleType.kt");
|
||||||
Reference in New Issue
Block a user