mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
KTIJ-33395 [kotlin] Add test for using Lombok-annotated java classes in from different Kotlin module
Currently it yields `UNRESOLVED_REFERENCE` and `MISSING_DEPENDENCY_CLASS` errors (cherry picked from commit 997b9a131a0bb47d4dcc96828f09d537869611f7) # Conflicts: # community/plugins/kotlin/kotlin.lombok.tests/BUILD.bazel GitOrigin-RevId: 44e71fdd19ab88b9b36a5a853a4b3b884e5ca461
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9506123029
commit
e19383c20e
@@ -23,6 +23,7 @@ jvm_library(
|
||||
"//plugins/kotlin/base/test:kotlin-base-test_test_lib",
|
||||
"//plugins/kotlin/base/plugin:kotlin-base-plugin",
|
||||
"//plugins/kotlin/base/plugin:kotlin-base-plugin_test_lib",
|
||||
"//java/openapi:java",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="intellij.lombok" scope="TEST" />
|
||||
<orderEntry type="module" module-name="kotlin.base.test" scope="TEST" />
|
||||
<orderEntry type="module" module-name="kotlin.base.plugin" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.java" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.highlighter
|
||||
|
||||
import com.intellij.openapi.module.JavaModuleType
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.DependencyScope
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
|
||||
import com.intellij.testFramework.fixtures.MavenDependencyUtil
|
||||
import de.plushnikov.intellij.plugin.LombokTestUtil
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||
import org.jetbrains.kotlin.idea.test.ExpectedPluginModeProvider
|
||||
import org.jetbrains.kotlin.idea.test.setUpWithKotlinPlugin
|
||||
|
||||
internal class KotlinWithLombokHighlighting : JavaCodeInsightFixtureTestCase(), ExpectedPluginModeProvider {
|
||||
override val pluginMode: KotlinPluginMode
|
||||
get() = KotlinPluginMode.K2
|
||||
|
||||
private val sdk: Sdk
|
||||
get() = LombokTestUtil.LOMBOK_DESCRIPTOR.sdk ?: error("Lombok SDK is not found")
|
||||
|
||||
override fun setUp() {
|
||||
setUpWithKotlinPlugin(testRootDisposable) { super.setUp() }
|
||||
LombokTestUtil.LOMBOK_DESCRIPTOR.registerSdk(testRootDisposable)
|
||||
}
|
||||
|
||||
fun `test using lombok classes from java module in kotlin module without lombok compiler plugin`() {
|
||||
val javaWithLombokModule = PsiTestUtil.addModule(
|
||||
project,
|
||||
JavaModuleType.getModuleType(),
|
||||
"javaWithLombokModule",
|
||||
myFixture.tempDirFixture.findOrCreateDir("javaWithLombokModule"),
|
||||
)
|
||||
|
||||
@Language("JAVA")
|
||||
val javaDataClassText = """
|
||||
package lib;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UserDataClass {
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val javaDataClass = myFixture.addFileToProject(
|
||||
"javaWithLombokModule/lib/UserDataClass.java",
|
||||
javaDataClassText,
|
||||
)
|
||||
|
||||
myFixture.allowTreeAccessForFile(javaDataClass.virtualFile)
|
||||
|
||||
ConfigLibraryUtil.configureSdk(javaWithLombokModule, sdk)
|
||||
ModuleRootModificationUtil.modifyModel(javaWithLombokModule) { model ->
|
||||
MavenDependencyUtil.addFromMaven(
|
||||
model,
|
||||
LombokTestUtil.LOMBOK_MAVEN_COORDINATES,
|
||||
/* includeTransitiveDependencies = */ true,
|
||||
DependencyScope.PROVIDED,
|
||||
)
|
||||
true
|
||||
}
|
||||
|
||||
val kotlinModule = PsiTestUtil.addModule(
|
||||
project,
|
||||
JavaModuleType.getModuleType(),
|
||||
"kotlinModule",
|
||||
myFixture.tempDirFixture.findOrCreateDir("kotlinModule"),
|
||||
)
|
||||
|
||||
@Language("kotlin")
|
||||
val kotlinMainText = """
|
||||
package main
|
||||
|
||||
import lib.UserDataClass
|
||||
|
||||
fun useConstructor() {
|
||||
UserDataClass("hello", 10)
|
||||
}
|
||||
|
||||
fun useProperties(user: UserDataClass) {
|
||||
println(user.name)
|
||||
println(user.age)
|
||||
}
|
||||
|
||||
fun createBuilder(): UserDataClass {
|
||||
return UserDataClass.<error descr="[MISSING_DEPENDENCY_CLASS] Cannot access class 'UserDataClass.UserDataClassBuilder'. Check your module classpath for missing or conflicting dependencies.">builder</error>().<error descr="[UNRESOLVED_REFERENCE] Unresolved reference 'name'.">name</error>("hello").age(10).build()
|
||||
}
|
||||
|
||||
fun useBuilder(userBuilder: UserDataClass.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference 'UserDataClassBuilder'.">UserDataClassBuilder</error>): UserDataClass {
|
||||
return userBuilder.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference 'name'.">name</error>("hello").age(10).build()
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val kotlinMainFile = myFixture.addFileToProject(
|
||||
"kotlinModule/Main.kt",
|
||||
kotlinMainText,
|
||||
)
|
||||
|
||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(kotlinModule, sdk)
|
||||
ModuleRootModificationUtil.addDependency(kotlinModule, javaWithLombokModule)
|
||||
|
||||
myFixture.openFileInEditor(kotlinMainFile.virtualFile)
|
||||
myFixture.checkHighlighting()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user