[lombok] ensure to search for fields/components with generated members in the same way as without

- but with additional secondary elements

Otherwise, kotlin usages won't be found, because no one would call MethodReferenceSearch.

Added test for kotlin+lombok setup, only k2

^KTIJ-29440 fixed

GitOrigin-RevId: a769e07571e34b8b07782f09254412c4466ad18a
This commit is contained in:
Anna Kozlova
2024-04-16 11:15:49 +02:00
committed by intellij-monorepo-bot
parent 06573f2b76
commit 16a9e35d3b
5 changed files with 69 additions and 0 deletions

1
.idea/modules.xml generated
View File

@@ -1459,6 +1459,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/jvm-debugger/util/kotlin.jvm-debugger.util.iml" filepath="$PROJECT_DIR$/plugins/kotlin/jvm-debugger/util/kotlin.jvm-debugger.util.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/jvm-decompiler/kotlin.jvm-decompiler.iml" filepath="$PROJECT_DIR$/plugins/kotlin/jvm-decompiler/kotlin.jvm-decompiler.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/k2-fe10-bindings/kotlin.k2.fe10-bindings.iml" filepath="$PROJECT_DIR$/plugins/kotlin/k2-fe10-bindings/kotlin.k2.fe10-bindings.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/kotlin.lombok.tests/kotlin.k2.lombok.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/kotlin.lombok.tests/kotlin.k2.lombok.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/maven/kotlin.maven.iml" filepath="$PROJECT_DIR$/plugins/kotlin/maven/kotlin.maven.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/migration/kotlin.migration.iml" filepath="$PROJECT_DIR$/plugins/kotlin/migration/kotlin.migration.iml" />

View File

@@ -56,5 +56,6 @@
<orderEntry type="module" module-name="kotlin.j2k.k2.tests" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.code-insight.fixes.k2.tests" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.gradle.gradle-java.tests.k2" />
<orderEntry type="module" module-name="kotlin.k2.lombok.tests" />
</component>
</module>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlin.plugin.k2" scope="TEST" />
<orderEntry type="module" module-name="kotlin.tests-common" scope="TEST" />
<orderEntry type="module" module-name="kotlin.test-framework" scope="TEST" />
<orderEntry type="module" module-name="intellij.lombok" scope="TEST" />
</component>
</module>

View File

@@ -0,0 +1,41 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.findUsages
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
import de.plushnikov.intellij.plugin.LombokTestUtil
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
class KotlinLombokFindUsages: KotlinLightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor {
return LombokTestUtil.LOMBOK_NEW_DESCRIPTOR
}
override fun isFirPlugin(): Boolean {
return true
}
fun testFindUsagesForSetter() {
val aClass = myFixture.addClass(
"""import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class SomeJavaClass {
private int someValue;
}"""
)
myFixture.addFileToProject("usage.kt", """
fun main(val a: SomeJavaClass) {
a.someValue = 10
}
""".trimIndent())
val field = aClass.fields[0]
val usages = (myFixture as CodeInsightTestFixtureImpl).findUsages(field)
assertNotEmpty(usages)
}
}

View File

@@ -2,6 +2,8 @@ package de.plushnikov.intellij.plugin.extension;
import com.intellij.find.findUsages.FindUsagesHandler;
import com.intellij.find.findUsages.FindUsagesHandlerFactory;
import com.intellij.find.findUsages.FindUsagesOptions;
import com.intellij.find.findUsages.JavaFindUsagesHelper;
import com.intellij.openapi.project.DumbService;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
@@ -9,6 +11,8 @@ import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiRecordComponent;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.usageView.UsageInfo;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import de.plushnikov.intellij.plugin.psi.LombokLightClassBuilder;
import de.plushnikov.intellij.plugin.psi.LombokLightFieldBuilder;
@@ -44,6 +48,13 @@ public final class LombokFieldFindUsagesHandlerFactory extends FindUsagesHandler
@Override
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
return new FindUsagesHandler(element) {
@Override
public boolean processElementUsages(@NotNull PsiElement element,
@NotNull Processor<? super UsageInfo> processor,
@NotNull FindUsagesOptions options) {
return JavaFindUsagesHelper.processElementUsages(element, options, processor);
}
@Override
public PsiElement @NotNull [] getSecondaryElements() {
final PsiMember psiMember = (PsiMember)getPsiElement();