Make IDE parts using light methods work with JetFunction
This commit is contained in:
committed by
Alexey Sedunov
parent
7d278f2f42
commit
0debd1ce6f
@@ -180,7 +180,7 @@ public class LightClassUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiMethod getLightClassMethod(@NotNull JetNamedFunction function) {
|
public static PsiMethod getLightClassMethod(@NotNull JetFunction function) {
|
||||||
return getPsiMethodWrapper(function);
|
return getPsiMethodWrapper(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ public fun JetClassOrObject.toLightClass(): KotlinLightClass? = LightClassUtil.g
|
|||||||
public fun JetDeclaration.toLightElements(): List<PsiNamedElement> =
|
public fun JetDeclaration.toLightElements(): List<PsiNamedElement> =
|
||||||
when (this) {
|
when (this) {
|
||||||
is JetClassOrObject -> Collections.singletonList(LightClassUtil.getPsiClass(this))
|
is JetClassOrObject -> Collections.singletonList(LightClassUtil.getPsiClass(this))
|
||||||
is JetNamedFunction -> Collections.singletonList(LightClassUtil.getLightClassMethod(this))
|
is JetNamedFunction,
|
||||||
|
is JetSecondaryConstructor -> Collections.singletonList(LightClassUtil.getLightClassMethod(this as JetFunction))
|
||||||
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||||
is JetPropertyAccessor -> Collections.singletonList(LightClassUtil.getLightClassAccessorMethod(this))
|
is JetPropertyAccessor -> Collections.singletonList(LightClassUtil.getLightClassAccessorMethod(this))
|
||||||
is JetParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
is JetParameter -> ArrayList<PsiNamedElement>().let { elements ->
|
||||||
@@ -44,7 +45,7 @@ public fun JetDeclaration.toLightElements(): List<PsiNamedElement> =
|
|||||||
|
|
||||||
public fun PsiElement.toLightMethods(): List<PsiMethod> =
|
public fun PsiElement.toLightMethods(): List<PsiMethod> =
|
||||||
when (this) {
|
when (this) {
|
||||||
is JetNamedFunction -> LightClassUtil.getLightClassMethod(this).singletonOrEmptyList()
|
is JetFunction -> LightClassUtil.getLightClassMethod(this).singletonOrEmptyList()
|
||||||
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||||
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).toList()
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this).singletonOrEmptyList()
|
||||||
@@ -55,7 +56,7 @@ public fun PsiElement.toLightMethods(): List<PsiMethod> =
|
|||||||
|
|
||||||
public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
||||||
when (this) {
|
when (this) {
|
||||||
is JetNamedFunction -> LightClassUtil.getLightClassMethod(this)
|
is JetFunction -> LightClassUtil.getLightClassMethod(this)
|
||||||
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
is JetProperty -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
||||||
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
is JetParameter -> LightClassUtil.getLightClassPropertyMethods(this).getGetter()
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this)
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(this)
|
||||||
@@ -72,7 +73,7 @@ public fun JetParameter.toPsiParameter(): PsiParameter? {
|
|||||||
val lightParamIndex = if (owner != null && owner.isExtensionDeclaration()) paramIndex + 1 else paramIndex
|
val lightParamIndex = if (owner != null && owner.isExtensionDeclaration()) paramIndex + 1 else paramIndex
|
||||||
|
|
||||||
val method: PsiMethod? = when (owner) {
|
val method: PsiMethod? = when (owner) {
|
||||||
is JetNamedFunction -> LightClassUtil.getLightClassMethod(owner)
|
is JetFunction -> LightClassUtil.getLightClassMethod(owner)
|
||||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
||||||
is JetClass -> LightClassUtil.getPsiClass(owner)?.getConstructors()?.let { constructors ->
|
is JetClass -> LightClassUtil.getPsiClass(owner)?.getConstructors()?.let { constructors ->
|
||||||
if (constructors.isNotEmpty()) constructors[0] else null
|
if (constructors.isNotEmpty()) constructors[0] else null
|
||||||
|
|||||||
+2
-2
@@ -98,8 +98,8 @@ public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, Re
|
|||||||
if (element instanceof JetClassOrObject) {
|
if (element instanceof JetClassOrObject) {
|
||||||
processJetClassOrObject((JetClassOrObject) element, queryParameters);
|
processJetClassOrObject((JetClassOrObject) element, queryParameters);
|
||||||
}
|
}
|
||||||
else if (element instanceof JetNamedFunction) {
|
else if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
final JetNamedFunction function = (JetNamedFunction) element;
|
final JetFunction function = (JetFunction) element;
|
||||||
String name = function.getName();
|
String name = function.getName();
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
PsiMethod method = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
PsiMethod method = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
||||||
|
|||||||
+2
-2
@@ -191,8 +191,8 @@ class FunctionUsagesSearchHelper(
|
|||||||
override val selfUsages: Boolean = true,
|
override val selfUsages: Boolean = true,
|
||||||
override val overrideUsages: Boolean = true,
|
override val overrideUsages: Boolean = true,
|
||||||
skipImports: Boolean = false
|
skipImports: Boolean = false
|
||||||
) : DefaultSearchHelper<JetNamedFunction>(skipImports), OverrideSearchHelper {
|
) : DefaultSearchHelper<JetFunction>(skipImports), OverrideSearchHelper {
|
||||||
override fun makeFilter(target: UsagesSearchTarget<JetNamedFunction>): UsagesSearchFilter {
|
override fun makeFilter(target: UsagesSearchTarget<JetFunction>): UsagesSearchFilter {
|
||||||
return (isTargetOrOverrideUsage
|
return (isTargetOrOverrideUsage
|
||||||
or isOverloadUsage.ifOrFalse(overloadUsages)
|
or isOverloadUsage.ifOrFalse(overloadUsages)
|
||||||
or isExtensionUsage.ifOrFalse(extensionUsages)) and isFilteredImport
|
or isExtensionUsage.ifOrFalse(extensionUsages)) and isFilteredImport
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
|||||||
val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor()
|
val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor()
|
||||||
if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) {
|
if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) {
|
||||||
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), delegatedPropertyGetterDescriptor)
|
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), delegatedPropertyGetterDescriptor)
|
||||||
if (function is JetNamedFunction) {
|
if (function is JetNamedFunction || function is JetSecondaryConstructor) {
|
||||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
val psiMethod = LightClassUtil.getLightClassMethod(function as JetFunction)
|
||||||
if (psiMethod != null) {
|
if (psiMethod != null) {
|
||||||
result.add(KotlinMethodSmartStepTarget(function, psiMethod, "${propertyDescriptor.getName()}.", expression, false, lines))
|
result.add(KotlinMethodSmartStepTarget(function, psiMethod, "${propertyDescriptor.getName()}.", expression, false, lines))
|
||||||
}
|
}
|
||||||
@@ -166,8 +166,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
|||||||
if (descriptor is CallableMemberDescriptor) {
|
if (descriptor is CallableMemberDescriptor) {
|
||||||
// TODO doesn't work for libraries
|
// TODO doesn't work for libraries
|
||||||
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), descriptor)
|
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), descriptor)
|
||||||
if (function is JetNamedFunction) {
|
if (function is JetNamedFunction || function is JetSecondaryConstructor) {
|
||||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
val psiMethod = LightClassUtil.getLightClassMethod(function as JetFunction)
|
||||||
if (psiMethod != null) {
|
if (psiMethod != null) {
|
||||||
result.add(KotlinMethodSmartStepTarget(function, psiMethod, null, expression, false, lines))
|
result.add(KotlinMethodSmartStepTarget(function, psiMethod, null, expression, false, lines))
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-12
@@ -39,19 +39,16 @@ import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchReques
|
|||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearch;
|
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearch;
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchHelper;
|
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchHelper;
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchRequest;
|
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchRequest;
|
||||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
|
||||||
import org.jetbrains.kotlin.psi.JetParameter;
|
|
||||||
import org.jetbrains.kotlin.psi.JetProperty;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaration> extends KotlinFindUsagesHandler<T> {
|
public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaration> extends KotlinFindUsagesHandler<T> {
|
||||||
private static class Function extends KotlinFindMemberUsagesHandler<JetNamedFunction> {
|
private static class Function extends KotlinFindMemberUsagesHandler<JetFunction> {
|
||||||
public Function(
|
public Function(
|
||||||
@NotNull JetNamedFunction declaration,
|
@NotNull JetFunction declaration,
|
||||||
@NotNull Collection<? extends PsiElement> elementsToSearch,
|
@NotNull Collection<? extends PsiElement> elementsToSearch,
|
||||||
@NotNull KotlinFindUsagesHandlerFactory factory
|
@NotNull KotlinFindUsagesHandlerFactory factory
|
||||||
) {
|
) {
|
||||||
@@ -59,7 +56,7 @@ public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected UsagesSearchHelper<JetNamedFunction> getSearchHelper(KotlinCallableFindUsagesOptions options) {
|
protected UsagesSearchHelper<JetFunction> getSearchHelper(KotlinCallableFindUsagesOptions options) {
|
||||||
return FindUsagesPackage.toHelper((KotlinFunctionFindUsagesOptions) options);
|
return FindUsagesPackage.toHelper((KotlinFunctionFindUsagesOptions) options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +121,8 @@ public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaratio
|
|||||||
protected abstract UsagesSearchHelper<T> getSearchHelper(KotlinCallableFindUsagesOptions options);
|
protected abstract UsagesSearchHelper<T> getSearchHelper(KotlinCallableFindUsagesOptions options);
|
||||||
|
|
||||||
private static Iterable<PsiMethod> getLightMethods(JetNamedDeclaration element) {
|
private static Iterable<PsiMethod> getLightMethods(JetNamedDeclaration element) {
|
||||||
if (element instanceof JetNamedFunction) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
PsiMethod method = LightClassUtil.getLightClassMethod((JetNamedFunction) element);
|
PsiMethod method = LightClassUtil.getLightClassMethod((JetFunction) element);
|
||||||
return method != null ? Collections.singletonList(method) : Collections.<PsiMethod>emptyList();
|
return method != null ? Collections.singletonList(method) : Collections.<PsiMethod>emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +149,7 @@ public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaratio
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
UsagesSearchRequest request =
|
UsagesSearchRequest request =
|
||||||
getSearchHelper(kotlinOptions).newRequest(FindUsagesPackage.toSearchTarget(options, (T) element, true));
|
getSearchHelper(kotlinOptions).newRequest(FindUsagesPackage.<T>toSearchTarget(options, (T) element, true));
|
||||||
|
|
||||||
for (PsiReference ref : UsagesSearch.INSTANCE$.search(request)) {
|
for (PsiReference ref : UsagesSearch.INSTANCE$.search(request)) {
|
||||||
processUsage(processor, ref);
|
processUsage(processor, ref);
|
||||||
@@ -189,8 +186,8 @@ public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaratio
|
|||||||
@NotNull JetNamedDeclaration declaration,
|
@NotNull JetNamedDeclaration declaration,
|
||||||
@NotNull Collection<? extends PsiElement> elementsToSearch,
|
@NotNull Collection<? extends PsiElement> elementsToSearch,
|
||||||
@NotNull KotlinFindUsagesHandlerFactory factory) {
|
@NotNull KotlinFindUsagesHandlerFactory factory) {
|
||||||
return declaration instanceof JetNamedFunction
|
return declaration instanceof JetFunction
|
||||||
? new Function((JetNamedFunction) declaration, elementsToSearch, factory)
|
? new Function((JetFunction) declaration, elementsToSearch, factory)
|
||||||
: new Property(declaration, elementsToSearch, factory);
|
: new Property(declaration, elementsToSearch, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ public abstract class KotlinCallTreeStructure extends HierarchyTreeStructure {
|
|||||||
return (PsiMethod) element;
|
return (PsiMethod) element;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetNamedFunction) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
return LightClassUtil.getLightClassMethod((JetNamedFunction) element);
|
return LightClassUtil.getLightClassMethod((JetFunction) element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
|
|||||||
+2
-2
@@ -103,8 +103,8 @@ public class KotlinCallerMethodsTreeStructure extends KotlinCallTreeStructure {
|
|||||||
Collections.singleton((PsiMethod) element), descriptor, methodToDescriptorMap, searchScope, true
|
Collections.singleton((PsiMethod) element), descriptor, methodToDescriptorMap, searchScope, true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (element instanceof JetNamedFunction) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
PsiMethod lightMethod = LightClassUtil.getLightClassMethod((JetNamedFunction) element);
|
PsiMethod lightMethod = LightClassUtil.getLightClassMethod((JetFunction) element);
|
||||||
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
processPsiMethodCallers(Collections.singleton(lightMethod), descriptor, methodToDescriptorMap, searchScope, false);
|
||||||
}
|
}
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
|
|||||||
@@ -16,15 +16,17 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.highlighter.markers
|
package org.jetbrains.kotlin.idea.highlighter.markers
|
||||||
|
|
||||||
import java.util.HashSet
|
|
||||||
import com.intellij.psi.PsiMethod
|
|
||||||
import com.intellij.psi.PsiClass
|
|
||||||
import com.intellij.psi.CommonClassNames
|
|
||||||
import com.intellij.openapi.progress.ProgressManager
|
import com.intellij.openapi.progress.ProgressManager
|
||||||
|
import com.intellij.psi.CommonClassNames
|
||||||
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.psi.JetClass
|
import com.intellij.psi.PsiMethod
|
||||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||||
|
import org.jetbrains.kotlin.psi.JetClass
|
||||||
|
import org.jetbrains.kotlin.psi.JetFunction
|
||||||
import org.jetbrains.kotlin.psi.JetNamedFunction
|
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
import org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||||
|
import java.util.HashSet
|
||||||
|
|
||||||
fun collectContainingClasses(methods: Collection<PsiMethod>): Set<PsiClass> {
|
fun collectContainingClasses(methods: Collection<PsiMethod>): Set<PsiClass> {
|
||||||
val classes = HashSet<PsiClass>()
|
val classes = HashSet<PsiClass>()
|
||||||
@@ -50,11 +52,11 @@ private fun getPsiClass(element: PsiElement?): PsiClass? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getPsiMethod(element: PsiElement?): PsiMethod? {
|
private fun getPsiMethod(element: PsiElement?): PsiMethod? {
|
||||||
|
val parent = element?.getParent()
|
||||||
return when {
|
return when {
|
||||||
element == null -> null
|
element == null -> null
|
||||||
element is PsiMethod -> element
|
element is PsiMethod -> element
|
||||||
element.getParent() is JetNamedFunction ->
|
parent is JetNamedFunction, parent is JetSecondaryConstructor -> LightClassUtil.getLightClassMethod(parent as JetFunction)
|
||||||
LightClassUtil.getLightClassMethod(element.getParent() as JetNamedFunction)
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ import com.intellij.codeInsight.FileModificationService
|
|||||||
import com.intellij.codeInsight.daemon.QuickFixBundle
|
import com.intellij.codeInsight.daemon.QuickFixBundle
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.*
|
||||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection
|
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection
|
||||||
import com.intellij.codeInspection.ex.EntryPointsManager
|
|
||||||
import com.intellij.codeInspection.ex.EntryPointsManagerImpl
|
import com.intellij.codeInspection.ex.EntryPointsManagerImpl
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.project.ProjectUtil
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
@@ -64,7 +62,7 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
val lightElement: PsiElement? = when (declaration) {
|
val lightElement: PsiElement? = when (declaration) {
|
||||||
is JetClassOrObject -> declaration.toLightClass()
|
is JetClassOrObject -> declaration.toLightClass()
|
||||||
is JetNamedFunction -> LightClassUtil.getLightClassMethod(declaration)
|
is JetNamedFunction, is JetSecondaryConstructor -> LightClassUtil.getLightClassMethod(declaration as JetFunction)
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return lightElement != null && javaInspection.isEntryPoint(lightElement)
|
return lightElement != null && javaInspection.isEntryPoint(lightElement)
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ public class JetChangeSignatureData(
|
|||||||
|
|
||||||
override val affectedFunctions: Collection<UsageInfo> by Delegates.lazy {
|
override val affectedFunctions: Collection<UsageInfo> by Delegates.lazy {
|
||||||
primaryFunctions + primaryFunctions.flatMapTo(HashSet<UsageInfo>()) { primaryFunction ->
|
primaryFunctions + primaryFunctions.flatMapTo(HashSet<UsageInfo>()) { primaryFunction ->
|
||||||
val primaryDeclaration = primaryFunction.getDeclaration() as? JetNamedFunction
|
val primaryDeclaration = primaryFunction.getDeclaration() as? JetFunction
|
||||||
val lightMethod = primaryDeclaration?.let { LightClassUtil.getLightClassMethod(it) }
|
val lightMethod = primaryDeclaration?.let { LightClassUtil.getLightClassMethod(it) }
|
||||||
val overrides = lightMethod?.let { OverridingMethodsSearch.search(it).findAll() } ?: Collections.emptyList()
|
val overrides = lightMethod?.let { OverridingMethodsSearch.search(it).findAll() } ?: Collections.emptyList()
|
||||||
overrides.map { method ->
|
overrides.map { method ->
|
||||||
|
|||||||
+8
-4
@@ -20,12 +20,14 @@ import com.intellij.openapi.editor.Editor
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiMethod
|
import com.intellij.psi.PsiMethod
|
||||||
import com.intellij.psi.search.SearchScope
|
import com.intellij.psi.search.SearchScope
|
||||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
|
||||||
import org.jetbrains.kotlin.psi.JetNamedFunction
|
|
||||||
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
import com.intellij.refactoring.rename.RenameJavaMethodProcessor
|
||||||
import org.jetbrains.kotlin.asJava.KotlinLightMethod
|
import org.jetbrains.kotlin.asJava.KotlinLightMethod
|
||||||
import kotlin.properties.Delegates
|
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
|
import org.jetbrains.kotlin.psi.JetFunction
|
||||||
|
import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
import org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
public class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
public class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||||
private val javaMethodProcessorInstance by Delegates.lazy {
|
private val javaMethodProcessorInstance by Delegates.lazy {
|
||||||
@@ -61,7 +63,9 @@ public class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
|||||||
|
|
||||||
private fun wrapPsiMethod(element: PsiElement?): PsiMethod? = when (element) {
|
private fun wrapPsiMethod(element: PsiElement?): PsiMethod? = when (element) {
|
||||||
is KotlinLightMethod -> element
|
is KotlinLightMethod -> element
|
||||||
is JetNamedFunction -> runReadAction { LightClassUtil.getLightClassMethod(element) }
|
is JetNamedFunction, is JetSecondaryConstructor -> runReadAction {
|
||||||
|
LightClassUtil.getLightClassMethod(element as JetFunction)
|
||||||
|
}
|
||||||
else -> throw IllegalStateException("Can't be for element $element there because of canProcessElement()")
|
else -> throw IllegalStateException("Can't be for element $element there because of canProcessElement()")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -38,10 +38,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetAnnotationsIndex;
|
import org.jetbrains.kotlin.idea.stubindex.JetAnnotationsIndex;
|
||||||
import org.jetbrains.kotlin.psi.JetAnnotationEntry;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.psi.JetClass;
|
|
||||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
|
||||||
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
|
|
||||||
@@ -84,8 +81,8 @@ public class KotlinAnnotatedElementsSearcher extends AnnotatedElementsSearcher {
|
|||||||
PsiClass lightClass = LightClassUtil.getPsiClass((JetClass) parentOfType);
|
PsiClass lightClass = LightClassUtil.getPsiClass((JetClass) parentOfType);
|
||||||
consumer.process(lightClass);
|
consumer.process(lightClass);
|
||||||
}
|
}
|
||||||
else if (parentOfType instanceof JetNamedFunction) {
|
else if (parentOfType instanceof JetNamedFunction || parentOfType instanceof JetSecondaryConstructor) {
|
||||||
PsiMethod wrappedMethod = LightClassUtil.getLightClassMethod((JetNamedFunction) parentOfType);
|
PsiMethod wrappedMethod = LightClassUtil.getLightClassMethod((JetFunction) parentOfType);
|
||||||
consumer.process(wrappedMethod);
|
consumer.process(wrappedMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -43,8 +43,8 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
return processClassImplementations((JetClass) element, consumer);
|
return processClassImplementations((JetClass) element, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetNamedFunction) {
|
if (element instanceof JetNamedFunction || element instanceof JetSecondaryConstructor) {
|
||||||
return processFunctionImplementations((JetNamedFunction) element, scope, consumer);
|
return processFunctionImplementations((JetFunction) element, scope, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
@@ -74,7 +74,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean processFunctionImplementations(final JetNamedFunction function, SearchScope scope, Processor<PsiElement> consumer) {
|
private static boolean processFunctionImplementations(final JetFunction function, SearchScope scope, Processor<PsiElement> consumer) {
|
||||||
PsiMethod psiMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
PsiMethod psiMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
||||||
@Override
|
@Override
|
||||||
public PsiMethod compute() {
|
public PsiMethod compute() {
|
||||||
|
|||||||
Reference in New Issue
Block a user