Introduce KotlinOverridableInternalMembersShortNameIndex

Keeping track of all potentially overridable internal members
To optimize certain scenarios in light classes
This commit is contained in:
Pavel V. Talanov
2017-03-24 15:07:27 +03:00
parent 24303c8b39
commit a44aa8e112
5 changed files with 67 additions and 5 deletions
@@ -18,12 +18,12 @@ package org.jetbrains.kotlin.psi.stubs.impl;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.psi.KtModifierList;
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken;
import org.jetbrains.kotlin.psi.KtDeclarationModifierList;
import org.jetbrains.kotlin.psi.stubs.KotlinModifierListStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtModifierListElementType;
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken;
public class KotlinModifierListStubImpl extends KotlinStubBaseImpl<KtModifierList> implements KotlinModifierListStub {
public class KotlinModifierListStubImpl extends KotlinStubBaseImpl<KtDeclarationModifierList> implements KotlinModifierListStub {
private final int mask;
@@ -168,6 +168,8 @@ public class IdeStubIndexService extends StubIndexService {
IndexUtilsKt.indexTopLevelExtension(stub, sink);
}
}
IndexUtilsKt.indexInternals(stub, sink);
}
@Override
@@ -208,6 +210,8 @@ public class IdeStubIndexService extends StubIndexService {
IndexUtilsKt.indexTopLevelExtension(stub, sink);
}
}
IndexUtilsKt.indexInternals(stub, sink);
}
@Override
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.idea.stubindex
import com.intellij.psi.stubs.IndexSink
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.stubs.KotlinCallableStubBase
import org.jetbrains.kotlin.psi.stubs.KotlinTypeAliasStub
import org.jetbrains.kotlin.psi.stubs.*
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.util.aliasImportMap
fun <TDeclaration : KtCallableDeclaration> indexTopLevelExtension(stub: KotlinCallableStubBase<TDeclaration>, sink: IndexSink) {
@@ -87,3 +87,21 @@ private fun KtTypeElement.index(
else -> error("Unsupported type: $this")
}
}
fun indexInternals(stub: KotlinCallableStubBase<*>, sink: IndexSink) {
val name = stub.name ?: return
val modifierListStub = stub.modifierList ?: return
if (!modifierListStub.hasModifier(KtTokens.INTERNAL_KEYWORD)) return
if (stub.isTopLevel()) return
if (modifierListStub.hasModifier(KtTokens.OPEN_KEYWORD)
|| modifierListStub.hasModifier(KtTokens.ABSTRACT_KEYWORD)) {
sink.occurrence(KotlinOverridableInternalMembersShortNameIndex.Instance.key, name)
}
}
private val KotlinStubWithFqName<*>.modifierList: KotlinModifierListStub?
get() = findChildStubByType(KtStubElementTypes.MODIFIER_LIST) as? KotlinModifierListStub
@@ -0,0 +1,39 @@
/*
* Copyright 2010-2017 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 org.jetbrains.kotlin.psi.KtCallableDeclaration
class KotlinOverridableInternalMembersShortNameIndex private constructor() : StringStubIndexExtension<KtCallableDeclaration>() {
override fun getKey() = KEY
override fun get(name: String, project: Project, scope: GlobalSearchScope): Collection<KtCallableDeclaration> {
return StubIndex.getElements(KEY, name, project, scope, KtCallableDeclaration::class.java)
}
companion object {
@JvmField
val Instance = KotlinOverridableInternalMembersShortNameIndex()
private val KEY = KotlinIndexUtil.createIndexKey(KotlinOverridableInternalMembersShortNameIndex::class.java)
}
}
+1
View File
@@ -663,6 +663,7 @@
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinMultifileClassPartIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinScriptFqnIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTypeAliasByExpansionShortNameIndex"/>
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinOverridableInternalMembersShortNameIndex"/>
<psi.classFileDecompiler implementation="org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClassFileDecompiler"/>
<psi.classFileDecompiler implementation="org.jetbrains.kotlin.idea.decompiler.js.KotlinJavaScriptMetaFileDecompiler"/>