From 577923605c1966addaf255f3bb55b4e92485c81a Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Thu, 20 Jul 2023 11:56:22 +0200 Subject: [PATCH] [kotlin] KTIJ-18022 Don't report usages of internal Kotlin declarations from JavaDoc of classes in other modules GitOrigin-RevId: 6b9f79f1a5fe57677b3f0ed82191b60c89acb908 --- .../KotlinInternalInJavaInspection.kt | 6 ++++- .../before/A/src/test.java | 4 ++- .../kotlinInternalInJava/expected.xml | 26 +++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinInternalInJavaInspection.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinInternalInJavaInspection.kt index 47e12f354b2e..0120b942787a 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinInternalInJavaInspection.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinInternalInJavaInspection.kt @@ -5,13 +5,14 @@ package org.jetbrains.kotlin.idea.inspections import com.intellij.codeInspection.LocalInspectionTool import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.* +import com.intellij.psi.javadoc.PsiInlineDocTag +import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.asJava.elements.KtLightElement import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.base.util.module import org.jetbrains.kotlin.lexer.KtTokens.INTERNAL_KEYWORD import org.jetbrains.kotlin.psi.KtModifierListOwner - class KotlinInternalInJavaInspection : LocalInspectionTool() { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { return object : JavaElementVisitor() { @@ -33,6 +34,9 @@ class KotlinInternalInJavaInspection : LocalInspectionTool() { } if (modifierListOwner.hasModifier(INTERNAL_KEYWORD)) { + // ignore JavaDoc @link references + if (PsiTreeUtil.getParentOfType(this, PsiInlineDocTag::class.java) != null) return + holder.registerProblem(this, KotlinBundle.message("usage.of.kotlin.internal.declaration.from.different.module")) } } diff --git a/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/before/A/src/test.java b/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/before/A/src/test.java index 7901a490090e..d84258f2b8e9 100644 --- a/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/before/A/src/test.java +++ b/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/before/A/src/test.java @@ -3,7 +3,9 @@ import kotlin.collections.MapsKt; import kotlin.internal.PlatformImplementations; // Internal in stdlib, error import java.util.function.Consumer; - +/** + * {@link SomeInternalClassInOtherModule} + */ public class SomeClass extends PlatformImplementations { // Internal in stdlib, error public static void doSomething() { PlatformImplementations a; // Internal in stdlib, error diff --git a/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/expected.xml b/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/expected.xml index 7a83f9a08f70..710c8f714d9e 100644 --- a/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/expected.xml +++ b/plugins/kotlin/idea/tests/testData/multiFileInspections/kotlinInternalInJava/expected.xml @@ -9,16 +9,6 @@ Usage of Kotlin internal declaration from different module - - test.java - 7 - A - <default> - - Usage of Kotlin internal declarations from Java - Usage of Kotlin internal declaration from different module - - test.java 9 @@ -41,7 +31,7 @@ test.java - 12 + 13 A <default> @@ -51,7 +41,7 @@ test.java - 15 + 14 A <default> @@ -61,7 +51,17 @@ test.java - 15 + 17 + A + <default> + + Usage of Kotlin internal declarations from Java + Usage of Kotlin internal declaration from different module + + + + test.java + 17 A <default>