Add JetMultiDeclarationReference
A reference to component* functions
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.plugin.references
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetMultiDeclaration
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
|
||||
class JetMultiDeclarationReference(element: JetMultiDeclaration) : JetMultiReference<JetMultiDeclaration>(element) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
return expression.getEntries().map { entry ->
|
||||
//TODO: remove getOriginal
|
||||
context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)?.getCandidateDescriptor()?.getOriginal()
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
|
||||
override fun getRangeInElement(): TextRange? {
|
||||
val entries = expression.getEntries()
|
||||
if (entries.isEmpty()) {
|
||||
return TextRange.EMPTY_RANGE
|
||||
}
|
||||
val start = entries.first!!.getStartOffsetInParent()
|
||||
val end = entries.last!!.getStartOffsetInParent() + entries.last!!.getTextLength()
|
||||
return TextRange(start, end)
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,9 @@ public class JetReferenceContributor() : PsiReferenceContributor() {
|
||||
registerProvider(javaClass<JetPropertyDelegate>()) {
|
||||
JetPropertyDelegationMethodsReference(it)
|
||||
}
|
||||
registerProvider(javaClass<JetMultiDeclaration>()) {
|
||||
JetMultiDeclarationReference(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package to
|
||||
|
||||
import a.A
|
||||
import a.component1
|
||||
import a.component2
|
||||
|
||||
fun f() {
|
||||
val (a, b) = A()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
class A() {
|
||||
}
|
||||
|
||||
fun A.component1() = 1
|
||||
fun A.component2() = 2
|
||||
|
||||
<selection>fun f() {
|
||||
val (a, b) = A()
|
||||
}</selection>
|
||||
@@ -0,0 +1,13 @@
|
||||
package test
|
||||
|
||||
import dependency.*
|
||||
|
||||
fun <Int> f(l: List<Int>) {
|
||||
val (e<caret>l1, el2, el3) = l
|
||||
}
|
||||
|
||||
// MULTIRESOLVE
|
||||
// REF: (for kotlin.List<T> in dependency).component1()
|
||||
// REF: (for kotlin.List<T> in dependency).component2()
|
||||
// REF: (for kotlin.List<T> in dependency).component3()
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package dependency
|
||||
|
||||
fun <T> List<T>.component1() = get(0)
|
||||
fun <T> List<T>.component2() = get(1)
|
||||
fun <T> List<T>.component3() = get(2)
|
||||
@@ -0,0 +1,15 @@
|
||||
package a
|
||||
|
||||
class A() {
|
||||
}
|
||||
|
||||
fun A.component1() = 1
|
||||
fun A.component2() = 1
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val (a,<caret> b) = A()
|
||||
}
|
||||
|
||||
// MULTIRESOLVE
|
||||
// REF: (for A in a).component1()
|
||||
// REF: (for A in a).component2()
|
||||
@@ -0,0 +1,10 @@
|
||||
package a
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val p = Pair(1, 2)
|
||||
val (a, b<caret>) = p
|
||||
}
|
||||
|
||||
// MULTIRESOLVE
|
||||
// REF: (in kotlin.Pair).component1()
|
||||
// REF: (in kotlin.Pair).component2()
|
||||
@@ -228,6 +228,11 @@ public class InsertImportOnPasteTestGenerated extends AbstractInsertImportOnPast
|
||||
doTestCopy("idea/testData/copyPaste/imports/Local.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
doTestCopy("idea/testData/copyPaste/imports/MultiDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultiReferencePartiallyCopied.kt")
|
||||
public void testMultiReferencePartiallyCopied() throws Exception {
|
||||
doTestCopy("idea/testData/copyPaste/imports/MultiReferencePartiallyCopied.kt");
|
||||
@@ -506,6 +511,11 @@ public class InsertImportOnPasteTestGenerated extends AbstractInsertImportOnPast
|
||||
doTestCut("idea/testData/copyPaste/imports/Local.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
doTestCut("idea/testData/copyPaste/imports/MultiDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultiReferencePartiallyCopied.kt")
|
||||
public void testMultiReferencePartiallyCopied() throws Exception {
|
||||
doTestCut("idea/testData/copyPaste/imports/MultiReferencePartiallyCopied.kt");
|
||||
|
||||
@@ -142,6 +142,11 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
|
||||
doTest("idea/testData/resolve/references/JavaReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MultiDeclarationReference.kt")
|
||||
public void testMultiDeclarationReference() throws Exception {
|
||||
doTest("idea/testData/resolve/references/MultiDeclarationReference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PackageReference.kt")
|
||||
public void testPackageReference() throws Exception {
|
||||
doTest("idea/testData/resolve/references/PackageReference.kt");
|
||||
@@ -152,6 +157,11 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
|
||||
doTest("idea/testData/resolve/references/PackageReferenceInImport.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PairMultiDeclaration.kt")
|
||||
public void testPairMultiDeclaration() throws Exception {
|
||||
doTest("idea/testData/resolve/references/PairMultiDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyPlaceInClassObjectInObject.kt")
|
||||
public void testPropertyPlaceInClassObjectInObject() throws Exception {
|
||||
doTest("idea/testData/resolve/references/PropertyPlaceInClassObjectInObject.kt");
|
||||
|
||||
@@ -61,6 +61,11 @@ public class ReferenceResolveWithLibTestGenerated extends AbstractReferenceResol
|
||||
doTest("idea/testData/resolve/referenceWithLib/iteratorWithTypeParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multiDeclarationWithTypeParameters.kt")
|
||||
public void testMultiDeclarationWithTypeParameters() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceWithLib/multiDeclarationWithTypeParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClassFromLib.kt")
|
||||
public void testNestedClassFromLib() throws Exception {
|
||||
doTest("idea/testData/resolve/referenceWithLib/nestedClassFromLib.kt");
|
||||
|
||||
Reference in New Issue
Block a user