in src/main/kotlin/org/jetbrains/plugins/feature/suggester/suggesters/RenamingSuggester.kt [49:87]
override fun getSuggestion(action: Action): Suggestion {
val language = action.language ?: return NoSuggestion
val langSupport = LanguageSupport.getForLanguage(language) ?: return NoSuggestion
val name = CommandProcessor.getInstance().currentCommandName
if (name != null && name != "Paste") {
return NoSuggestion
}
when (action) {
is BeforeChildReplacedAction -> {
val parent = action.parent
val oldChild = action.oldChild
if (langSupport.isIdentifier(oldChild)) {
if (!renamedIdentifiersData.references.contains(parent)) {
// TODO Find out why resolve reference causes:
// "java.lang.Throwable: Somebody has requested stubbed spine during PSI operations;
// not only is this expensive, but will also cause stub PSI invalidation"
// Can be reproduced placing '{' before another code block "{ ... }"
val declaration = parent.reference?.resolve() ?: parent
@Suppress("SpreadOperator")
val references = arrayListOf(declaration, *declaration.getAllReferences().toTypedArray())
renamedIdentifiersData = RenamedIdentifiersData(oldChild.text, references)
}
}
}
is ChildReplacedAction -> {
val parent = action.parent
val newChild = action.newChild
if (langSupport.isIdentifier(newChild)) {
if (renamedIdentifiersData.references.contains(parent) &&
renamedIdentifiersData.isAllRenamed()
) {
return createSuggestion()
}
}
}
}
return NoSuggestion
}