KT-6820 Find usages doesn't find delegated properties when searching get/set/propertyDelegated functions

#KT-6820 fixed
This commit is contained in:
Evgeny Gerashchenko
2015-03-04 19:34:36 +03:00
parent 0a824edace
commit 8ba15937f9
12 changed files with 65 additions and 32 deletions
@@ -59,7 +59,7 @@ public class DelegatedPropertyResolver {
private CallResolver callResolver;
private KotlinBuiltIns builtIns;
private static final String PD_METHOD_NAME = "propertyDelegated";
public static final Name PROPERTY_DELEGATED_FUNCTION_NAME = Name.identifier("propertyDelegated");
@Inject
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
@@ -147,13 +147,12 @@ public class DelegatedPropertyResolver {
List<JetExpression> arguments = Lists.newArrayList();
JetPsiFactory psiFactory = JetPsiFactory(delegateExpression);
arguments.add(createExpressionForPropertyMetadata(psiFactory, propertyDescriptor));
Name functionName = Name.identifier(PD_METHOD_NAME);
JetReferenceExpression fakeCalleeExpression = psiFactory.createSimpleName(functionName.asString());
JetReferenceExpression fakeCalleeExpression = psiFactory.createSimpleName(PROPERTY_DELEGATED_FUNCTION_NAME.asString());
ExpressionReceiver receiver = new ExpressionReceiver(delegateExpression, delegateType);
Call call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT);
OverloadResolutionResults<FunctionDescriptor> functionResults =
callResolver.resolveCallWithGivenName(context, call, fakeCalleeExpression, functionName);
callResolver.resolveCallWithGivenName(context, call, fakeCalleeExpression, PROPERTY_DELEGATED_FUNCTION_NAME);
if (!functionResults.isSuccess()) {
String expectedFunction = renderCall(call, traceToResolvePDMethod.getBindingContext());
@@ -390,6 +390,7 @@ usageType.implicit.get = Implicit 'get'
usageType.implicit.set = Implicit 'set'
usageType.implicit.invoke = Implicit 'invoke'
usageType.implicit.iteration = Implicit iteration
usageType.property.delegation = Property delegation
usageType.extension.receiver.type = Extension receiver type
usageType.super.type.qualifier = Super type qualifier
usageType.receiver = Receiver
@@ -17,40 +17,13 @@
package org.jetbrains.kotlin.idea.findUsages
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.psi.JetForExpression
import org.jetbrains.kotlin.psi.JetMultiDeclaration
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import org.jetbrains.kotlin.psi.JetReferenceExpression
import org.jetbrains.kotlin.psi.JetImportDirective
import org.jetbrains.kotlin.psi.JetCallableReferenceExpression
import org.jetbrains.kotlin.psi.JetProperty
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
import org.jetbrains.kotlin.psi.JetFunction
import org.jetbrains.kotlin.psi.JetTypeParameter
import org.jetbrains.kotlin.psi.JetTypeConstraint
import org.jetbrains.kotlin.psi.JetDelegationSpecifier
import org.jetbrains.kotlin.psi.JetTypedef
import org.jetbrains.kotlin.psi.JetTypeProjection
import org.jetbrains.kotlin.psi.JetParameter
import org.jetbrains.kotlin.psi.JetIsExpression
import org.jetbrains.kotlin.psi.JetBinaryExpressionWithTypeRHS
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.JetDotQualifiedExpression
import org.jetbrains.kotlin.psi.JetSuperExpression
import org.jetbrains.kotlin.psi.JetDelegatorByExpressionSpecifier
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypesAndPredicate
import org.jetbrains.kotlin.psi.JetBinaryExpression
import org.jetbrains.kotlin.psi.JetPsiUtil
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.psi.JetAnnotationEntry
import org.jetbrains.kotlin.psi.JetCallExpression
import org.jetbrains.kotlin.psi.JetUnaryExpression
import org.jetbrains.kotlin.psi.JetWhenConditionInRange
import org.jetbrains.kotlin.psi.JetPackageDirective
import org.jetbrains.kotlin.psi.JetQualifiedExpression
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
@@ -62,6 +35,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
import org.jetbrains.kotlin.idea.references.JetArrayAccessReference
import org.jetbrains.kotlin.idea.references.JetInvokeFunctionReference
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
public object UsageTypeUtils {
@@ -69,6 +43,7 @@ public object UsageTypeUtils {
when (element) {
is JetForExpression -> return IMPLICIT_ITERATION
is JetMultiDeclaration -> return READ
is JetPropertyDelegate -> return PROPERTY_DELEGATION
}
val refExpr = element.getNonStrictParentOfType<JetReferenceExpression>()
@@ -262,6 +237,7 @@ enum class UsageTypeEnum {
IMPLICIT_SET
IMPLICIT_INVOKE
IMPLICIT_ITERATION
PROPERTY_DELEGATION
RECEIVER
DELEGATE
@@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.lexer.JetSingleValueToken
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
import org.jetbrains.kotlin.resolve.*
public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
.builder<JetToken>()
@@ -59,7 +60,8 @@ public fun Name.getOperationSymbolsToSearch(): Set<JetToken> {
IDENTITY_EQUALS -> return IDENTITY_EQUALS_OPERATIONS
CONTAINS -> return IN_OPERATIONS_TO_SEARCH
ITERATOR_OPERATION_NAME -> return ImmutableSet.of<JetToken>(JetTokens.IN_KEYWORD)
in INDEXING_OPERATION_NAMES -> return ImmutableSet.of<JetToken>(JetTokens.LBRACKET)
in INDEXING_OPERATION_NAMES -> return ImmutableSet.of<JetToken>(JetTokens.LBRACKET, JetTokens.BY_KEYWORD)
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return ImmutableSet.of<JetToken>(JetTokens.BY_KEYWORD)
}
if (isComponentLike(this)) return ImmutableSet.of<JetToken>(JetTokens.LPAR)
@@ -52,6 +52,7 @@ public object JetUsageTypeProvider : UsageTypeProviderEx {
IMPLICIT_SET -> JetUsageTypes.IMPLICIT_SET
IMPLICIT_INVOKE -> JetUsageTypes.IMPLICIT_INVOKE
IMPLICIT_ITERATION -> JetUsageTypes.IMPLICIT_ITERATION
PROPERTY_DELEGATION -> JetUsageTypes.PROPERTY_DELEGATION
RECEIVER -> JetUsageTypes.RECEIVER
DELEGATE -> JetUsageTypes.DELEGATE
@@ -92,6 +93,7 @@ object JetUsageTypes {
val IMPLICIT_SET = UsageType(JetBundle.message("usageType.implicit.set"))
val IMPLICIT_INVOKE = UsageType(JetBundle.message("usageType.implicit.invoke"))
val IMPLICIT_ITERATION = UsageType(JetBundle.message("usageType.implicit.iteration"))
val PROPERTY_DELEGATION = UsageType(JetBundle.message("usageType.property.delegation"))
// values
val RECEIVER = UsageType(JetBundle.message("usageType.receiver"))
@@ -0,0 +1,8 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
// OPTIONS: usages
class Delegate() {
fun <caret>get(thisRef: Any?, propertyMetadata: PropertyMetadata): String = ":)"
}
val p: String by Delegate()
@@ -0,0 +1 @@
Property delegation (8: 15) val p: String by Delegate()
@@ -0,0 +1,13 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
// OPTIONS: usages
class Delegate() {
fun get(thisRef: Any?, propertyMetadata: PropertyMetadata): String = ":)"
fun set(thisRef: Any?, propertyMetadata: PropertyMetadata, value: String) {
}
fun <caret>propertyDelegated(propertyMetadata: PropertyMetadata) {
}
}
var p: String by Delegate()
@@ -0,0 +1 @@
Property delegation (13: 15) var p: String by Delegate()
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
// OPTIONS: usages
class Delegate() {
fun get(thisRef: Any?, propertyMetadata: PropertyMetadata): String = ":)"
fun <caret>set(thisRef: Any?, propertyMetadata: PropertyMetadata, value: String) {
}
}
var p: String by Delegate()
@@ -0,0 +1 @@
Property delegation (11: 15) var p: String by Delegate()
@@ -106,6 +106,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("getAsPropertyDelegate.0.kt")
public void testGetAsPropertyDelegate() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/getAsPropertyDelegate.0.kt");
doTest(fileName);
}
@TestMetadata("identityEquals.0.kt")
public void testIdentityEquals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/identityEquals.0.kt");
@@ -136,12 +142,24 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("propertyDelegatedFunction.0.kt")
public void testPropertyDelegatedFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/propertyDelegatedFunction.0.kt");
doTest(fileName);
}
@TestMetadata("set.0.kt")
public void testSet() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/set.0.kt");
doTest(fileName);
}
@TestMetadata("setAsPropertyDelegate.0.kt")
public void testSetAsPropertyDelegate() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/setAsPropertyDelegate.0.kt");
doTest(fileName);
}
@TestMetadata("unaryMinus.0.kt")
public void testUnaryMinus() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/unaryMinus.0.kt");