Fix NPE caused by Rename Refactoring of backing field when caret is after the last character
#KT-16605 Fixed
This commit is contained in:
committed by
Alexey Sedunov
parent
1bad04db50
commit
c952e26cbb
+2
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
|
||||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
|
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
|
||||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
@@ -31,9 +30,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
|
|
||||||
class RenameBackingFieldReferenceHandler: VariableInplaceRenameHandler() {
|
class RenameBackingFieldReferenceHandler: VariableInplaceRenameHandler() {
|
||||||
override fun isAvailable(element: PsiElement?, editor: Editor, file: PsiFile): Boolean {
|
override fun isAvailable(element: PsiElement?, editor: Editor, file: PsiFile): Boolean {
|
||||||
val refExpression = PsiTreeUtil.findElementOfClassAtOffset(
|
val refExpression = file.findElementForRename<KtSimpleNameExpression>(editor.caretModel.offset) ?: return false
|
||||||
file, editor.caretModel.offset, KtSimpleNameExpression::class.java, false
|
|
||||||
) ?: return false
|
|
||||||
if (refExpression.text != "field") return false
|
if (refExpression.text != "field") return false
|
||||||
return refExpression.analyze()[BindingContext.REFERENCE_TARGET, refExpression] is SyntheticFieldDescriptor
|
return refExpression.analyze()[BindingContext.REFERENCE_TARGET, refExpression] is SyntheticFieldDescriptor
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user