[KT-79319] fix: resolve NullPointerException in Kotlin imports
diff --git a/plugins/lombok/lombok.k2/src/org/jetbrains/kotlin/lombok/k2/generators/AbstractBuilderGenerator.kt b/plugins/lombok/lombok.k2/src/org/jetbrains/kotlin/lombok/k2/generators/AbstractBuilderGenerator.kt index 6a7219b..c0088b8 100644 --- a/plugins/lombok/lombok.k2/src/org/jetbrains/kotlin/lombok/k2/generators/AbstractBuilderGenerator.kt +++ b/plugins/lombok/lombok.k2/src/org/jetbrains/kotlin/lombok/k2/generators/AbstractBuilderGenerator.kt
@@ -259,8 +259,8 @@ @OptIn(SymbolInternals::class) private fun extractBuilderWithDeclarations(classSymbol: FirClassSymbol<*>): List<BuilderWithDeclaration<T>>? { + val annotationSymbol = annotationClassId.toSymbol(session) as? FirRegularClassSymbol ?: return emptyList() return buildList { - val annotationSymbol = annotationClassId.toSymbol(session) as FirRegularClassSymbol val allowedTargets = annotationSymbol.fir.getAllowedAnnotationTargets(session) if (allowedTargets.contains(KotlinTarget.CLASS)) {
diff --git a/plugins/lombok/testData/diagnostics/javaConstantImport.kt b/plugins/lombok/testData/diagnostics/javaConstantImport.kt new file mode 100644 index 0000000..cb71772 --- /dev/null +++ b/plugins/lombok/testData/diagnostics/javaConstantImport.kt
@@ -0,0 +1,40 @@ +// FIR_IDENTICAL + +// FILE: JavaConstant.java + +public class JavaConstant { + private JavaConstant() { + throw new AssertionError("Utility class should not be instantiated"); + } + public static String CONST = "CONST"; +} + +// FILE: LombokExample.java + +import lombok.Builder; + +@Builder +public class LombokExample { + private String name; + private int age; +} + +// FILE: test.kt + +import JavaConstant.CONST +import LombokExample + +data class Context( + val id: String, +) + +fun test() { + val context = Context("test") + println(CONST) + + // Use Lombok builder to ensure the builder generator is triggered + val example = LombokExample.builder() + .name("Test") + .age(25) + .build() +} \ No newline at end of file
diff --git a/test-project/pom.xml b/test-project/pom.xml new file mode 100644 index 0000000..51d3f14 --- /dev/null +++ b/test-project/pom.xml
@@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>bzh.zomzog.poc</groupId> + <artifactId>k220</artifactId> + <version>1.0-SNAPSHOT</version> + + <properties> + <java.version>17</java.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <kotlin.code.style>official</kotlin.code.style> + <kotlin.compiler.jvmTarget>17</kotlin.compiler.jvmTarget> + <kotlin.version>2.2.0</kotlin.version> + <lombok.version>1.18.38</lombok.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib</artifactId> + <version>${kotlin.version}</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-maven-plugin</artifactId> + <version>${kotlin.version}</version> + <executions> + <execution> + <id>compile</id> + <goals> + <goal>compile</goal> + </goals> + <configuration> + <sourceDirs> + <source>src/main/java</source> + <source>src/main/kotlin</source> + <source>src/main/resources</source> + </sourceDirs> + </configuration> + </execution> + </executions> + <configuration> + <args> + <arg>-Xjsr305=strict</arg> + <arg>-java-parameters</arg> + </args> + <jvmTarget>${java.version}</jvmTarget> + <compilerPlugins> + <plugin>lombok</plugin> + </compilerPlugins> + </configuration> + <dependencies> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-maven-lombok</artifactId> + <version>${kotlin.version}</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>${lombok.version}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file
diff --git a/test-project/src/main/java/bzh/zomzog/poc/k220/JavaConstant.java b/test-project/src/main/java/bzh/zomzog/poc/k220/JavaConstant.java new file mode 100644 index 0000000..b5cdd9d --- /dev/null +++ b/test-project/src/main/java/bzh/zomzog/poc/k220/JavaConstant.java
@@ -0,0 +1,8 @@ +package bzh.zomzog.poc.k220; + +public class JavaConstant { + private JavaConstant() { + throw new AssertionError("Utility class should not be instantiated"); + } + public static String CONST = "CONST"; +} \ No newline at end of file
diff --git a/test-project/src/main/kotlin/bzh/zomzog/poc/k220/Context.kt b/test-project/src/main/kotlin/bzh/zomzog/poc/k220/Context.kt new file mode 100644 index 0000000..b00c3bd --- /dev/null +++ b/test-project/src/main/kotlin/bzh/zomzog/poc/k220/Context.kt
@@ -0,0 +1,7 @@ +package bzh.zomzog.poc.k220 + +import bzh.zomzog.poc.k220.JavaConstant.CONST + +data class Context( + val id: String, +) \ No newline at end of file