Revert extension function in IndexUtils and better testing

This commit is contained in:
Nikolay Krasko
2019-01-31 17:22:43 +03:00
parent c89bee624a
commit a75da632a6
9 changed files with 37 additions and 29 deletions
@@ -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_WITHOUT_DOTS_IN_NAME
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.actions.AbstractGotoTestOrCodeActionTest
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_WITHOUT_DOTS_IN_NAME
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.actions.AbstractGotoTestOrCodeActionTest
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_WITHOUT_DOTS_IN_NAME
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.actions.AbstractGotoTestOrCodeActionTest
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_WITHOUT_DOTS_IN_NAME
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.actions.AbstractGotoTestOrCodeActionTest
import org.jetbrains.kotlin.idea.caches.resolve.AbstractIdeCompiledLightClassTest
@@ -30,7 +30,7 @@ fun <TDeclaration : KtCallableDeclaration> indexTopLevelExtension(stub: KotlinCa
if (stub.isExtension()) {
val declaration = stub.psi
val containingTypeReference = declaration.receiverTypeReference!!
index(containingTypeReference.typeElement, declaration, containingTypeReference) { typeName ->
containingTypeReference.typeElement?.index(declaration, containingTypeReference) { typeName ->
val name = declaration.name ?: return@index
sink.occurrence(
KotlinTopLevelExtensionsByReceiverTypeIndex.INSTANCE.key,
@@ -44,38 +44,35 @@ fun indexTypeAliasExpansion(stub: KotlinTypeAliasStub, sink: IndexSink) {
val declaration = stub.psi
val typeReference = declaration.getTypeReference() ?: return
val typeElement = typeReference.typeElement ?: return
index(typeElement, declaration, typeReference) { typeName ->
typeElement.index(declaration, typeReference) { typeName ->
sink.occurrence(KotlinTypeAliasByExpansionShortNameIndex.KEY, typeName)
}
}
private fun index(
typeElement: KtTypeElement?,
private fun KtTypeElement.index(
declaration: KtTypeParameterListOwner,
containingTypeReference: KtTypeReference,
occurrence: (String) -> Unit
) {
fun internalIndex(
typeElement: KtTypeElement?,
fun KtTypeElement.indexWithVisited(
declaration: KtTypeParameterListOwner,
containingTypeReference: KtTypeReference,
visited: MutableSet<KtTypeElement>,
occurrence: (String) -> Unit
) {
if (typeElement == null) return
if (typeElement in visited) return
if (this in visited) return
visited.add(typeElement)
visited.add(this)
when (typeElement) {
when (this) {
is KtUserType -> {
val referenceName = typeElement.referencedName ?: return
val referenceName = referencedName ?: return
val typeParameter = declaration.typeParameters.firstOrNull { it.name == referenceName }
if (typeParameter != null) {
val bound = typeParameter.extendsBound
if (bound != null) {
internalIndex(bound.typeElement, declaration, containingTypeReference, visited, occurrence)
bound.typeElement?.indexWithVisited(declaration, containingTypeReference, visited, occurrence)
} else {
occurrence("Any")
}
@@ -84,13 +81,13 @@ private fun index(
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 -> {
val arity = typeElement.parameters.size + (if (typeElement.receiverTypeReference != null) 1 else 0)
val arity = parameters.size + (if (receiverTypeReference != null) 1 else 0)
val suspendPrefix =
if (containingTypeReference.modifierList?.hasModifier(KtTokens.SUSPEND_KEYWORD) == true)
"Suspend"
@@ -101,11 +98,11 @@ private fun index(
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) {
-1
View File
@@ -1 +0,0 @@
//fun <T: T> T.some() {}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea
package org.jetbrains.kotlin.idea.index
import com.intellij.psi.search.GlobalSearchScope
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
}
@@ -3,7 +3,7 @@
* 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 org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
@@ -39,11 +39,6 @@ public class KotlinTypeAliasByExpansionShortNameIndexTestGenerated extends Abstr
runTest("idea/testData/typealiasExpansionIndex/generics.kt");
}
@TestMetadata("recursion.kt")
public void testRecursion() throws Exception {
runTest("idea/testData/typealiasExpansionIndex/recursion.kt");
}
@TestMetadata("simpleType.kt")
public void testSimpleType() throws Exception {
runTest("idea/testData/typealiasExpansionIndex/simpleType.kt");