From 1eeef6da625b75a0cd2cf6c560a6b06366c77673 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 16 Mar 2022 17:30:09 +0100 Subject: [PATCH] improve "Method always returns the same value" inspection messages GitOrigin-RevId: 20ef273a00b17991f4ff94bbbbf94be334af4e60 --- .../resources/messages/JavaAnalysisBundle.properties | 8 ++++---- .../sameReturnValue/SameReturnValueInspection.java | 8 ++++---- .../src/inspectionDescriptions/SameReturnValue.html | 11 +++++++++-- .../inspection/jvm/sameReturnValue/java/expected.xml | 6 +++--- .../jvm/sameReturnValue/kotlin/expected.xml | 4 ++-- .../inspection/jvm/sameReturnValue/mixed/expected.xml | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/java/java-analysis-api/resources/messages/JavaAnalysisBundle.properties b/java/java-analysis-api/resources/messages/JavaAnalysisBundle.properties index 7236c9de453c..e6c791dafe49 100644 --- a/java/java-analysis-api/resources/messages/JavaAnalysisBundle.properties +++ b/java/java-analysis-api/resources/messages/JavaAnalysisBundle.properties @@ -321,10 +321,10 @@ inspection.requires.auto.module.message='requires' directive for an automatic mo inspection.requires.auto.module.option=Highlight only transitive dependencies inspection.requires.auto.module.transitive='requires transitive' directive for an automatic module inspection.requires.auto.module=Dependencies on automatic modules -inspection.same.return.value.display.name=Method returns the same value -inspection.same.return.value.problem.descriptor1=Method and all its derivables always return {0} -inspection.same.return.value.problem.descriptor2=All implementations of this method always return {0} -inspection.same.return.value.problem.descriptor=Method always returns {0} +inspection.same.return.value.display.name=Method always returns the same value +inspection.same.return.value.problem.descriptor1=Method #ref() and all its overriding methods always return {0} +inspection.same.return.value.problem.descriptor2=All implementations of method #ref() always return {0} +inspection.same.return.value.problem.descriptor=Method #ref() always returns {0} inspection.surround.requirenonnull.quickfix=Replace with ''Objects.requireNonNull({0})'' inspection.suspicious.array.method.call.display.name=Suspicious 'Arrays' method call inspection.suspicious.array.method.call.problem.arrays=Array types are incompatible: arrays are always different diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java index b2f11977509e..4e58ac71d596 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/sameReturnValue/SameReturnValueInspection.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection.sameReturnValue; import com.intellij.analysis.AnalysisScope; @@ -26,11 +26,11 @@ public class SameReturnValueInspection extends GlobalJavaBatchInspectionTool { if (returnValue != null) { final String message; if (refMethod.getDerivedReferences().isEmpty()) { - message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor", "" + returnValue + ""); + message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor", returnValue); } else if (refMethod.hasBody()) { - message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor1", "" + returnValue + ""); + message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor1", returnValue); } else { - message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor2", "" + returnValue + ""); + message = JavaAnalysisBundle.message("inspection.same.return.value.problem.descriptor2", returnValue); } final UDeclaration decl = refMethod.getUastElement(); diff --git a/java/java-impl/src/inspectionDescriptions/SameReturnValue.html b/java/java-impl/src/inspectionDescriptions/SameReturnValue.html index 5fee2f2f409c..de72c24375b8 100644 --- a/java/java-impl/src/inspectionDescriptions/SameReturnValue.html +++ b/java/java-impl/src/inspectionDescriptions/SameReturnValue.html @@ -1,6 +1,13 @@ -Reports methods and method hierarchies in which the return value always appears to -be the same constant. +Reports methods and method hierarchies that always return the same constant. +

Example:

+

+  class X {
+    int xxx() {
+      return 0;
+    }
+  }
+
diff --git a/java/java-tests/testData/inspection/jvm/sameReturnValue/java/expected.xml b/java/java-tests/testData/inspection/jvm/sameReturnValue/java/expected.xml index 5b139ecd8499..72a3f27a350b 100644 --- a/java/java-tests/testData/inspection/jvm/sameReturnValue/java/expected.xml +++ b/java/java-tests/testData/inspection/jvm/sameReturnValue/java/expected.xml @@ -4,19 +4,19 @@ Test.java 3 Method returns the same value - Method always returns <code>0</code> + Method <code>xxx()</code> always returns <code>0</code> Test.java 10 Method returns the same value - Method always returns <code>0</code> + Method <code>compare()</code> always returns <code>0</code> LambdaWithSameValue.java 2 Method returns the same value - All implementations of this method always return <code>42</code> + All implementations of method <code>getResult()</code> always return <code>42</code> diff --git a/java/java-tests/testData/inspection/jvm/sameReturnValue/kotlin/expected.xml b/java/java-tests/testData/inspection/jvm/sameReturnValue/kotlin/expected.xml index 5038dd0ed1d3..6356fb3face5 100644 --- a/java/java-tests/testData/inspection/jvm/sameReturnValue/kotlin/expected.xml +++ b/java/java-tests/testData/inspection/jvm/sameReturnValue/kotlin/expected.xml @@ -4,14 +4,14 @@ Test.kt 2 Method returns the same value - Method always returns <code>0</code> + Method <code>xxx()</code> always returns <code>0</code> Test.kt 8 Method returns the same value - Method and all its derivables always return <code>foo</code> + Method <code>xxx()</code> and all its overriding methods always return <code>foo</code> diff --git a/java/java-tests/testData/inspection/jvm/sameReturnValue/mixed/expected.xml b/java/java-tests/testData/inspection/jvm/sameReturnValue/mixed/expected.xml index dbc086b34e0e..b2389b4a3f23 100644 --- a/java/java-tests/testData/inspection/jvm/sameReturnValue/mixed/expected.xml +++ b/java/java-tests/testData/inspection/jvm/sameReturnValue/mixed/expected.xml @@ -4,7 +4,7 @@ Bar.kt 2 Method returns the same value - Method and all its derivables always return <code>0</code> + Method <code>xxx()</code> and all its overriding methods always return <code>0</code>