mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
[kotlin] Adjust referenced primary constructor on highlight reference elements
#KTIJ-20054 Fixed GitOrigin-RevId: 6fc6fd815bf6c9262aeda0bf99d170d1617ac155
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9c2b0fab6d
commit
312ff98fa8
+18
-5
@@ -2,10 +2,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.search.ideaExtensions
|
||||
|
||||
import com.intellij.codeInsight.JavaTargetElementEvaluator
|
||||
import com.intellij.codeInsight.TargetElementEvaluatorEx
|
||||
import com.intellij.codeInsight.TargetElementUtil
|
||||
import com.intellij.codeInsight.TargetElementUtilExtender
|
||||
import com.intellij.codeInsight.*
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiReference
|
||||
@@ -17,7 +15,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
|
||||
abstract class KotlinTargetElementEvaluator : TargetElementEvaluatorEx, TargetElementUtilExtender {
|
||||
abstract class KotlinTargetElementEvaluator : TargetElementEvaluatorEx2(), TargetElementEvaluatorEx, TargetElementUtilExtender {
|
||||
companion object {
|
||||
const val DO_NOT_UNWRAP_LABELED_EXPRESSION = 0x100
|
||||
const val BYPASS_IMPORT_ALIAS = 0x200
|
||||
@@ -37,6 +35,21 @@ abstract class KotlinTargetElementEvaluator : TargetElementEvaluatorEx, TargetEl
|
||||
|
||||
override fun includeSelfInGotoImplementation(element: PsiElement): Boolean = !(element is KtClass && element.isAbstract())
|
||||
|
||||
override fun adjustReferenceOrReferencedElement(
|
||||
file: PsiFile,
|
||||
editor: Editor,
|
||||
offset: Int,
|
||||
flags: Int,
|
||||
refElement: PsiElement?
|
||||
): PsiElement? {
|
||||
if (!BitUtil.isSet(flags, TargetElementUtil.LOOKUP_ITEM_ACCEPTED)) {
|
||||
if (refElement is KtConstructor<*>) {
|
||||
return refElement.getContainingClassOrObject()
|
||||
}
|
||||
}
|
||||
return refElement
|
||||
}
|
||||
|
||||
override fun getElementByReference(ref: PsiReference, flags: Int): PsiElement? {
|
||||
if (ref is KtSimpleNameReference && ref.expression is KtLabelReferenceExpression) {
|
||||
val refTarget = ref.resolve() as? KtExpression ?: return null
|
||||
|
||||
+15
@@ -23,6 +23,16 @@ public class UsageHighlightingTestGenerated extends AbstractUsageHighlightingTes
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("class.kt")
|
||||
public void testClass() throws Exception {
|
||||
runTest("testData/usageHighlighter/class.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classRef.kt")
|
||||
public void testClassRef() throws Exception {
|
||||
runTest("testData/usageHighlighter/classRef.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("destructingDeclaration.kt")
|
||||
public void testDestructingDeclaration() throws Exception {
|
||||
runTest("testData/usageHighlighter/destructingDeclaration.kt");
|
||||
@@ -107,4 +117,9 @@ public class UsageHighlightingTestGenerated extends AbstractUsageHighlightingTes
|
||||
public void testLocalVal() throws Exception {
|
||||
runTest("testData/usageHighlighter/localVal.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primaryCtor.kt")
|
||||
public void testPrimaryCtor() throws Exception {
|
||||
runTest("testData/usageHighlighter/primaryCtor.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class <info descr="null">Foo</info>(val foo: Int) // the declaration
|
||||
|
||||
fun bar() {
|
||||
<info descr="null">Foo</info>(1)
|
||||
::<info descr="null">Foo</info>
|
||||
<info descr="null">~Foo</info>::class
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class <info descr="null">Foo</info>(val foo: Int) // the declaration
|
||||
|
||||
fun bar() {
|
||||
<info descr="null">Foo</info>(1)
|
||||
::<info descr="null">~Foo</info>
|
||||
<info descr="null">Foo</info>::class
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class <info descr="null">Foo</info>(val foo: Int) // the declaration
|
||||
|
||||
fun bar() {
|
||||
<info descr="null">~Foo</info>(1)
|
||||
::<info descr="null">Foo</info>
|
||||
<info descr="null">Foo</info>::class
|
||||
}
|
||||
Reference in New Issue
Block a user