mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-09 08:09:39 +07:00
[java] Update inspection description
GitOrigin-RevId: b74ce5e0a81dec057cc35df07fc1fee411adf0e7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
859ec40299
commit
e321d26a2d
@@ -307,7 +307,7 @@ inspection.same.return.value.problem.descriptor1=Method and all its derivables a
|
||||
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.surround.requirenonnull.quickfix=Replace with ''Objects.requireNonNull({0})''
|
||||
inspection.suspicious.array.method.call.display.name=Suspicious Arrays method calls
|
||||
inspection.suspicious.array.method.call.display.name=Suspicious 'Arrays' method calls
|
||||
inspection.suspicious.array.method.call.problem.arrays=Array types are incompatible: arrays are always different
|
||||
inspection.suspicious.array.method.call.problem.element=Element type is not compatible with array type
|
||||
inspection.suspicious.collections.method.calls.display.name=Suspicious collections method calls
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 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.
|
||||
// Copyright 2000-2021 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.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.BlockUtils;
|
||||
@@ -11,7 +11,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.siyeh.ig.controlflow.SwitchStatementWithTooFewBranchesInspection.UnwrapSwitchStatementFix;
|
||||
import com.siyeh.ig.controlflow.MinimumSwitchBranchesInspection.UnwrapSwitchStatementFix;
|
||||
import com.siyeh.ig.psiutils.BreakConverter;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports all fields, methods or classes, found in the specified inspection
|
||||
scope, that may have a <b><font color="#000080">final</font></b> modifier added to their declarations. <br> <br>
|
||||
Reports all fields, methods or classes, found in the specified inspection scope, that may have a <code>final</code> modifier added to their
|
||||
declarations.
|
||||
<!-- tooltip end -->
|
||||
Use check boxes in the inspection options below, to define which declarations are to be reported.
|
||||
</body>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports non-short-circuit operations consuming an infinite stream. Such operations can only be completed by throwing an exception.
|
||||
<!-- tooltip end -->
|
||||
<p>Example:</p>
|
||||
<p><code>
|
||||
<pre>
|
||||
Stream.iterate(0, i -> i + 1).collect(Collectors.toList())
|
||||
</code></p>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,24 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports enhanced <b>switch</b> statements and expressions which can be replaced with a traditional <b>switch</b> statement.
|
||||
|
||||
Reports enhanced <code>switch</code> statements and expressions, and suggest replacing them with a traditional <code>switch</code>
|
||||
statement.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
switch (condition) {
|
||||
case foo -> throw null;
|
||||
default -> b = true;
|
||||
}
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
switch (condition) {
|
||||
case foo:
|
||||
throw null;
|
||||
default ->
|
||||
bar = true;
|
||||
break;
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2019.1</small></p>
|
||||
</body>
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports if trivial lambda expression is used where there's an alternative method which behaves the same way, but
|
||||
accepts a concrete value instead of a lambda.
|
||||
<p>
|
||||
For example, <code>Optional.orElseGet(() -> null)</code> can be replaced with <code>Optional.orElse(null)</code>.
|
||||
</p>
|
||||
Reports if trivial lambda expression is used where there's an alternative method which behaves the same way, but accepts a concrete value
|
||||
instead of a lambda.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
Optional.orElseGet(() -> null)
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
Optional.orElse(null)
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.1</small></p>
|
||||
<small>New in 2017.1</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports long numeric literals without underscores.
|
||||
<p>
|
||||
Underscores make long numeric literals easier to read.
|
||||
</p>
|
||||
<p>
|
||||
The quick-fix adds underscores to the literal, for example, <code>1000000</code> becomes <code>1_000_000</code>.
|
||||
</p>
|
||||
Reports long numeric literals without underscores, and suggests adding them. Underscores make long numeric literals easier to read.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
1000000
|
||||
</pre>
|
||||
<p>After the quick fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
1_000_000
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection only applies to language level 7 or higher.</p>
|
||||
<p><small>New in 2020.2</small></p>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports common usage patterns of <code>java.util.Map</code> that could be replaced with Java 8 methods:
|
||||
Reports common usage patterns of <code>java.util.Map</code>, and suggests replacing them with:
|
||||
<code>getOrDefault()</code>, <code>computeIfAbsent()</code>, <code>putIfAbsent()</code>, <code>merge()</code>, or <code>replaceAll()</code>.
|
||||
<p>Examples:</p>
|
||||
<ul>
|
||||
@@ -34,19 +34,18 @@ Reports common usage patterns of <code>java.util.Map</code> that could be replac
|
||||
}
|
||||
</pre>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<p>Note that the replacement with <code>computeIfAbsent()</code> or <code>merge()</code> might work incorrectly for some <code>Map</code>
|
||||
implementations if the code extracted to the lambda expression modifies the same <code>Map</code>. By default,
|
||||
the warning doesn’t appear if this code might have side effects. If necessary, enable the last checkbox to always show the warning.</p>
|
||||
<p>Also, due to different handling of the <code>null</code> value in old methods like <code>put()</code> and newer methods like
|
||||
<code>computeIfAbsent()</code> or <code>merge()</code>, semantics might change if storing the <code>null</code> value into given
|
||||
<code>Map</code> is important. The inspection won't suggest the replacement when the value is statically known to be nullable,
|
||||
but for values with unknown nullability the replacement is still suggested. In these cases, we recommended suppressing the warning
|
||||
and adding an explanatory comment.
|
||||
implementations if the code extracted to the lambda expression modifies the same <code>Map</code>. By default,
|
||||
the warning doesn’t appear if this code might have side effects. If necessary, enable the last checkbox to always show the warning.</p>
|
||||
<p>Also, due to different handling of the <code>null</code> value in old methods like <code>put()</code> and newer methods like
|
||||
<code>computeIfAbsent()</code> or <code>merge()</code>, semantics might change if storing the <code>null</code> value into given
|
||||
<code>Map</code> is important. The inspection won't suggest the replacement when the value is statically known to be nullable,
|
||||
but for values with unknown nullability the replacement is still suggested. In these cases, we recommended suppressing the warning
|
||||
and adding an explanatory comment.
|
||||
</p>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection works only if the language level of the project or module is 8 or higher</p>
|
||||
<p><small>New in 2016.3</small></p>
|
||||
<p>This inspection works only if the language level of the project or module is 8 or higher.</p>
|
||||
<small>New in 2016.3</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
The inspection detects situations when a service is loaded with <code>java.util.ServiceLoader</code>
|
||||
but it isn't declared with <code>uses</code> clause in the <code>module-info.java</code> file.
|
||||
<p>
|
||||
<small>New in 2018.1</small>
|
||||
The inspection detects situations when a service is loaded with <code>java.util.ServiceLoader</code> but it isn't declared with the
|
||||
<code>uses</code> clause in the <code>module-info.java</code> file.
|
||||
<!-- tooltip end -->
|
||||
<small>New in 2018.1</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,9 +1,17 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports conditions like <code>if(Optional.isPresent())</code> which could be rewritten in functional style.
|
||||
Reports conditions like <code>if(Optional.isPresent())</code> which could be rewritten in functional style. Functional style is shorter and
|
||||
easier to read.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
if (str.isPresent()) str.get().trim();
|
||||
</pre>
|
||||
<p>After the quick fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
str.ifPresent(String::trim);
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<p>This inspection only reports if the language level of the project or module is 8 or higher</p>
|
||||
<p>This inspection only reports if the language level of the project or module is 8 or higher.</p>
|
||||
<small>New in 2016.3</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,20 @@
|
||||
<html>
|
||||
<body>
|
||||
Inspection reports unnecessary close of resource in the end of try-with-resources block
|
||||
Inspection reports unnecessary close of resource in the end of try-with-resources block, and suggests removing it.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
try(MyAutoCloseable ac = new MyAutoCloseable()) {
|
||||
foo();
|
||||
ac.close();
|
||||
}
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
try(MyAutoCloseable ac = new MyAutoCloseable()) {
|
||||
foo();
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2018.1</small></p>
|
||||
<small>New in 2018.1</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,9 +1,17 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports collectors which could be simplified. In particular some cascaded <code>groupingBy</code> collectors
|
||||
could be expressed with simpler <code>toMap</code> collector which also will likely be more performant.
|
||||
Reports collectors, and suggests simplifying them. In particular some cascaded <code>groupingBy</code> collectors could be expressed with
|
||||
simpler <code>toMap</code> collector which also will likely be more performant.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
Collectors.groupingByConcurrent(String::length, Collectors.collectingAndThen(Collectors.maxBy(String::compareTo), Optional::get));
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
Collectors.toConcurrentMap(String::length, Function.identity(), BinaryOperator.maxBy(String::compareTo));
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection only reports if the language level of the project or module is 8 or higher </p>
|
||||
<p>This inspection only reports if the language level of the project or module is 8 or higher.</p>
|
||||
<p><small>New in 2017.1</small></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,13 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports when a non-generic-array manipulation method like <code>Arrays.fill()</code> is called with mismatched argument types.
|
||||
Such a call will not do anything useful and is likely a mistake.
|
||||
Reports when a non-generic-array manipulation method like <code>Arrays.fill()</code> is called with mismatched argument types. Such a call
|
||||
will not do anything useful and is likely a mistake.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
int foo(String[] strings) {
|
||||
return Arrays.binarySearch(strings, 1);
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.2</small></p>
|
||||
</body>
|
||||
|
||||
@@ -688,7 +688,7 @@ inspection.surround.if.family=Surround with if
|
||||
inspection.surround.if.quickfix=Surround with ''if ({0}{1})''
|
||||
inspection.suspicious.list.remove.display.name=Suspicious 'List.remove()' in the loop
|
||||
inspection.switch.expression.backward.expression.migration.inspection.name='switch' expression can be replaced with old style 'switch' statement
|
||||
inspection.switch.expression.backward.migration.inspection.name=New style 'switch' can be replaced with old style one
|
||||
inspection.switch.expression.backward.migration.inspection.name=Non old style 'switch' statement
|
||||
inspection.switch.expression.backward.statement.migration.inspection.name='switch' statement can be replaced with old style 'switch' statement
|
||||
inspection.switch.expression.migration.inspection.name=Statement can be replaced with enhanced 'switch'
|
||||
inspection.switch.expression.migration.inspection.switch.description=Switch statement can be replaced with enhanced 'switch'
|
||||
@@ -1247,7 +1247,7 @@ inspection.collection.add.all.can.be.replaced.with.constructor.display.name=Redu
|
||||
inspection.manual.min.max.calculation.display.name=Manual min/max calculation
|
||||
inspection.explicit.array.filling.display.name=Explicit array filling
|
||||
inspection.java.8.collection.remove.if.display.name=Loop can be replaced with Collection.removeIf()
|
||||
inspection.java.8.map.api.display.name=Single Map method can be used
|
||||
inspection.java.8.map.api.display.name=Simplify 'Map' operations
|
||||
inspection.string.repeat.can.be.used.display.name=String.repeat() can be used
|
||||
inspection.read.write.string.can.be.used.display.name='Files.readString()' or 'Files.writeString()' can be used
|
||||
inspection.java.9.collection.factory.display.name=Immutable collection creation can be replaced with collection factory call
|
||||
@@ -1257,14 +1257,14 @@ inspection.redundant.stream.optional.call.display.name=Redundant step in Stream
|
||||
inspection.obvious.null.check.display.name=Null-check method is called with obviously non-null argument
|
||||
inspection.simplify.stream.api.call.chains.display.name=Stream API call chain can be simplified
|
||||
inspection.simplify.optional.call.chains.display.name=Optional call chain can be simplified
|
||||
inspection.simplify.collector.display.name=Collector can be simplified
|
||||
inspection.simplify.collector.display.name=Simplifiable collector
|
||||
inspection.use.bulk.operation.display.name=Bulk operation can be used instead of iteration
|
||||
inspection.comparator.combinators.display.name=Comparator combinator can be used
|
||||
inspection.replace.inefficient.stream.count.display.name=Inefficient Stream API call chains ending with count()
|
||||
inspection.redundant.lambda.parameter.type.display.name=Redundant lambda parameter types
|
||||
inspection.wrapper.type.may.be.primitive.display.name=Wrapper type may be primitive
|
||||
inspection.optional.get.without.is.present.display.name=Optional.get() is called without isPresent() check
|
||||
inspection.optional.is.present.display.name=Optional.isPresent() can be replaced with functional-style expression
|
||||
inspection.optional.is.present.display.name=Non functional Optional.isPresent() style usage
|
||||
inspection.conditional.can.be.optional.display.name=Conditional can be replaced with Optional
|
||||
inspection.optional.assigned.to.null.display.name=Null value for Optional type
|
||||
inspection.excessive.range.check.display.name=Excessive range check
|
||||
|
||||
@@ -538,7 +538,7 @@ ignore.enhanced.for.loop.statements=Ignore enhanced for loops
|
||||
thread.run.display.name=Call to 'Thread.run()'
|
||||
non.synchronized.method.overrides.synchronized.method.display.name=Unsynchronized method overrides synchronized method
|
||||
synchronize.on.this.display.name=Synchronization on 'this'
|
||||
switch.statement.with.too.many.branches.display.name='switch' statement with too many branches
|
||||
maximum.switch.branches.display.name=Maximum 'switch' branches
|
||||
utility.class.without.private.constructor.display.name=Utility class without 'private' constructor
|
||||
throw.caught.locally.display.name='throw' caught by containing 'try' statement
|
||||
exception.from.catch.which.doesnt.wrap.display.name='throw' inside 'catch' block which ignores the caught exception
|
||||
@@ -654,7 +654,7 @@ final.method.in.final.class.display.name='final' method in 'final' class
|
||||
extends.annotation.display.name=Class extends annotation interface
|
||||
naked.notify.display.name='notify()' or 'notifyAll()' without corresponding state change
|
||||
switch.statement.density.display.name='switch' statement with too low of a branch density
|
||||
switch.statement.with.too.few.branches.display.name='switch' statement with too few branches
|
||||
minimum.switch.branches.display.name=Minimum 'switch' branches
|
||||
upper.case.field.name.not.constant.display.name=Non-constant field with upper-case name
|
||||
unnecessary.label.on.continue.statement.display.name=Unnecessary label on 'continue' statement
|
||||
jdbc.prepare.statement.with.non.constant.string.display.name=Call to 'Connection.prepare*()' with non-constant string
|
||||
@@ -706,7 +706,7 @@ static.suite.display.name='suite()' method not declared 'static'
|
||||
redundant.field.initialization.display.name=Redundant field initialization
|
||||
string.buffer.to.string.in.concatenation.display.name='StringBuilder.toString()' in concatenation
|
||||
utility.class.with.public.constructor.display.name=Utility class with 'public' constructor
|
||||
for.loop.replaceable.by.while.display.name='for' loop may be replaced with 'while' loop
|
||||
for.loop.replaceable.by.while.display.name=Empty intializer or update component in 'for' loop
|
||||
missing.deprecated.annotation.display.name=Missing @Deprecated annotation
|
||||
cloneable.class.in.secure.context.display.name=Cloneable class in secure context
|
||||
static.inheritance.display.name=Static inheritance
|
||||
@@ -777,7 +777,7 @@ static.method.naming.convention.element.description='static'
|
||||
empty.try.block.display.name=Empty 'try' block
|
||||
field.has.setter.but.no.getter.display.name=Field has setter but no getter
|
||||
three.negations.per.method.display.name=Method with more than three negations
|
||||
conditional.expression.display.name=Conditional expression (?:)
|
||||
conditional.expression.display.name=Conditional expression usage (?:)
|
||||
unnecessary.enum.modifier.display.name=Unnecessary enum modifier
|
||||
string.equals.empty.string.display.name='String.equals("")'
|
||||
synchronize.on.lock.display.name=Synchronization on a Lock object
|
||||
@@ -2136,9 +2136,9 @@ single.statement.in.block.name=Code block contains single statement
|
||||
single.statement.in.block.descriptor=''{0}'' contains single statement
|
||||
single.statement.in.block.quickfix=Remove braces from ''{0}'' statement
|
||||
single.statement.in.block.family.quickfix=Remove braces from statement
|
||||
single.element.annotation.name=Single-element annotation
|
||||
single.element.annotation.quickfix=Add 'value='
|
||||
single.element.annotation.family.quickfix=Expand annotation to normal form
|
||||
shorthand.annotation.name=Non-normalized annotation
|
||||
shorthand.annotation.quickfix=Add 'value='
|
||||
shorthand.annotation.family.quickfix=Expand annotation to normal form
|
||||
array.creation.without.new.keyword.name=Array creation without 'new' expression
|
||||
array.creation.without.new.keyword.quickfix=Add ''new {0}''
|
||||
array.creation.without.new.keyword.family.quickfix=Add 'new' expression
|
||||
@@ -2278,7 +2278,8 @@ inspection.excessive.range.check.fix.family.name=Simplify excessive range check
|
||||
suspicious.integer.div.assignment.problem.descriptor=Division result is truncated to integer
|
||||
suspicious.integer.div.assignment.display.name=Suspicious integer division assignment
|
||||
suspicious.integer.div.assignment.quickfix=Cast to double
|
||||
inspection.if.statement.missing.break.in.loop.name=Loop can be terminated after condition is met
|
||||
inspection.if.statement.missing.break.in.loop.name=Early loop exit in 'if' condition
|
||||
inspection.if.statement.missing.break.in.loop.description=Loop can be terminated after condition is met
|
||||
inspection.if.statement.missing.break.in.loop.quickfix=Add 'break'
|
||||
|
||||
inspection.case.mismatch.display.name=Mismatched case in String operation
|
||||
|
||||
@@ -27,13 +27,18 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class SwitchStatementWithTooManyBranchesInspection extends BaseInspection {
|
||||
public class MaximumSwitchBranchesInspection extends BaseInspection {
|
||||
|
||||
private static final int DEFAULT_BRANCH_LIMIT = 10;
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public int m_limit = DEFAULT_BRANCH_LIMIT;
|
||||
|
||||
@Override
|
||||
public @NotNull String getShortName() {
|
||||
return "SwitchStatementWithTooManyBranches";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleIntegerFieldOptionsPanel(
|
||||
@@ -1,11 +1,10 @@
|
||||
// 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.
|
||||
// Copyright 2000-2021 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.siyeh.ig.performance;
|
||||
|
||||
import com.intellij.codeInsight.BlockUtils;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -16,13 +15,14 @@ import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.SideEffectChecker;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.tryCast;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class IfStatementMissingBreakInLoopInspection extends BaseInspection {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message("inspection.if.statement.missing.break.in.loop.name");
|
||||
return InspectionGadgetsBundle.message("inspection.if.statement.missing.break.in.loop.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -738,14 +738,16 @@
|
||||
bundle="messages.InspectionGadgetsBundle" key="switch.statement.with.confusing.declaration.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.control.flow.issues" enabledByDefault="false"
|
||||
level="WARNING" implementationClass="com.siyeh.ig.controlflow.SwitchStatementWithConfusingDeclarationInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SwitchStatementWithTooFewBranches" bundle="messages.InspectionGadgetsBundle"
|
||||
key="switch.statement.with.too.few.branches.display.name" groupBundle="messages.InspectionsBundle"
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SwitchStatementWithTooFewBranches"
|
||||
bundle="messages.InspectionGadgetsBundle"
|
||||
key="minimum.switch.branches.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.control.flow.issues" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.controlflow.SwitchStatementWithTooFewBranchesInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SwitchStatementWithTooManyBranches" bundle="messages.InspectionGadgetsBundle"
|
||||
key="switch.statement.with.too.many.branches.display.name" groupBundle="messages.InspectionsBundle"
|
||||
implementationClass="com.siyeh.ig.controlflow.MinimumSwitchBranchesInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SwitchStatementWithTooManyBranches"
|
||||
bundle="messages.InspectionGadgetsBundle"
|
||||
key="maximum.switch.branches.display.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.control.flow.issues" enabledByDefault="false" level="WARNING"
|
||||
implementationClass="com.siyeh.ig.controlflow.SwitchStatementWithTooManyBranchesInspection"/>
|
||||
implementationClass="com.siyeh.ig.controlflow.MaximumSwitchBranchesInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" suppressId="SwitchStatementWithoutDefaultBranch" shortName="SwitchStatementsWithoutDefault"
|
||||
bundle="messages.InspectionGadgetsBundle" key="switch.statements.without.default.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.control.flow.issues" enabledByDefault="true"
|
||||
@@ -2487,9 +2489,9 @@
|
||||
groupKey="group.names.code.style.issues" enabledByDefault="true" level="INFORMATION"
|
||||
implementationClass="com.siyeh.ig.exceptions.MultiCatchCanBeSplitInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="SingleElementAnnotation" bundle="messages.InspectionGadgetsBundle"
|
||||
key="single.element.annotation.name" groupBundle="messages.InspectionsBundle"
|
||||
key="shorthand.annotation.name" groupBundle="messages.InspectionsBundle"
|
||||
groupKey="group.names.code.style.issues" enabledByDefault="true" level="INFORMATION"
|
||||
implementationClass="com.siyeh.ig.annotation.SingleElementAnnotationInspection"/>
|
||||
implementationClass="com.siyeh.ig.annotation.NonNormalizedAnnotationInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="MetaAnnotationWithoutRuntimeRetention"
|
||||
bundle="messages.InspectionGadgetsBundle"
|
||||
key="meta.annotation.without.runtime.retention" groupBundle="messages.InspectionsBundle"
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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-2021 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.siyeh.ig.annotation;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.AddAnnotationAttributeNameFix;
|
||||
@@ -30,7 +16,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SingleElementAnnotationInspection extends BaseInspection {
|
||||
public class NonNormalizedAnnotationInspection extends BaseInspection {
|
||||
@Override
|
||||
public @NotNull String getShortName() {
|
||||
return "SingleElementAnnotation";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -54,14 +44,14 @@ public class SingleElementAnnotationInspection extends BaseInspection {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return InspectionGadgetsBundle.message("single.element.annotation.quickfix");
|
||||
return InspectionGadgetsBundle.message("shorthand.annotation.quickfix");
|
||||
}
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return InspectionGadgetsBundle.message("single.element.annotation.family.quickfix");
|
||||
return InspectionGadgetsBundle.message("shorthand.annotation.family.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,13 +33,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class SwitchStatementWithTooFewBranchesInspection extends BaseInspection {
|
||||
public class MinimumSwitchBranchesInspection extends BaseInspection {
|
||||
|
||||
private static final int DEFAULT_BRANCH_LIMIT = 2;
|
||||
|
||||
@SuppressWarnings("PublicField")
|
||||
public int m_limit = DEFAULT_BRANCH_LIMIT;
|
||||
|
||||
@Override
|
||||
public @NotNull String getShortName() {
|
||||
return "SwitchStatementWithTooFewBranches";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleIntegerFieldOptionsPanel(InspectionGadgetsBundle.message("switch.statement.with.too.few.branches.min.option"),
|
||||
@@ -70,10 +75,10 @@ public class SwitchStatementWithTooFewBranchesInspection extends BaseInspection
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SwitchStatementWithTooFewBranchesVisitor();
|
||||
return new MinimumSwitchBranchesVisitor();
|
||||
}
|
||||
|
||||
private class SwitchStatementWithTooFewBranchesVisitor extends BaseInspectionVisitor {
|
||||
private class MinimumSwitchBranchesVisitor extends BaseInspectionVisitor {
|
||||
@Override
|
||||
public void visitSwitchExpression(PsiSwitchExpression expression) {
|
||||
Object[] infos = processSwitch(expression);
|
||||
@@ -1,13 +1,12 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any <b>assert</b> statements
|
||||
that cause side effects outside of the assert statement. Since assertions can be
|
||||
switched off, the side effects are not guaranteed to happen and can cause subtle bugs.
|
||||
Common unwanted side effects detected by this inspection are modifications of variables
|
||||
and fields in the assert statement. Also methods called are analyzed one level deep
|
||||
for any modifications of fields.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
Reports any <code>assert</code> statements that cause side effects outside of the assert statement. Since assertions can be switched off,
|
||||
the side effects are not guaranteed to happen and can cause subtle bugs. Common unwanted side effects detected by this inspection are
|
||||
modifications of variables and fields in the assert statement. Also methods called are analyzed one level deep for any modifications of
|
||||
fields.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
assert i++ < 10;
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports JUnit 4.0 <b>@Before</b> or <b>@After</b> methods
|
||||
which are not declared
|
||||
<b>public</b>, do not return <b>void</b>, or take arguments.
|
||||
Such methods are easy to create inadvertently, but will not be executed by JUnit tests runners.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
Reports JUnit 4 <code>@Before</code> or <code>@After</code> methods which are not declared <code>public</code>, do not return
|
||||
<code>void</code>, or take arguments, ans suggests removing them. Such methods are easy to create inadvertently, but will not be executed
|
||||
by JUnit tests runners.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
@Before private int foo(int arg) { ... }
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
@Before public void foo() { ... }
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,15 +1,30 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports the ternary condition operator. Some coding standards prohibit the use of
|
||||
the condition operator, in favor of <b>if-else</b> statements.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Use the first checkbox below to ignore simple assignments and returns and thus allow constructs like this:
|
||||
Reports usage of the ternary condition operator, and suggests rewriting it as an <code>if</code>/<code>else</code> statement. Some coding
|
||||
standards prohibit the use of the condition operator.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
String s = (foo == null) ? "" : foo.toString();
|
||||
Object result = (condition) ? foo() : bar();
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
Object result;
|
||||
if (condition) {
|
||||
comp = foo();
|
||||
}
|
||||
else {
|
||||
comp = bar();
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>Use the first checkbox below to ignore simple assignments and returns and thus allow constructs like this:</p>
|
||||
<pre>
|
||||
String s = (foo == null) ? "" : foo.toString();
|
||||
</pre>
|
||||
<p>
|
||||
Use the second checkbox below to ignore conditional expression in contexts where automatic replacement with an if statement is not possible.
|
||||
For example when the conditional expression is used as an argument to a <b>super()</b> constructor call.
|
||||
Use the second checkbox below to ignore conditional expression in contexts where automatic replacement with an if statement is not
|
||||
possible.
|
||||
For example when the conditional expression is used as an argument to a <code>super()</code> constructor call.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,22 +1,22 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>for</b> loops which contain neither initialization or update components, and can thus be replaced by
|
||||
simpler <b>while</b> statements. Example:
|
||||
<pre><code>
|
||||
Reports <code>for</code> loops which contain neither initialization or update components, and suggests rewriting it as a <code>while</code>
|
||||
loop. This makes the code easier to read.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
for(; exitCondition(); ) {
|
||||
process();
|
||||
}
|
||||
</code></pre>
|
||||
This loop can be replaced with
|
||||
<pre><code>
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
while(exitCondition()) {
|
||||
process();
|
||||
}
|
||||
</code></pre>
|
||||
A fix action is also available for other <code>for</code> loops, so you can replace any <code>for</code> loop with <code>while</code>.
|
||||
</pre>
|
||||
A quick-fix action is also available for other <code>for</code> loops, so you can replace any <code>for</code> loop with <code>while</code>.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Use the checkbox below if you wish this inspection to ignore <b>for</b> loops with trivial or non-existent conditions.
|
||||
<p>Use the checkbox below if you wish this inspection to ignore <code>for</code> loops with trivial or non-existent conditions.
|
||||
<p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +1,26 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports cases in which a loop contains the <b>if</b> statement that can end with <b>break</b>.
|
||||
<p>
|
||||
For instance, consider the following code:
|
||||
<pre><code>
|
||||
<b>boolean</b> found = <b>false</b>;
|
||||
<b>for</b> (<b>int</b> i = 0; i < arr.length; i++) {
|
||||
<b>if</b> (Objects.equals(value, arr[i])) {
|
||||
found = <b>true</b>;
|
||||
Reports cases in which a loop contains the <code>if</code> statement that can end with <code>break</code> without changing the semantics.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
boolean found = false;
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (Objects.equals(value, arr[i])) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
In this case, iterations have no effect after the condition is met, and you can skip them by adding a <b>break</b>.
|
||||
<pre><code>
|
||||
<b>boolean</b> found = <b>false</b>;
|
||||
<b>for</b> (<b>int</b> i = 0; i < arr.length; i++) {
|
||||
<b>if</b> (Objects.equals(value, arr[i])) {
|
||||
found = <b>true</b>;
|
||||
<b>break</b>;
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
boolean found = false;
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (Objects.equals(value, arr[i])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<small>New in 2019.2</small>
|
||||
</p>
|
||||
<small>New in 2019.2</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,9 +1,16 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any implementations of <b>Iterator.hasNext()</b> or <b>ListIterator.hasPrevious()</b>
|
||||
that call <b>Iterator.next()</b> or <b>ListIterator.previous()</b> on themselves.
|
||||
Such calls are almost certainly in error, as methods like <b>hasNext()</b>
|
||||
should not modify the iterators state, while <b>next()</b> should.
|
||||
<!-- tooltip end -->
|
||||
Reports any implementations of <code>Iterator.hasNext()</code> or <code>ListIterator.hasPrevious()</code>
|
||||
that call <code>Iterator.next()</code> or <code>ListIterator.previous()</code> on themselves.
|
||||
Such calls are almost certainly in error, as methods like <code>hasNext()</code>
|
||||
should not modify the iterators state, while <code>next()</code> should.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
class MyIterator implements Iterator<Integer> {
|
||||
public boolean hasNext() {
|
||||
return next() != null;
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,14 +1,13 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports conditional expressions that could be simplified. Examples:
|
||||
<pre>condition ? true : foo → condition || foo</pre>
|
||||
<pre>condition ? false : foo → !condition && foo</pre>
|
||||
<pre>condition ? foo : !foo → condition == foo</pre>
|
||||
<pre>condition ? true : false → condition</pre>
|
||||
<pre>a == b ? b : a → a</pre>
|
||||
<pre>result != null ? result : null → result</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
Reports conditional expressions, and suggests simplifying it.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
condition ? true : foo
|
||||
</pre>
|
||||
<p>After the quick fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
condition || foo
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,13 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports annotations in the 'single element' shorthand form, like <code>@Retention(RUNTIME)</code>.
|
||||
<p>The quick fix for this inspection converts annotation to the 'normal' form (with attribute name),
|
||||
e.g. <code>@Retention(value=RUNTIME)</code>.
|
||||
Reports annotations in shorthand form, and suggests rewriting it to normal form (with attribute name).
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
@SuppressWarnings("foo")
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
@SuppressWarnings(value = "foo")
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any variables declared as <b>java.lang.StringBuffer</b> which may be
|
||||
more efficiently declared as <b>java.lang.StringBuilder</b>.
|
||||
<b>java.lang.StringBuilder</b> is a non-thread-safe replacement for
|
||||
<b>java.lang.StringBuffer</b>, available in Java 5 and newer.
|
||||
Reports any variables declared as <code>StringBuffer</code>, and suggests replacing it as a <code>StringBuilder</code>.
|
||||
<code>StringBuilder</code> is a non-thread-safe replacement for <code>StringBuffer</code>.
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection only reports if the language level of the project or module is 5 or higher</p>
|
||||
|
||||
<p>This inspection only reports if the language level of the project or module is 5 or higher.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,22 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports String concatenation in loops. As every String concatenation copies the whole String, usually it is preferable to replace
|
||||
it with explicit calls to <b>StringBuilder.append()</b> or <b>StringBuffer.append()</b>.
|
||||
Reports String concatenation in loops, and suggests using <code>StringBuilder</code> instead. As every String concatenation copies the whole
|
||||
String, usually it is preferable to replace it with explicit calls to <code>StringBuilder.append()</code> or
|
||||
<code>StringBuffer.append()</code>.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
for(int i=0; i<10; i++) {
|
||||
str += i;
|
||||
}
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
StringBuilder strBuilder = new StringBuilder(str);
|
||||
for(int i = 0; i<10; i++) {
|
||||
strBuilder.append(i);
|
||||
}
|
||||
str = strBuilder.toString();
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Sometimes quick-fix actions are available which allow you to convert <code>String</code> variable to <code>StringBuilder</code> or
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports two types of suspicious calls to <b>Collection.toArray()</b>.
|
||||
The first type is any calls where the type of the specified array argument is not of the same type as the array type to which the result is casted.
|
||||
Example:
|
||||
<pre><code>
|
||||
Reports two types of suspicious calls to <b>Collection.toArray()</b>. The first type is any calls where the type of the specified array
|
||||
argument is not of the same type as the array type to which the result is casted.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
void m(List list) {
|
||||
Number[] ns = (Number[])
|
||||
list.toArray(new String[0]);
|
||||
Number[] ns = (Number[]) list.toArray(new String[0]);
|
||||
}
|
||||
</code></pre>
|
||||
</pre>
|
||||
The second type is any calls where the type of the specified array argument does not match the type parameter of the collection declaration.
|
||||
Example:
|
||||
<pre><code>
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
void m(List<Number> list) {
|
||||
Number[] ns =
|
||||
list.toArray(new String[0]);
|
||||
Number[] ns = list.toArray(new String[0]);
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +1,25 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>switch</b> statements with too few <b>case</b> labels.
|
||||
Such statements may be more clearly expressed as <b>if</b> statements.
|
||||
Reports <code>switch</code> statements with too few <code>case</code> labels, and suggests rewriting it as <code>if</code> and
|
||||
<code>else if</code>statements.
|
||||
<p>Example (minimum branches == 3):</p>
|
||||
<pre>
|
||||
switch (expression) {
|
||||
case "foo" -> foo();
|
||||
case "bar" -> bar();
|
||||
}
|
||||
</pre>
|
||||
<p>After the quick-fix is applied the result looks like:</p>
|
||||
<pre>
|
||||
if ("foo".equals(expression)) {
|
||||
foo();
|
||||
}
|
||||
else if ("bar".equals(expression)) {
|
||||
bar();
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>Use the field below to specify the minimum number of <code>case</code> labels expected.
|
||||
<p>
|
||||
Use the field below to specify the minimum number of <b>case</b> labels expected.
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,8 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>switch</b> statements with too many <b>case</b> labels.
|
||||
Reports <code>switch</code> statements with too many <code>case</code> labels.
|
||||
<!-- tooltip end -->
|
||||
<p>Use the field below to specify the maximum number of <code>case</code> labels expected.
|
||||
<p>
|
||||
Use the field below to specify the maximum number of <b>case</b> labels expected.
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports synchronization on a call to <b>getClass()</b>.
|
||||
If the class containing the synchronization is subclassed, the subclass will synchronize on a different class object.
|
||||
Usually the call to <b>getClass()</b> can be replaced with a class literal expression, for example <b>String.class</b>.
|
||||
An even better solution is synchronizing on a <b>private static final</b> lock object, access to which can be completely controlled.
|
||||
Reports synchronization on a call to <code>getClass()</code>. If the class containing the synchronization is subclassed, the subclass will
|
||||
synchronize on a different class object. Usually the call to <code>getClass()</code> can be replaced with a class literal expression, for
|
||||
example <code>String.class</code>. An even better solution is synchronizing on a <code>private static final</code> lock object, access to
|
||||
which can be completely controlled.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
synchronized(getClass()) {}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<small>New in 2016.2</small>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports synchronization on a local variable or parameter.
|
||||
It is very difficult to guarantee correctness when such synchronization is used.
|
||||
It may be possible to improve code like this by controlling access through e.g. a synchronized wrapper class,
|
||||
or by synchronizing on a field.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Reports synchronization on a local variable or parameter. It is very difficult to guarantee correctness when such synchronization is used.
|
||||
It may be possible to improve code like this by controlling access through e.g. a synchronized wrapper class, or by synchronizing on a
|
||||
field.
|
||||
<p>Example:</p>
|
||||
<pre>
|
||||
void bar() {
|
||||
final Object lock = new Object();
|
||||
synchronized (lock) { }
|
||||
}
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
There are two styles to convert a collection to an array: either using a pre-sized array
|
||||
(like <b>c.toArray(new String[c.size()])</b>) or using an empty array (like
|
||||
<b>c.toArray(new String[0])</b>.
|
||||
Reports the usage of <code>Collection.toArray()</code> calls depending on different styles, and suggests applying the preferred style.
|
||||
|
||||
<p>
|
||||
There are two styles to convert a collection to an array: either using a pre-sized array
|
||||
(like <code>c.toArray(new String[c.size()])</code>) or using an empty array (like
|
||||
<code>c.toArray(new String[0])</code>.
|
||||
In older Java versions using pre-sized array was recommended, as the reflection
|
||||
call which is necessary to create an array of proper size was quite slow.
|
||||
However since late updates of OpenJDK 6 this call was intrinsified, making
|
||||
the performance of the empty array version the same and sometimes even better, compared
|
||||
to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or
|
||||
synchronized collection as a data race is possible between the <b>size</b> and <b>toArray</b>
|
||||
synchronized collection as a data race is possible between the <code>size</code> and <code>toArray</code>
|
||||
call which may result in extra nulls at the end of the array, if the collection was concurrently
|
||||
shrunk during the operation.
|
||||
</p>
|
||||
<p>
|
||||
This inspection allows to follow the uniform style: either using an empty array
|
||||
(which is recommended in modern Java)
|
||||
or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).
|
||||
</p>
|
||||
<!-- tooltip end -->
|
||||
<p>Use the radio button below to select the preferred style.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.siyeh.igtest.controlflow.switch_statement_with_too_few_branches;
|
||||
|
||||
class SwitchStatementWithTooFewBranches {
|
||||
class MinimumSwitchBranches {
|
||||
|
||||
void foo(int i) {
|
||||
switch (i) {}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 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.
|
||||
// Copyright 2000-2021 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.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class SwitchStatementWithTooManyBranchesInspectionTest extends LightJavaInspectionTestCase {
|
||||
public class MaximumSwitchBranchesInspectionTest extends LightJavaInspectionTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
doMemberTest(" public void foo(int x) {\n" +
|
||||
@@ -111,6 +111,6 @@ public class SwitchStatementWithTooManyBranchesInspectionTest extends LightJavaI
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new SwitchStatementWithTooManyBranchesInspection();
|
||||
return new MaximumSwitchBranchesInspection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2021 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.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MinimumSwitchBranchesInspectionTest extends LightJavaInspectionTestCase {
|
||||
|
||||
public void testMinimumSwitchBranches() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new MinimumSwitchBranchesInspection();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.siyeh.ig.LightJavaInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SwitchStatementWithTooFewBranchesInspectionTest extends LightJavaInspectionTestCase {
|
||||
|
||||
public void testSwitchStatementWithTooFewBranches() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new SwitchStatementWithTooFewBranchesInspection();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
// Copyright 2000-2018 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.
|
||||
// Copyright 2000-2021 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.siyeh.ig.fixes;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.siyeh.ig.controlflow.SwitchStatementWithTooFewBranchesInspection;
|
||||
import com.siyeh.ig.controlflow.MinimumSwitchBranchesInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnwrapSwitchStatementFixTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected LocalInspectionTool @NotNull [] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[] {new SwitchStatementWithTooFewBranchesInspection()};
|
||||
return new LocalInspectionTool[]{new MinimumSwitchBranchesInspection()};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,25 +1,11 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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-2021 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.siyeh.ig.fixes.style;
|
||||
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.annotation.SingleElementAnnotationInspection;
|
||||
import com.siyeh.ig.annotation.NonNormalizedAnnotationInspection;
|
||||
|
||||
public class SingleElementAnnotationInspectionTest extends IGQuickFixesTestCase {
|
||||
public class NonNormalizedAnnotationInspectionTest extends IGQuickFixesTestCase {
|
||||
|
||||
public void testOneAttr() {
|
||||
doTest();
|
||||
@@ -64,8 +50,8 @@ public class SingleElementAnnotationInspectionTest extends IGQuickFixesTestCase
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new SingleElementAnnotationInspection());
|
||||
myDefaultHint = InspectionGadgetsBundle.message("single.element.annotation.quickfix");
|
||||
myFixture.enableInspections(new NonNormalizedAnnotationInspection());
|
||||
myDefaultHint = InspectionGadgetsBundle.message("shorthand.annotation.quickfix");
|
||||
myRelativePath = "style/expand_annotation";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user