Fixed highlight usages
This commit is contained in:
+3
-3
@@ -38,9 +38,9 @@ public class JetReferenceContributor() : PsiReferenceContributor() {
|
||||
if (it.getReferencedNameElementType() != JetTokens.IDENTIFIER) return@registerMultiProvider emptyArray()
|
||||
|
||||
when (it.access()) {
|
||||
Access.READ -> arrayOf(SyntheticPropertyAccessorReference(it, true))
|
||||
Access.WRITE -> arrayOf(SyntheticPropertyAccessorReference(it, false))
|
||||
Access.READ_WRITE -> arrayOf(SyntheticPropertyAccessorReference(it, true), SyntheticPropertyAccessorReference(it, false))
|
||||
Access.READ -> arrayOf(SyntheticPropertyAccessorReference.Getter(it))
|
||||
Access.WRITE -> arrayOf(SyntheticPropertyAccessorReference.Setter(it))
|
||||
Access.READ_WRITE -> arrayOf(SyntheticPropertyAccessorReference.Getter(it), SyntheticPropertyAccessorReference.Setter(it))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticExtensionPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) {
|
||||
sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, private val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val descriptors = super.getTargetDescriptors(context)
|
||||
if (descriptors.none { it is SyntheticExtensionPropertyDescriptor }) return emptyList()
|
||||
@@ -66,4 +66,7 @@ class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression,
|
||||
expression.getReferencedNameElement().replace(nameIdentifier)
|
||||
return expression
|
||||
}
|
||||
}
|
||||
|
||||
public class Getter(expression: JetNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, true)
|
||||
public class Setter(expression: JetNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, false)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.findUsages
|
||||
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public class KotlinReferenceUsageInfo(reference: PsiReference) : UsageInfo(reference) {
|
||||
private val referenceType = reference.javaClass
|
||||
|
||||
override fun getReference(): PsiReference? {
|
||||
val element = getElement() ?: return null
|
||||
return element.getReferences().singleOrNull { it.javaClass == referenceType }
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -43,6 +43,7 @@ import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||
import com.intellij.util.CommonProcessors
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightMethod
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.processDelegationCallConstructorUsages
|
||||
import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isInheritable
|
||||
@@ -98,7 +99,7 @@ public class KotlinFindClassUsagesHandler(
|
||||
for (constructor in constructors) {
|
||||
if (constructor !is KotlinLightMethod) continue
|
||||
constructor.processDelegationCallConstructorUsages(constructor.getUseScope()) {
|
||||
it.getCalleeExpression()?.getReference()?.let { KotlinFindUsagesHandler.processUsage(uniqueProcessor, it) }
|
||||
it.getCalleeExpression()?.mainReference?.let { KotlinFindUsagesHandler.processUsage(uniqueProcessor, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ public abstract class KotlinFindMemberUsagesHandler<T extends JetNamedDeclaratio
|
||||
: null;
|
||||
if (psiMethod != null) {
|
||||
for (PsiReference ref : MethodReferencesSearch.search(psiMethod, options.searchScope, true)) {
|
||||
processUsage(uniqueProcessor, ref.getElement());
|
||||
processUsage(uniqueProcessor, ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.findUsages.handlers;
|
||||
|
||||
import com.intellij.find.findUsages.FindUsagesHandler;
|
||||
import com.intellij.find.findUsages.FindUsagesOptions;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -27,6 +26,7 @@ import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.findUsages.KotlinFindUsagesHandlerFactory;
|
||||
import org.jetbrains.kotlin.idea.findUsages.KotlinReferenceUsageInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -62,10 +62,8 @@ public abstract class KotlinFindUsagesHandler<T extends PsiElement> extends Find
|
||||
return factory;
|
||||
}
|
||||
|
||||
protected static boolean processUsage(Processor<UsageInfo> processor, PsiReference ref) {
|
||||
if (ref == null) return true;
|
||||
TextRange rangeInElement = ref.getRangeInElement();
|
||||
return processor.process(new UsageInfo(ref.getElement(), rangeInElement.getStartOffset(), rangeInElement.getEndOffset(), false));
|
||||
protected static boolean processUsage(@NotNull Processor<UsageInfo> processor, @NotNull PsiReference ref) {
|
||||
return processor.process(new KotlinReferenceUsageInfo(ref));
|
||||
}
|
||||
|
||||
protected static boolean processUsage(@NotNull Processor<UsageInfo> processor, @NotNull PsiElement element) {
|
||||
|
||||
Reference in New Issue
Block a user