mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[uast-inspection] IDEA-365213 support suppressions for LoggingSimilarMessageInspection
GitOrigin-RevId: 2e671fb69eac1371bc1445f7ca5d03e2284e394b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cb55e944c2
commit
27264fa515
+19
-14
@@ -2,10 +2,7 @@
|
||||
package com.intellij.codeInspection.logging
|
||||
|
||||
import com.intellij.analysis.JvmAnalysisBundle
|
||||
import com.intellij.codeInspection.AbstractBaseUastLocalInspectionTool
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession
|
||||
import com.intellij.codeInspection.ProblemDescriptor
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.codeInspection.options.OptPane
|
||||
import com.intellij.java.JavaBundle
|
||||
import com.intellij.java.library.JavaLibraryUtil
|
||||
@@ -51,9 +48,11 @@ class LoggingSimilarMessageInspection : AbstractBaseUastLocalInspectionTool() {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun buildVisitor(holder: ProblemsHolder,
|
||||
isOnTheFly: Boolean,
|
||||
session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
override fun buildVisitor(
|
||||
holder: ProblemsHolder,
|
||||
isOnTheFly: Boolean,
|
||||
session: LocalInspectionToolSession,
|
||||
): PsiElementVisitor {
|
||||
val project = holder.project
|
||||
val fileModule = ModuleUtilCore.findModuleForFile(holder.file.virtualFile, project)
|
||||
if (!(JavaLibraryUtil.hasLibraryClass(fileModule, LoggingUtil.SLF4J_LOGGER) ||
|
||||
@@ -162,6 +161,8 @@ class LoggingSimilarMessageInspection : AbstractBaseUastLocalInspectionTool() {
|
||||
val result = mutableSetOf<UCallExpression>()
|
||||
file.accept(object : AbstractUastVisitor() {
|
||||
override fun visitCallExpression(node: UCallExpression): Boolean {
|
||||
val place = node.sourcePsi ?: return false
|
||||
if (SuppressionUtil.inspectionResultSuppressed(place, this@LoggingSimilarMessageInspection)) return false
|
||||
val loggerTypeSearcher = LOGGER_TYPE_SEARCHERS.mapFirst(node) ?: return false
|
||||
if (mySkipErrorLogLevel) {
|
||||
val hasSetMessage = hasSetThrowable(node, loggerTypeSearcher)
|
||||
@@ -180,8 +181,10 @@ class LoggingSimilarMessageInspection : AbstractBaseUastLocalInspectionTool() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasSetThrowable(node: UCallExpression,
|
||||
loggerType: LoggerTypeSearcher?): Boolean {
|
||||
private fun hasSetThrowable(
|
||||
node: UCallExpression,
|
||||
loggerType: LoggerTypeSearcher?,
|
||||
): Boolean {
|
||||
if (loggerType == null) {
|
||||
return false
|
||||
}
|
||||
@@ -189,10 +192,10 @@ class LoggingSimilarMessageInspection : AbstractBaseUastLocalInspectionTool() {
|
||||
return false
|
||||
}
|
||||
var currentCall = node.receiver
|
||||
for (ignore in 0..MAX_BUILDER_LENGTH) {
|
||||
(0..MAX_BUILDER_LENGTH).forEach { ignore ->
|
||||
if (currentCall is UQualifiedReferenceExpression) {
|
||||
currentCall = currentCall.selector
|
||||
continue
|
||||
return@forEach
|
||||
}
|
||||
if (currentCall !is UCallExpression) {
|
||||
return false
|
||||
@@ -322,9 +325,11 @@ private class PartHolderIterator(private val parts: List<LoggingStringPartEvalua
|
||||
|
||||
private data class MessageLog(val call: UCallExpression, val parts: List<LoggingStringPartEvaluator.PartHolder>?)
|
||||
|
||||
private fun similar(first: List<LoggingStringPartEvaluator.PartHolder>?,
|
||||
second: List<LoggingStringPartEvaluator.PartHolder>?,
|
||||
minTextLength: Int): Boolean {
|
||||
private fun similar(
|
||||
first: List<LoggingStringPartEvaluator.PartHolder>?,
|
||||
second: List<LoggingStringPartEvaluator.PartHolder>?,
|
||||
minTextLength: Int,
|
||||
): Boolean {
|
||||
if (first == null || second == null) return false
|
||||
if (first.isEmpty() || second.isEmpty()) return false
|
||||
if (first.any { it.callPart != null } || second.any { it.callPart != null }) {
|
||||
|
||||
+36
@@ -614,5 +614,41 @@ class JavaLoggingSimilarMessageInspectionTest : LoggingSimilarMessageInspectionT
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test suppressed slf4j statement`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.slf4j.*;
|
||||
class Logging {
|
||||
private static Logger LOG = LoggerFactory.getLogger(Logging.class);
|
||||
|
||||
private static void request1(String i) {
|
||||
LOG.debug("Call successful");
|
||||
}
|
||||
|
||||
private static void request2(int i) {
|
||||
//noinspection LoggingSimilarMessage
|
||||
LOG.debug("Call successful");
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test suppressed slf4j method`() {
|
||||
myFixture.testHighlighting(JvmLanguage.JAVA, """
|
||||
import org.slf4j.*;
|
||||
class Logging {
|
||||
private static Logger LOG = LoggerFactory.getLogger(Logging.class);
|
||||
|
||||
private static void request1(String i) {
|
||||
LOG.debug("Call successful");
|
||||
}
|
||||
|
||||
@SuppressWarnings("LoggingSimilarMessage")
|
||||
public static void test2() {
|
||||
LOG.debug("Call successful");
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+41
@@ -91,5 +91,46 @@ class K2LoggingSimilarMessageInspectionTest : KotlinLoggingSimilarMessageInspect
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
|
||||
fun `test suppressed slf4j statement`() {
|
||||
myFixture.testHighlighting(JvmLanguage.KOTLIN, """
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
internal object Logging {
|
||||
private val LOG: Logger = LoggerFactory.getLogger(Logging::class.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference 'java'.">java</error>)
|
||||
|
||||
private fun request1(i: String) {
|
||||
LOG.debug("Call successful")
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
@Suppress("LoggingSimilarMessage")
|
||||
LOG.debug("Call successful")
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
fun `test suppressed slf4j method`() {
|
||||
myFixture.testHighlighting(JvmLanguage.KOTLIN, """
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
internal object Logging {
|
||||
private val LOG: Logger = LoggerFactory.getLogger(Logging::class.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference 'java'.">java</error>)
|
||||
|
||||
private fun request1(i: String) {
|
||||
LOG.debug("Call successful")
|
||||
}
|
||||
|
||||
@Suppress("LoggingSimilarMessage")
|
||||
fun test2() {
|
||||
LOG.debug("Call successful")
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user