From 326fdbdc342e620549d5f978e29f7ebadab91076 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 6 Feb 2026 17:08:05 +0100 Subject: [PATCH] IJPL-19723 [test]: simplify GitOrigin-RevId: 932c2b7a78bbe6f85a2d7689372032958b785999 --- .../additionalEmptySuppressor/expected.xml | 55 +++++++++++++ .../additionalEmptySuppressor/src/x/X.java | 77 +++++++++++++++++++ .../codeInspection/RedundantSuppressTest.java | 54 ++++--------- 3 files changed, 149 insertions(+), 37 deletions(-) create mode 100644 java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/src/x/X.java diff --git a/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/expected.xml b/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/expected.xml new file mode 100644 index 000000000000..2297f77f6bdc --- /dev/null +++ b/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/expected.xml @@ -0,0 +1,55 @@ + + + + + X.java + 5 + Redundant suppression + Redundant suppression + + + + + X.java + 42 + Redundant suppression + Redundant suppression + + + + + X.java + 53 + Redundant suppression + Redundant suppression + + + + + + X.java + 20 + Redundant suppression + Redundant suppression + + + + + + X.java + 30 + Redundant suppression + Redundant suppression + + + + + + X.java + 11 + Redundant suppression + Redundant suppression + + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/src/x/X.java b/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/src/x/X.java new file mode 100644 index 000000000000..17c2cedcc248 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantSuppress/additionalEmptySuppressor/src/x/X.java @@ -0,0 +1,77 @@ +package x; + +class S { + public void f() { + //noinspection HardCodedStringLiteral + String s=null; + //noinspection unused, HardCodedStringLiteral + String s2="sssssss"; + } + @SuppressWarnings({"HardCodedStringLiteral"}) + void g() { + String s = null; + } + @SuppressWarnings({"HardCodedStringLiteral"}) + void g2() { + String s = "sssssss"; + } + + void h() { + @SuppressWarnings({"HardCodedStringLiteral"}) + String s = null; + } + void h2() { + @SuppressWarnings({"HardCodedStringLiteral"}) + String s = "sssssss"; + } + + void i() { + @SuppressWarnings({"HardCodedStringLiteral"}) + class ss { + String s = null; + } + } + void i2() { + @SuppressWarnings({"HardCodedStringLiteral"}) + class ss { + String s = "sssssss"; + } + } + + /** @noinspection HardCodedStringLiteral */ + void j() { + String s = null; + } + /** @noinspection HardCodedStringLiteral */ + void j2() { + String s = "sssssss"; + } + + void k() { + class ss { + /** @noinspection HardCodedStringLiteral */ + String s = null; + } + } + void k2() { + class ss { + /** @noinspection HardCodedStringLiteral */ + String s = "sssssss"; + } + } + + @SuppressWarnings({"EmptyMethod"}) + void foo() {} + + @SuppressWarnings({"EmptyMethod"}) + void foo1() {String f;} + + @SuppressWarnings("unknown") + void fooUnknownSuppression() {} + +} + +@SuppressWarnings("UnnecessaryUnicodeEscape") +class UnicodeEscapeSuppressBug { + String s = "\u0062"; +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java index 90af4abeb928..c4635787457e 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/RedundantSuppressTest.java @@ -1,59 +1,42 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.codeInspection; import com.intellij.codeInsight.daemon.impl.HighlightVisitorBasedInspection; import com.intellij.codeInspection.InspectionProfile; import com.intellij.codeInspection.InspectionSuppressor; import com.intellij.codeInspection.LanguageInspectionSuppressors; -import com.intellij.codeInspection.PossibleHeapPollutionVarargsInspection; import com.intellij.codeInspection.RedundantSuppressInspection; import com.intellij.codeInspection.SuppressQuickFix; -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; -import com.intellij.codeInspection.emptyMethod.EmptyMethodInspection; import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; import com.intellij.codeInspection.ex.InspectionToolWrapper; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.codeInspection.i18n.I18nInspection; import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection; -import com.intellij.codeInspection.miscGenerics.RawUseOfParameterizedTypeInspection; import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; import com.intellij.lang.Language; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.tree.injected.MyTestInjector; import com.intellij.testFramework.JavaInspectionTestCase; import com.intellij.testFramework.LightProjectDescriptor; -import com.siyeh.ig.dataflow.UnnecessaryLocalVariableInspection; -import com.siyeh.ig.inheritance.RefusedBequestInspection; -import com.siyeh.ig.internationalization.UnnecessaryUnicodeEscapeInspection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Unmodifiable; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; public class RedundantSuppressTest extends JavaInspectionTestCase { private GlobalInspectionToolWrapper myWrapper; + private final List> myWrappers = new ArrayList<>(); @Override protected void setUp() throws Exception { super.setUp(); - List> myInspectionToolWrappers = Arrays.asList(new LocalInspectionToolWrapper(new JavaDocReferenceInspection()), - new LocalInspectionToolWrapper(new PossibleHeapPollutionVarargsInspection()), - new LocalInspectionToolWrapper(new UncheckedWarningLocalInspection()), - new LocalInspectionToolWrapper(new I18nInspection()), - new LocalInspectionToolWrapper(new RawUseOfParameterizedTypeInspection()), - new LocalInspectionToolWrapper(new UnnecessaryLocalVariableInspection()), - new LocalInspectionToolWrapper(new UnnecessaryUnicodeEscapeInspection()), - new LocalInspectionToolWrapper(new RefusedBequestInspection()), - new GlobalInspectionToolWrapper(new EmptyMethodInspection()), - new GlobalInspectionToolWrapper(new HighlightVisitorBasedInspection().setRunAnnotators(true)), - new GlobalInspectionToolWrapper(new UnusedDeclarationInspection())); myWrapper = new GlobalInspectionToolWrapper(new RedundantSuppressInspection() { @Override protected @NotNull @Unmodifiable List> getInspectionTools(@NotNull PsiElement psiElement, @NotNull InspectionProfile profile) { - return myInspectionToolWrappers; + return myWrappers; } }); } @@ -71,37 +54,33 @@ public class RedundantSuppressTest extends JavaInspectionTestCase { } public void testModuleInfo() { + myWrappers.add(new LocalInspectionToolWrapper(new JavaDocReferenceInspection())); doTest("redundantSuppress/" + getTestName(true), myWrapper, false); } public void testDefaultFile() { + myWrappers.add(new LocalInspectionToolWrapper(new I18nInspection())); doTest(); } - public void testAlternativeIds() { - doTest(); - } + public void testAlternativeIds() { doTest(); } public void testAnnotator() { + myWrappers.add(new GlobalInspectionToolWrapper(new HighlightVisitorBasedInspection().setRunAnnotators(true))); doTest("redundantSuppress/" + getTestName(true), myWrapper, false); } - public void testIgnoreUnused() { - doTest(); - } - + public void testIgnoreUnused() { doTest(); } public void testIgnoreWithAnnotation() { doTest(); } - public void testSameSuppressIds() { doTest(); } + public void testSameSuppressIds() { + myWrappers.add(new LocalInspectionToolWrapper(new UncheckedWarningLocalInspection())); + doTest(); + } public void testSuppressAll() { - try { - ((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = true; - doTest(); - } - finally { - ((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = false; - } + ((RedundantSuppressInspection)myWrapper.getTool()).IGNORE_ALL = true; + doTest(); } public void testInjections() { @@ -123,7 +102,8 @@ public class RedundantSuppressTest extends JavaInspectionTestCase { return SuppressQuickFix.EMPTY_ARRAY; } }, getTestRootDisposable()); - doTest("redundantSuppress/defaultFile", myWrapper, true); + myWrappers.add(new LocalInspectionToolWrapper(new I18nInspection())); + doTest(); } private void doTest() {