shuffle some code around to avoid JVM crash in tests

This commit is contained in:
Dmitry Jemerov
2015-03-24 18:57:18 +01:00
parent 20fbb814e4
commit 843298883f
@@ -75,10 +75,7 @@ public fun resolveKDocLink(session: KotlinCodeAnalyzer,
// Try to find a matching local descriptor (parameter or type parameter) first. // Try to find a matching local descriptor (parameter or type parameter) first.
if (qualifiedName.size() == 1) { if (qualifiedName.size() == 1) {
val scope = getResolutionScope(session, fromDescriptor) val localResult = resolveInLocalScope(fromDescriptor, qualifiedName.single(), session)
val localResult = scope.getDescriptors().filter {
it.getName().asString() == qualifiedName.single() && it.getContainingDeclaration() == fromDescriptor
}
if (!localResult.isEmpty()) { if (!localResult.isEmpty()) {
return localResult return localResult
} }
@@ -87,9 +84,6 @@ public fun resolveKDocLink(session: KotlinCodeAnalyzer,
var result: Collection<DeclarationDescriptor> = listOf(fromDescriptor) var result: Collection<DeclarationDescriptor> = listOf(fromDescriptor)
qualifiedName.forEach { nameComponent -> qualifiedName.forEach { nameComponent ->
if (result.size() != 1) return listOf() if (result.size() != 1) return listOf()
if (!Name.isValidIdentifier(nameComponent)) {
return listOf()
}
val scope = getResolutionScope(session, result.first()) val scope = getResolutionScope(session, result.first())
result = scope.getDescriptors().filter { it.getName().asString() == nameComponent } result = scope.getDescriptors().filter { it.getName().asString() == nameComponent }
} }
@@ -97,6 +91,15 @@ public fun resolveKDocLink(session: KotlinCodeAnalyzer,
return result return result
} }
private fun resolveInLocalScope(fromDescriptor: DeclarationDescriptor,
name: String,
session: KotlinCodeAnalyzer): List<DeclarationDescriptor> {
val scope = getResolutionScope(session, fromDescriptor)
return scope.getDescriptors().filter {
it.getName().asString() == name && it.getContainingDeclaration() == fromDescriptor
}
}
public fun getParamDescriptors(fromDescriptor: DeclarationDescriptor): List<DeclarationDescriptor> { public fun getParamDescriptors(fromDescriptor: DeclarationDescriptor): List<DeclarationDescriptor> {
// TODO resolve parameters of functions passed as parameters // TODO resolve parameters of functions passed as parameters
when (fromDescriptor) { when (fromDescriptor) {