[kotlin] KTIJ-18022 Don't report usages of internal Kotlin declarations from JavaDoc of classes in other modules

GitOrigin-RevId: 6b9f79f1a5fe57677b3f0ed82191b60c89acb908
This commit is contained in:
Yuriy Artamonov
2023-07-20 11:30:18 +00:00
committed by intellij-monorepo-bot
parent 1870315023
commit 577923605c
3 changed files with 21 additions and 15 deletions
@@ -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"))
}
}
@@ -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
@@ -9,16 +9,6 @@
<description>Usage of Kotlin internal declaration from different module</description>
</problem>
<problem>
<file>test.java</file>
<line>7</line>
<module>A</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="test.java" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Usage of Kotlin internal declarations from Java</problem_class>
<description>Usage of Kotlin internal declaration from different module</description>
</problem>
<problem>
<file>test.java</file>
<line>9</line>
@@ -41,7 +31,7 @@
<problem>
<file>test.java</file>
<line>12</line>
<line>13</line>
<module>A</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="test.java" />
@@ -51,7 +41,7 @@
<problem>
<file>test.java</file>
<line>15</line>
<line>14</line>
<module>A</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="test.java" />
@@ -61,7 +51,17 @@
<problem>
<file>test.java</file>
<line>15</line>
<line>17</line>
<module>A</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="test.java" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Usage of Kotlin internal declarations from Java</problem_class>
<description>Usage of Kotlin internal declaration from different module</description>
</problem>
<problem>
<file>test.java</file>
<line>17</line>
<module>A</module>
<package>&lt;default&gt;</package>
<entry_point TYPE="file" FQNAME="test.java" />