Minor code changes after code review

This commit is contained in:
Valentin Kipyatkov
2015-04-01 19:42:11 +03:00
parent b45b462bdf
commit 784b4a8aeb
7 changed files with 36 additions and 38 deletions
@@ -22,7 +22,6 @@ 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) {
@@ -32,7 +31,7 @@ fun indexTopLevelExtension<TDeclaration : JetCallableDeclaration>(stub: KotlinCa
}
}
private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declaration: TDeclaration, sink: IndexSink) {
private fun JetTypeElement.index<TDeclaration : JetCallableDeclaration>(declaration: TDeclaration, sink: IndexSink) {
fun occurrence(typeName: String) {
val name = declaration.getName() ?: return
sink.occurrence(JetTopLevelExtensionsByReceiverTypeIndex.INSTANCE.getKey(),
@@ -43,17 +42,16 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
is JetUserType -> {
var referenceName = getReferencedName() ?: return
if (declaration is JetNamedFunction) {
val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == referenceName }
if (typeParameter != null) {
val bound = typeParameter.getExtendsBound()
if (bound != null) {
bound.getTypeElement()?.index(declaration, sink)
return
}
occurrence("Any")
return
val typeParameter = declaration.getTypeParameters().firstOrNull { it.getName() == referenceName }
if (typeParameter != null) {
val bound = typeParameter.getExtendsBound()
if (bound != null) {
bound.getTypeElement()?.index(declaration, sink)
}
else {
occurrence("Any")
}
return
}
occurrence(referenceName)
@@ -68,7 +66,9 @@ private fun <TDeclaration : JetCallableDeclaration> JetTypeElement.index(declara
occurrence(typeName)
}
else -> occurrence("Any")
is JetDynamicType -> occurrence("Any")
else -> error("Unsupported type: $this")
}
}
@@ -31,13 +31,14 @@ public class JetTopLevelExtensionsByReceiverTypeIndex private() : StringStubInde
companion object {
private val KEY = KotlinIndexUtil.createIndexKey<String, JetCallableDeclaration>(javaClass<JetTopLevelExtensionsByReceiverTypeIndex>())
private val SEPARATOR = '\n'
public val INSTANCE: JetTopLevelExtensionsByReceiverTypeIndex = JetTopLevelExtensionsByReceiverTypeIndex()
public fun buildKey(receiverTypeName: String, callableName: String): String = receiverTypeName + "\n" + callableName
public fun buildKey(receiverTypeName: String, callableName: String): String = receiverTypeName + SEPARATOR + callableName
public fun receiverTypeNameFromKey(key: String): String = key.substringBefore('\n', "")
public fun receiverTypeNameFromKey(key: String): String = key.substringBefore(SEPARATOR, "")
public fun callableNameFromKey(key: String): String = key.substringAfter('\n', "")
public fun callableNameFromKey(key: String): String = key.substringAfter(SEPARATOR, "")
}
}