From 4ebf2bcc77866630db948b3f81060766c0743f3c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 26 Apr 2019 20:58:11 +0200 Subject: [PATCH] [java] suppressable "redundant requires statement" inspection (IDEA-205523) GitOrigin-RevId: a7591c521a9bd80f7442fa9e9e0f0d3dc2c236f6 --- ...9RedundantRequiresStatementInspection.java | 2 +- .../suppressionByAnnotation/expected.xml | 3 +++ .../suppressionByComment/expected.xml | 3 +++ .../Java9RedundantRequiresStatementTest.kt | 26 ++++++++----------- 4 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByAnnotation/expected.xml create mode 100644 java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByComment/expected.xml diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java index a7a2066a3c07..38bbadfe9291 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/Java9RedundantRequiresStatementInspection.java @@ -61,7 +61,7 @@ public class Java9RedundantRequiresStatementInspection extends GlobalJavaBatchIn isDependencyUnused(requiredModule.packagesExportedByModule, moduleImportedPackages, refJavaModule.getName())) { PsiRequiresStatement requiresStatement = ContainerUtil.find( psiJavaModule.getRequires(), statement -> requiredModuleName.equals(statement.getModuleName())); - if (requiresStatement != null) { + if (requiresStatement != null && !isSuppressedFor(requiresStatement)) { CommonProblemDescriptor descriptor = manager.createProblemDescriptor( requiresStatement, InspectionsBundle.message("inspection.redundant.requires.statement.description", requiredModuleName), diff --git a/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByAnnotation/expected.xml b/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByAnnotation/expected.xml new file mode 100644 index 000000000000..5e933496b9cf --- /dev/null +++ b/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByAnnotation/expected.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByComment/expected.xml b/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByComment/expected.xml new file mode 100644 index 000000000000..5e933496b9cf --- /dev/null +++ b/java/java-tests/testData/inspection/redundantRequiresStatement/suppressionByComment/expected.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/Java9RedundantRequiresStatementTest.kt b/java/java-tests/testSrc/com/intellij/java/codeInspection/Java9RedundantRequiresStatementTest.kt index 1bcff19f3f2b..ff24fc9c9b6c 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/Java9RedundantRequiresStatementTest.kt +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/Java9RedundantRequiresStatementTest.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInspection import com.intellij.analysis.AnalysisScope @@ -98,6 +84,16 @@ class Java9RedundantRequiresStatementTest : LightJava9ModulesCodeInsightFixtureT mainModule("module MAIN { requires java.base; }") } + fun testSuppressionByComment() { + mainClass() + mainModule("module M {\n //noinspection Java9RedundantRequiresStatement\n requires M2;\n}") + } + + fun testSuppressionByAnnotation() { + mainClass() + mainModule("@SuppressWarnings(\"Java9RedundantRequiresStatement\") module M { requires M2; }") + } + private fun mainModule(@Language("JAVA") text: String) { addFile("module-info.java", text, ModuleDescriptor.MAIN)