Skip to content

Commit c952e26

Browse files
cypressiousasedunov
authored andcommitted
Fix NPE caused by Rename Refactoring of backing field when caret is after the last character
#KT-16605 Fixed
1 parent 1bad04d commit c952e26

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameBackingFieldReferenceHandler.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2016 JetBrains s.r.o.
2+
* Copyright 2010-2017 JetBrains s.r.o.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import com.intellij.openapi.editor.Editor
2121
import com.intellij.openapi.project.Project
2222
import com.intellij.psi.PsiElement
2323
import com.intellij.psi.PsiFile
24-
import com.intellij.psi.util.PsiTreeUtil
2524
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
2625
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
2726
import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -31,9 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
3130

3231
class RenameBackingFieldReferenceHandler: VariableInplaceRenameHandler() {
3332
override fun isAvailable(element: PsiElement?, editor: Editor, file: PsiFile): Boolean {
34-
val refExpression = PsiTreeUtil.findElementOfClassAtOffset(
35-
file, editor.caretModel.offset, KtSimpleNameExpression::class.java, false
36-
) ?: return false
33+
val refExpression = file.findElementForRename<KtSimpleNameExpression>(editor.caretModel.offset) ?: return false
3734
if (refExpression.text != "field") return false
3835
return refExpression.analyze()[BindingContext.REFERENCE_TARGET, refExpression] is SyntheticFieldDescriptor
3936
}

0 commit comments

Comments
 (0)