Exclude errors descriptors from the set of conflicting declarations
Resolve hanging in evaluate expression
This commit is contained in:
@@ -105,6 +105,7 @@ object KotlinNameSuggester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val COMMON_TYPE_PARAMETER_NAMES = listOf("T", "U", "V", "W", "X", "Y", "Z")
|
private val COMMON_TYPE_PARAMETER_NAMES = listOf("T", "U", "V", "W", "X", "Y", "Z")
|
||||||
|
private val MAX_NUMBER_OF_SUGGESTED_NAME_CHECKS = 1000
|
||||||
|
|
||||||
fun suggestNamesForTypeParameters(count: Int, validator: (String) -> Boolean): List<String> {
|
fun suggestNamesForTypeParameters(count: Int, validator: (String) -> Boolean): List<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
@@ -143,7 +144,7 @@ object KotlinNameSuggester {
|
|||||||
fun suggestNameByName(name: String, validator: (String) -> Boolean): String {
|
fun suggestNameByName(name: String, validator: (String) -> Boolean): String {
|
||||||
if (validator(name)) return name
|
if (validator(name)) return name
|
||||||
var i = 1
|
var i = 1
|
||||||
while (!validator(name + i)) {
|
while (i <= MAX_NUMBER_OF_SUGGESTED_NAME_CHECKS && !validator(name + i)) {
|
||||||
++i
|
++i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||||
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ class NewDeclarationNameValidator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notExcluded(it: DeclarationDescriptorWithSource) = it.source.getPsi() !in excludedDeclarations
|
private fun isExcluded(it: DeclarationDescriptorWithSource) = ErrorUtils.isError(it) || it.source.getPsi() in excludedDeclarations
|
||||||
|
|
||||||
private fun LexicalScope.hasConflict(name: Name): Boolean {
|
private fun LexicalScope.hasConflict(name: Name): Boolean {
|
||||||
fun DeclarationDescriptor.isVisible(): Boolean {
|
fun DeclarationDescriptor.isVisible(): Boolean {
|
||||||
@@ -106,10 +107,10 @@ class NewDeclarationNameValidator(
|
|||||||
|
|
||||||
return when(target) {
|
return when(target) {
|
||||||
Target.VARIABLES ->
|
Target.VARIABLES ->
|
||||||
getAllAccessibleVariables(name).any { !it.isExtension && it.isVisible() && notExcluded(it) }
|
getAllAccessibleVariables(name).any { !it.isExtension && it.isVisible() && !isExcluded(it) }
|
||||||
Target.FUNCTIONS_AND_CLASSES ->
|
Target.FUNCTIONS_AND_CLASSES ->
|
||||||
getAllAccessibleFunctions(name).any { !it.isExtension && it.isVisible() && notExcluded(it) } ||
|
getAllAccessibleFunctions(name).any { !it.isExtension && it.isVisible() && !isExcluded(it) } ||
|
||||||
findClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() && notExcluded(it) } ?: false
|
findClassifier(name, NoLookupLocation.FROM_IDE)?.let { it.isVisible() && !isExcluded(it) } ?: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user