Got rid of isProbablyNothing in stubs + fixed exception on some files on indexing stubs

This commit is contained in:
Valentin Kipyatkov
2015-03-31 17:50:26 +03:00
parent 0243280668
commit 6a2cc66eb1
52 changed files with 230 additions and 213 deletions
@@ -120,8 +120,7 @@ private class CallableClsStubBuilder(
isExtension = callableProto.hasReceiverType(),
hasBlockBody = true,
hasBody = Flags.MODALITY[callableProto.getFlags()] != Modality.ABSTRACT,
hasTypeParameterListBeforeFunctionName = callableProto.getTypeParameterList().isNotEmpty(),
isProbablyNothingType = isProbablyNothing(callableProto)
hasTypeParameterListBeforeFunctionName = callableProto.getTypeParameterList().isNotEmpty()
)
}
ProtoBuf.Callable.CallableKind.VAL, ProtoBuf.Callable.CallableKind.VAR -> {
@@ -135,8 +134,7 @@ private class CallableClsStubBuilder(
hasInitializer = false,
isExtension = callableProto.hasReceiverType(),
hasReturnTypeRef = true,
fqName = c.containerFqName.child(callableName),
isProbablyNothingType = isProbablyNothing(callableProto)
fqName = c.containerFqName.child(callableName)
)
}
ProtoBuf.Callable.CallableKind.CONSTRUCTOR -> {
@@ -148,11 +146,4 @@ private class CallableClsStubBuilder(
else -> throw IllegalStateException("Unknown callable kind $callableKind")
}
}
//TODO: remove isProbablyNothing from stubs
private fun isProbablyNothing(callableProto: ProtoBuf.Callable): Boolean {
val constructor = callableProto.getReturnType().getConstructor()
return constructor.getKind() == ProtoBuf.Type.Constructor.Kind.CLASS &&
c.nameResolver.getClassId(constructor.getId()).getShortClassName().asString() == "Nothing"
}
}
@@ -22,15 +22,17 @@ import com.intellij.openapi.util.Key
import com.intellij.psi.stubs.IndexSink
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.stubs.KotlinCallableStubBase
import org.jetbrains.kotlin.psi.stubs.getContainingFileStub
import org.jetbrains.kotlin.util.aliasImportMap
fun indexTopLevelExtension<TDeclaration : JetCallableDeclaration>(stub: KotlinCallableStubBase<TDeclaration>, sink: IndexSink) {
if (stub.isExtension()) {
val declaration = stub.getPsi()
declaration.getReceiverTypeReference()!!.getTypeElement()?.index(declaration, sink)
declaration.getReceiverTypeReference()!!.getTypeElement()?.index(declaration, stub.getContainingFileStub().getPsi() != null, sink)
}
}
private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declaration: TDeclaration, sink: IndexSink) {
private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declaration: TDeclaration, hasFile: Boolean, sink: IndexSink) {
fun occurrence(typeName: String) {
val name = declaration.getName() ?: return
sink.occurrence(JetTopLevelExtensionsByReceiverTypeIndex.INSTANCE.getKey(),
@@ -46,7 +48,7 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
if (typeParameter != null) {
val bound = typeParameter.getExtendsBound()
if (bound != null) {
bound.getTypeElement()?.index(declaration, sink)
bound.getTypeElement()?.index(declaration, hasFile, sink)
return
}
occurrence("Any")
@@ -56,11 +58,13 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
occurrence(referenceName)
val aliasNames = declaration.getContainingJetFile().aliasImportMap()[referenceName]
aliasNames.forEach { occurrence(it) }
if (hasFile) {
val aliasNames = declaration.getContainingJetFile().aliasImportMap()[referenceName]
aliasNames.forEach { occurrence(it) }
}
}
is JetNullableType -> getInnerType()?.index(declaration, sink)
is JetNullableType -> getInnerType()?.index(declaration, hasFile, sink)
is JetFunctionType -> {
val typeName = (if (getReceiverTypeReference() != null) "ExtensionFunction" else "Function") + getParameters().size()
@@ -71,29 +75,3 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
}
}
private class CachedAliasImportData(val map: Multimap<String, String>, val fileModificationStamp: Long)
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
private fun JetFile.aliasImportMap(): Multimap<String, String> {
val cached = getUserData(ALIAS_IMPORT_DATA_KEY)
val modificationStamp = getModificationStamp()
if (cached != null && modificationStamp == cached.fileModificationStamp) {
return cached.map
}
val data = CachedAliasImportData(buildAliasImportMap(), modificationStamp)
putUserData(ALIAS_IMPORT_DATA_KEY, cached)
return data.map
}
private fun JetFile.buildAliasImportMap(): Multimap<String, String> {
val map = HashMultimap.create<String, String>()
val importList = getImportList() ?: return map
for (import in importList.getImports()) {
val aliasName = import.getAliasName() ?: continue
val name = import.getImportPath()?.fqnPart()?.shortName()?.asString() ?: continue
map.put(aliasName, name)
}
return map
}
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.JetClassOrObject;
import org.jetbrains.kotlin.psi.stubs.*;
import org.jetbrains.kotlin.psi.stubs.elements.StubIndexService;
import org.jetbrains.kotlin.util.UtilPackage;
public class StubIndexServiceImpl implements StubIndexService {
@@ -81,7 +82,7 @@ public class StubIndexServiceImpl implements StubIndexService {
if (name != null) {
sink.occurrence(JetFunctionShortNameIndex.getInstance().getKey(), name);
if (stub.isProbablyNothingType()) {
if (UtilPackage.isProbablyNothing(stub.getPsi().getTypeReference())) {
sink.occurrence(JetProbablyNothingFunctionShortNameIndex.getInstance().getKey(), name);
}
}
@@ -103,7 +104,7 @@ public class StubIndexServiceImpl implements StubIndexService {
if (name != null) {
sink.occurrence(JetPropertyShortNameIndex.getInstance().getKey(), name);
if (stub.isProbablyNothingType()) {
if (UtilPackage.isProbablyNothing(stub.getPsi().getTypeReference())) {
sink.occurrence(JetProbablyNothingPropertyShortNameIndex.getInstance().getKey(), name);
}
}