|
16 | 16 | *******************************************************************************/ |
17 | 17 | package org.jetbrains.kotlin.core.references |
18 | 18 |
|
19 | | -import com.intellij.psi.PsiElement |
20 | | -import org.jetbrains.kotlin.psi.KtSimpleNameExpression |
21 | | -import org.jetbrains.kotlin.resolve.BindingContext |
| 19 | +import com.intellij.util.SmartList |
22 | 20 | import org.jetbrains.kotlin.descriptors.DeclarationDescriptor |
23 | | -import org.jetbrains.kotlin.psi.KtReferenceExpression |
24 | | -import org.jetbrains.kotlin.descriptors.PackageViewDescriptor |
25 | | -import org.jetbrains.kotlin.core.resolve.EclipseDescriptorUtils |
26 | | -import org.jetbrains.kotlin.descriptors.SourceElement |
27 | | -import org.jetbrains.kotlin.psi.KtCallExpression |
| 21 | +import org.jetbrains.kotlin.descriptors.FunctionDescriptor |
| 22 | +import org.jetbrains.kotlin.lexer.KtTokens |
| 23 | +import org.jetbrains.kotlin.name.Name |
| 24 | +import org.jetbrains.kotlin.psi.* |
| 25 | +import org.jetbrains.kotlin.resolve.BindingContext |
28 | 26 | import org.jetbrains.kotlin.resolve.calls.callUtil.getCall |
29 | 27 | import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall |
30 | 28 | import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall |
31 | | -import org.jetbrains.kotlin.psi.Call |
32 | | -import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression |
33 | | -import org.eclipse.jdt.core.IJavaProject |
34 | | -import org.jetbrains.kotlin.psi.KtElement |
35 | | -import java.util.ArrayList |
36 | | -import org.jetbrains.kotlin.psi.KtNameReferenceExpression |
37 | 29 | import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor |
38 | | -import com.intellij.util.SmartList |
39 | | -import org.jetbrains.kotlin.descriptors.FunctionDescriptor |
| 30 | +import org.jetbrains.kotlin.types.expressions.OperatorConventions |
| 31 | +import org.jetbrains.kotlin.util.OperatorNameConventions |
40 | 32 | import org.jetbrains.kotlin.utils.addIfNotNull |
41 | | -import org.jetbrains.kotlin.lexer.KtTokens |
| 33 | +import java.util.* |
42 | 34 |
|
43 | 35 | inline private fun <reified T> ArrayList<KotlinReference>.register(e: KtElement, action: (T) -> KotlinReference) { |
44 | 36 | if (e is T) this.add(action(e)) |
@@ -74,13 +66,42 @@ public interface KotlinReference { |
74 | 66 | val expression: KtReferenceExpression |
75 | 67 |
|
76 | 68 | fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> |
| 69 | + |
| 70 | + val resolvesByNames: Collection<Name> |
77 | 71 | } |
78 | 72 |
|
79 | 73 | open class KotlinSimpleNameReference(override val expression: KtSimpleNameExpression) : KotlinReference { |
80 | 74 | override fun getTargetDescriptors(context: BindingContext) = expression.getReferenceTargets(context) |
| 75 | + |
| 76 | + override val resolvesByNames: Collection<Name> |
| 77 | + get() { |
| 78 | + val element = expression |
| 79 | + |
| 80 | + if (element is KtOperationReferenceExpression) { |
| 81 | + val tokenType = element.operationSignTokenType |
| 82 | + if (tokenType != null) { |
| 83 | + val name = OperatorConventions.getNameForOperationSymbol( |
| 84 | + tokenType, element.parent is KtUnaryExpression, element.parent is KtBinaryExpression |
| 85 | + ) ?: return emptyList() |
| 86 | + val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[tokenType] |
| 87 | + return if (counterpart != null) { |
| 88 | + val counterpartName = OperatorConventions.getNameForOperationSymbol(counterpart, false, true)!! |
| 89 | + listOf(name, counterpartName) |
| 90 | + } |
| 91 | + else { |
| 92 | + listOf(name) |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + return listOf(element.getReferencedNameAsName()) |
| 98 | + } |
81 | 99 | } |
82 | 100 |
|
83 | 101 | public class KotlinInvokeFunctionReference(override val expression: KtCallExpression) : KotlinReference { |
| 102 | + override val resolvesByNames: Collection<Name> |
| 103 | + get() = listOf(OperatorNameConventions.INVOKE) |
| 104 | + |
84 | 105 | override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> { |
85 | 106 | val call = expression.getCall(context) |
86 | 107 | val resolvedCall = call.getResolvedCall(context) |
@@ -110,13 +131,19 @@ sealed class KotlinSyntheticPropertyAccessorReference(override val expression: K |
110 | 131 | } |
111 | 132 | return result |
112 | 133 | } |
| 134 | + |
| 135 | + override val resolvesByNames: Collection<Name> |
| 136 | + get() = listOf(expression.getReferencedNameAsName()) |
113 | 137 |
|
114 | 138 | class Getter(expression: KtNameReferenceExpression) : KotlinSyntheticPropertyAccessorReference(expression, true) |
115 | 139 | class Setter(expression: KtNameReferenceExpression) : KotlinSyntheticPropertyAccessorReference(expression, false) |
116 | 140 | } |
117 | 141 |
|
118 | 142 | public class KotlinConstructorDelegationReference(override val expression: KtConstructorDelegationReferenceExpression) : KotlinReference { |
119 | 143 | override fun getTargetDescriptors(context: BindingContext) = expression.getReferenceTargets(context) |
| 144 | + |
| 145 | + override val resolvesByNames: Collection<Name> |
| 146 | + get() = emptyList() |
120 | 147 | } |
121 | 148 |
|
122 | 149 | fun KtReferenceExpression.getReferenceTargets(context: BindingContext): Collection<DeclarationDescriptor> { |
|
0 commit comments