mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] Minor fixes for IDEA-346242 Add 'minimal java version' clause automatically to inspection descriptions
1. Add features to assertion inspections 2. Remove redundant feature message from HTML descriptions 3. Display Java 1.3 and Java 1.4 version properly 4. Display several features when necessary GitOrigin-RevId: 133b46152ad8376a37aa4fd847bedf38d45f3135
This commit is contained in:
committed by
intellij-monorepo-bot
parent
274b476799
commit
f943967aec
@@ -624,5 +624,7 @@ intention.family.name.move.members.into.class=Move members into class
|
||||
chooser.popup.title.select.class.to.move.members.to=Select Target Class
|
||||
intention.family.name.move.members.to=Move members to {0}
|
||||
inspection.name.can.be.replaced.with.long.hashcode=Standard 'hashCode()' method can be used
|
||||
inspection.depends.on.the.java.feature=This inspection depends on the Java feature ''{0}'' which is available since Java {1}.
|
||||
inspection.depends.on.the.java.feature=This inspection depends on the Java feature ''{0}'', which is available since Java {1}.
|
||||
inspection.depends.on.the.java.features=This inspection depends on the following Java features:
|
||||
inspection.depends.on.the.java.features.minimal.version=These features are available since Java {0}.
|
||||
inspection.data.flow.warn.when.reading.a.value.guaranteed.to.be.constant=Warn when constant is stored in variable
|
||||
|
||||
+9
@@ -7,6 +7,7 @@ import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -39,6 +40,14 @@ public abstract class AbstractBaseJavaLocalInspectionTool extends LocalInspectio
|
||||
feature.getFeatureName(), feature.getMinimumLevel().getShortText()))
|
||||
.wrapWith("p");
|
||||
}
|
||||
else if (features.size() > 1) {
|
||||
int minimalVersion = features.stream().mapToInt(f -> f.getMinimumLevel().feature()).max().getAsInt();
|
||||
return HtmlChunk.p().children(
|
||||
HtmlChunk.text(JavaAnalysisBundle.message("inspection.depends.on.the.java.features")),
|
||||
HtmlChunk.ul().children(features.stream().map(JavaFeature::getFeatureName).sorted()
|
||||
.map((@Nls String name) -> HtmlChunk.li().addText(name)).toList()),
|
||||
HtmlChunk.text(JavaAnalysisBundle.message("inspection.depends.on.the.java.features.minimal.version", minimalVersion)));
|
||||
}
|
||||
return HtmlChunk.empty();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.JavaMethodContractUtil;
|
||||
import com.intellij.codeInspection.dataFlow.MutationSignature;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -14,6 +15,8 @@ import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class AssertWithSideEffectsInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -27,6 +30,11 @@ public final class AssertWithSideEffectsInspection extends BaseInspection {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.ASSERTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new AssertWithSideEffectsVisitor();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.PsiAssertStatement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -10,6 +11,8 @@ import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.BoolUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class ConstantAssertConditionInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -19,6 +22,11 @@ public final class ConstantAssertConditionInspection extends BaseInspection {
|
||||
"constant.assert.condition.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.ASSERTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ConstantAssertConditionVisitor();
|
||||
|
||||
@@ -15,12 +15,15 @@
|
||||
*/
|
||||
package com.siyeh.ig.jdk;
|
||||
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.PsiAssertStatement;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class AssertStatementInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@@ -30,6 +33,11 @@ public final class AssertStatementInspection extends BaseInspection {
|
||||
"statement.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.ASSERTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new AssertStatementVisitor();
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
package com.siyeh.ig.style;
|
||||
|
||||
import com.intellij.codeInspection.options.OptPane;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.codeInspection.options.OptPane.checkbox;
|
||||
import static com.intellij.codeInspection.options.OptPane.pane;
|
||||
|
||||
@@ -46,6 +49,11 @@ public final class AssertMessageNotStringInspection extends BaseInspection {
|
||||
checkbox("onlyWarnOnBoolean", InspectionGadgetsBundle.message("assert.message.not.string.only.warn.boolean.option")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.ASSERTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new AssertMessageNotStringVisitor();
|
||||
|
||||
@@ -185,7 +185,11 @@ public enum LanguageLevel {
|
||||
if (this == JDK_X) {
|
||||
return "X";
|
||||
}
|
||||
return feature() + (isPreview() ? "-preview" : "");
|
||||
int feature = feature();
|
||||
if (feature < 5) {
|
||||
return "1." + feature;
|
||||
}
|
||||
return feature + (isPreview() ? "-preview" : "");
|
||||
}
|
||||
|
||||
/** See {@link JavaVersion#parse(String)} for supported formats. */
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public final class OptionalIsPresentInspection extends AbstractBaseJavaLocalInsp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.STREAM_OPTIONAL);
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public final class LambdaCanBeMethodReferenceInspection extends AbstractBaseJava
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.LAMBDA_EXPRESSIONS);
|
||||
return Set.of(JavaFeature.LAMBDA_EXPRESSIONS, JavaFeature.METHOD_REFERENCES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class IfCanBeAssertionInspection extends BaseInspection {
|
||||
private static final CallMatcher.Simple MATCHER = CallMatcher.staticCall("com.google.common.base.Preconditions", "checkNotNull");
|
||||
@@ -33,6 +34,11 @@ public final class IfCanBeAssertionInspection extends BaseInspection {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.ASSERTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new IfToAssertionVisitor();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public final class MethodRefCanBeReplacedWithLambdaInspection extends BaseInspec
|
||||
|
||||
@Override
|
||||
public @NotNull Set<@NotNull JavaFeature> requiredFeatures() {
|
||||
return Set.of(JavaFeature.LAMBDA_EXPRESSIONS);
|
||||
return Set.of(JavaFeature.LAMBDA_EXPRESSIONS, JavaFeature.METHOD_REFERENCES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports interfaces that can be annotated with <code>@FunctionalInterface</code> (available since JDK 1.8).
|
||||
Reports interfaces that can be annotated with <code>@FunctionalInterface</code>.
|
||||
<p>Annotating an interface with <code>@FunctionalInterface</code> indicates that the interface
|
||||
is functional and no more <code>abstract</code> methods can be added to it.</p>
|
||||
<p><b>Example:</b></p>
|
||||
@@ -16,7 +16,5 @@ Reports interfaces that can be annotated with <code>@FunctionalInterface</code>
|
||||
void execute(File file);
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection only reports if the language level of the project or module is 8 or higher.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -18,7 +18,6 @@ Javadoc tag but do not have the <code>@java.lang.Deprecated</code> annotation.
|
||||
void sample(){ }
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection reports only if the language level of the project or module is 5 or higher.</p>
|
||||
<p>
|
||||
Use the checkbox below to report members annotated with <code>@Deprecated</code> without
|
||||
an explanation in a Javadoc <code>@deprecated</code> tag.
|
||||
|
||||
@@ -24,6 +24,5 @@ IntFunction<List<?>[]> fun = List[]::new;
|
||||
<li>Use the <b>Ignore parameter types of overriding methods</b> option to ignore type parameters used in parameters of overridden methods.</li>
|
||||
<li>Use the <b>Ignore when automatic quick-fix is not available</b> option to ignore the cases when a quick-fix is not available.</li>
|
||||
</ul>
|
||||
This inspection only reports if the language level of the project or module is 5 or higher.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports Stream API chains, <code>Iterable.forEach()</code>, and <code>Map.forEach()</code> calls that can be automatically converted into classical loops.
|
||||
This can help to downgrade for backward compatibility with earlier Java versions.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
String joinNonEmpty(List<String> list) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports text blocks that can be replaced with regular string literals.
|
||||
Reports text blocks that can be replaced with regular string literals.
|
||||
This may help to downgrade for backward compatibility with earlier Java versions.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
Object obj = engine.eval("""
|
||||
|
||||
@@ -18,4 +18,17 @@ public final class LanguageLevelTest {
|
||||
assertEquals(LanguageLevel.JDK_17, jdk17Preview.getNonPreviewLevel());
|
||||
assertFalse(JavaFeature.PATTERNS_IN_SWITCH.isSufficient(jdk17Preview.getNonPreviewLevel()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getShortText() {
|
||||
LanguageLevel jdk17 = LanguageLevel.JDK_17;
|
||||
assertEquals("17", jdk17.getShortText());
|
||||
//noinspection UsagesOfObsoleteApi
|
||||
LanguageLevel jdk17Preview = LanguageLevel.JDK_17_PREVIEW;
|
||||
assertEquals("17-preview", jdk17Preview.getShortText());
|
||||
LanguageLevel jdk14 = LanguageLevel.JDK_1_4;
|
||||
assertEquals("1.4", jdk14.getShortText());
|
||||
LanguageLevel jdkX = LanguageLevel.JDK_X;
|
||||
assertEquals("X", jdkX.getShortText());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user