Fix SyntheticPropertyUsages tests
testJavaGetterToOrdinaryMethod_JavaGetterToOrdinaryMethod testSyntheticPropertyUsages1_RenameGetMethod from 192 disabled to call findReferences(elem), so overload does not worked
This commit is contained in:
+15
-5
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiMethod
|
import com.intellij.psi.PsiMethod
|
||||||
import com.intellij.psi.PsiReference
|
import com.intellij.psi.PsiReference
|
||||||
import com.intellij.psi.PsiType
|
import com.intellij.psi.PsiType
|
||||||
|
import com.intellij.psi.search.SearchScope
|
||||||
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||||
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
|
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
|
||||||
@@ -20,19 +21,28 @@ import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.utils.ifEmpty
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
|
|
||||||
class KotlinAwareJavaGetterRenameProcessor : RenameJavaMethodProcessor() {
|
class KotlinAwareJavaGetterRenameProcessor : RenameJavaMethodProcessor() {
|
||||||
override fun canProcessElement(element: PsiElement) = element is PsiMethod && element !is KtLightMethod && JvmAbi.isGetterName(element.name)
|
override fun canProcessElement(element: PsiElement) =
|
||||||
|
element is PsiMethod && element !is KtLightMethod && JvmAbi.isGetterName(element.name)
|
||||||
|
|
||||||
override fun findReferences(element: PsiElement): MutableCollection<PsiReference> {
|
override fun findReferences(
|
||||||
val getterReferences = super.findReferences(element)
|
element: PsiElement,
|
||||||
|
searchScope: SearchScope,
|
||||||
|
searchInCommentsAndStrings: Boolean
|
||||||
|
): Collection<PsiReference> {
|
||||||
|
val getterReferences = super.findReferences(element, searchScope, searchInCommentsAndStrings)
|
||||||
val getter = element as? PsiMethod ?: return getterReferences
|
val getter = element as? PsiMethod ?: return getterReferences
|
||||||
val propertyName = SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(Name.identifier(getter.name)) ?: return getterReferences
|
val propertyName = SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(Name.identifier(getter.name))
|
||||||
|
?: return getterReferences
|
||||||
val setterName = JvmAbi.setterName(propertyName.asString())
|
val setterName = JvmAbi.setterName(propertyName.asString())
|
||||||
val containingClass = getter.containingClass ?: return getterReferences
|
val containingClass = getter.containingClass ?: return getterReferences
|
||||||
KotlinFUSLogger.log(FUSEventGroups.Refactoring, this::class.java.name)
|
KotlinFUSLogger.log(FUSEventGroups.Refactoring, this::class.java.name)
|
||||||
val setterReferences = containingClass
|
val setterReferences = containingClass
|
||||||
.findMethodsByName(setterName, true)
|
.findMethodsByName(setterName, true)
|
||||||
.filter { it.parameters.size == 1 && it.returnType == PsiType.VOID }
|
.filter { it.parameters.size == 1 && it.returnType == PsiType.VOID }
|
||||||
.flatMap { super.findReferences(it).filterIsInstance<SyntheticPropertyAccessorReference.Setter>() }
|
.flatMap {
|
||||||
|
super.findReferences(it, searchScope, searchInCommentsAndStrings)
|
||||||
|
.filterIsInstance<SyntheticPropertyAccessorReference.Setter>()
|
||||||
|
}
|
||||||
.ifEmpty { return getterReferences }
|
.ifEmpty { return getterReferences }
|
||||||
return ArrayList<PsiReference>(getterReferences.size + setterReferences.size).apply {
|
return ArrayList<PsiReference>(getterReferences.size + setterReferences.size).apply {
|
||||||
addAll(getterReferences)
|
addAll(getterReferences)
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.refactoring.rename
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
|
import com.intellij.psi.PsiReference
|
||||||
|
import com.intellij.psi.PsiType
|
||||||
|
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
||||||
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||||
|
import org.jetbrains.kotlin.idea.references.SyntheticPropertyAccessorReference
|
||||||
|
import org.jetbrains.kotlin.idea.statistics.FUSEventGroups
|
||||||
|
import org.jetbrains.kotlin.idea.statistics.KotlinFUSLogger
|
||||||
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.utils.ifEmpty
|
||||||
|
|
||||||
|
class KotlinAwareJavaGetterRenameProcessor : RenameJavaMethodProcessor() {
|
||||||
|
override fun canProcessElement(element: PsiElement) = element is PsiMethod && element !is KtLightMethod && JvmAbi.isGetterName(element.name)
|
||||||
|
|
||||||
|
override fun findReferences(element: PsiElement): MutableCollection<PsiReference> {
|
||||||
|
val getterReferences = super.findReferences(element)
|
||||||
|
val getter = element as? PsiMethod ?: return getterReferences
|
||||||
|
val propertyName = SyntheticJavaPropertyDescriptor.propertyNameByGetMethodName(Name.identifier(getter.name)) ?: return getterReferences
|
||||||
|
val setterName = JvmAbi.setterName(propertyName.asString())
|
||||||
|
val containingClass = getter.containingClass ?: return getterReferences
|
||||||
|
KotlinFUSLogger.log(FUSEventGroups.Refactoring, this::class.java.name)
|
||||||
|
val setterReferences = containingClass
|
||||||
|
.findMethodsByName(setterName, true)
|
||||||
|
.filter { it.parameters.size == 1 && it.returnType == PsiType.VOID }
|
||||||
|
.flatMap { super.findReferences(it).filterIsInstance<SyntheticPropertyAccessorReference.Setter>() }
|
||||||
|
.ifEmpty { return getterReferences }
|
||||||
|
return ArrayList<PsiReference>(getterReferences.size + setterReferences.size).apply {
|
||||||
|
addAll(getterReferences)
|
||||||
|
setterReferences.mapTo(this) { SyntheticPropertyAccessorReference.Getter(it.expression) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user