summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2013-04-01 14:41:51 -0700
committerJean-Baptiste Queru <jbq@google.com>2013-04-01 14:41:51 -0700
commit2bd2b7c2623d4266384e890271869efc044aabff (patch)
tree0b31f50e55975b6354ed458314e17b4441bb4e17 /plugins/InspectionGadgets
parent1d526b16d476792ca7ce47616d55833115e8d6ab (diff)
downloadidea-2bd2b7c2623d4266384e890271869efc044aabff.tar.gz
Snapshot ee98b298267d0e09d2cd2f0731b6480a56dd48e7 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I4515f72af131fdea9fc6905a4dc0fe9532409a81
Diffstat (limited to 'plugins/InspectionGadgets')
-rw-r--r--plugins/InspectionGadgets/src/META-INF/plugin.xml8
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties48
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java94
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspection.java107
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java34
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspection.java35
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspection.java25
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StringConcatenationMissingWhitespaceInspection.java40
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/NonFinalUtilityClassInspection.java5
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java17
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java54
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java73
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/FallthruInSwitchStatementInspection.java20
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java165
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java22
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessNullCheckInspection.java24
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/SimplifiableEqualsExpressionInspection.java32
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/fixes/MakeClassFinalFix.java3
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoBoxingInspection.java205
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java7
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/logging/LogStatementGuardedByLogConditionInspection.java22
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java128
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspection.java24
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java276
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfStatementBranch.java22
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java55
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java8
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/migration/WhileCanBeForeachInspection.java284
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java48
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java188
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java12
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ControlFlowUtils.java3
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java15
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FormatUtils.java19
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java54
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java212
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java105
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java69
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java44
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspection.java34
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/AnnotationNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassComplexity.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassMethodCount.html5
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html9
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassComplexity.html8
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassCoupling.html5
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassInheritanceDepth.html4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassNestingDepth.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassWithoutNoArgConstructor.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ConstantNamingConvention.html7
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ConstructorCount.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/CyclomaticComplexity.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/DuplicateCondition.html3
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/EnumSwitchStatementWhichMissesCases.html3
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedClassNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedConstantNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/FieldCount.html7
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ForCanBeForeach.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/IfStatementWithTooManyBranches.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/InstanceMethodNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/InstanceVariableNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/InterfaceNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/JUnitAbstractTestClassNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/JUnitTestClassNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/LocalVariableNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/LogStatementGuardedByLogCondition.html20
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/LoggingConditionDisagreesWithLogStatement.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/MethodCanBeVariableArityMethod.html4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/MethodCount.html6
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/MethodCoupling.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/MultipleReturnPointsPerMethod.html13
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/MultiplyOrDivideByPowerOfTwo.html4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/NegatedConditional.html3
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/NegatedIfElse.html3
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/NestingDepth.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/NonCommentSourceStatements.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexArithmeticExpression.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexBooleanExpression.html7
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/PackageNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ParameterNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerMethod.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html9
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/PointlessNullCheck.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAssignmentWithOperatorAssignment.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ResultOfObjectAllocationIgnored.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/StaticMethodNamingConvention.html4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/StaticVariableNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenationMissingWhitespace.html6
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/StringConstructor.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/StringReplaceableByStringBuffer.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooFewBranches.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooManyBranches.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ThrownExceptionsPerMethod.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/TryFinallyCanBeTryWithResources.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/TryWithIdenticalCatches.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/TypeParameterNamingConvention.html2
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/WhileCanBeForeach.html2
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.after.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.java8
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.after.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.after.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/MoveThrows.java (renamed from plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/moveThrows.java)0
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.after.java11
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.java11
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.after.java15
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/AssignmentToSuperclassField.java25
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/expected.xml24
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/IgnoreResultsOfReadInspection.java23
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/IgnoreResultOfCall.java10
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/expected.xml9
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/ResultOfObjectAllocationIgnored.java (renamed from plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ResultOfObjectAllocationIgnoredInspection.java)6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/expected.xml16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/string_concatenation_missing_whitespace/Concatenations.java2
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumentToVariableArgMethod.java (renamed from plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumnetToVariableArgMethod.java)12
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/expected.xml2
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/non_final_utility_class/NonFinalUtilityClass.java3
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/DuplicateBooleanBranch.java8
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/expected.xml16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/DuplicateCondition.java12
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/expected.xml37
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/FallthruInSwitch.java2
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/expected.xml7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/OverlyComplexBooleanExpression.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/expected.xml9
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/PointlessBooleanExpression.java (renamed from plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/PointlessBooleanExpression.java)7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/expected.xml (renamed from plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/expected.xml)7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_null_check/expected.xml16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java8
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml14
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/LogStatementGuardedByLogCondition.java6
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/expected.xml7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java31
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/migration/method_can_be_variable_arity_method/MethodCanBeVariableArity.java7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/DivideByZero.java13
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/expected.xml16
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/ImplicitNumericConversion.java4
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/expected.xml7
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java5
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java5
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/SynchronizationOnLocalVariableOrMethodParameter.java34
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/expected.xml9
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java73
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspectionTest.java25
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/IgnoreResultOfCallInspectionTest.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspectionTest.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumnetToVariableArgMethodInspectionTest.java11
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspectionTest.java25
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspectionTest.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateConditionInspectionTest.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspectionTest.java13
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspectionTest.java4
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java5
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessNullCheckFixTest.java7
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/ConstantIfFixTest.java33
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/SimplifiableEqualsExpressionFixTest.java34
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/errorhandling/ThrowsRuntimeExceptionInspectionFixTest.java4
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/logging/StringConcatenationArgumentToLogCallFixTest.java41
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/migration/IfCanBeSwitchFixTest.java36
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java62
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspectionTest.java31
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java13
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspectionTest.java7
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/DivideByZeroInspectionTest.java10
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspectionTest.java21
172 files changed, 2314 insertions, 1575 deletions
diff --git a/plugins/InspectionGadgets/src/META-INF/plugin.xml b/plugins/InspectionGadgets/src/META-INF/plugin.xml
index 3e5977f50329..07af779efc64 100644
--- a/plugins/InspectionGadgets/src/META-INF/plugin.xml
+++ b/plugins/InspectionGadgets/src/META-INF/plugin.xml
@@ -107,6 +107,10 @@
key="assignment.to.static.field.from.instance.method.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.assignment.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.siyeh.ig.assignment.AssignmentToStaticFieldFromInstanceMethodInspection"/>
+ <localInspection language="JAVA" shortName="AssignmentToSuperclassField" bundle="com.siyeh.InspectionGadgetsBundle"
+ key="assignment.to.superclass.field.display.name" groupBundle="messages.InspectionsBundle"
+ groupKey="group.names.assignment.issues" enabledByDefault="false" level="WARNING"
+ implementationClass="com.siyeh.ig.assignment.AssignmentToSuperclassFieldInspection"/>
<localInspection language="JAVA" shortName="AssignmentUsedAsCondition" bundle="com.siyeh.InspectionGadgetsBundle"
key="assignment.used.as.condition.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.assignment.issues" enabledByDefault="false" level="WARNING"
@@ -1441,6 +1445,10 @@
<localInspection language="JAVA" suppressId="NonConstantLogger" shortName="NonStaticFinalLogger" bundle="com.siyeh.InspectionGadgetsBundle"
key="non.constant.logger.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.logging.issues"
enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.logging.NonStaticFinalLoggerInspection"/>
+ <localInspection language="JAVA" shortName="PlaceholderCountMatchesArgumentCount" bundle="com.siyeh.InspectionGadgetsBundle"
+ key="placeholder.count.matches.argument.count.display.name" groupBundle="messages.InspectionsBundle"
+ groupKey="group.names.logging.issues" enabledByDefault="false" level="WARNING"
+ implementationClass="com.siyeh.ig.logging.PlaceholderCountMatchesArgumentCountInspection"/>
<localInspection language="JAVA" shortName="PublicMethodWithoutLogging" bundle="com.siyeh.InspectionGadgetsBundle"
key="public.method.without.logging.display.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.logging.issues" enabledByDefault="false" level="WARNING"
diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
index fdcff59f758f..941a1b5f473a 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -201,7 +201,7 @@ no.logger.problem.descriptor=Class <code>#ref</code> does not declare a logger #
non.constant.logger.display.name=Non-constant logger
non.constant.logger.problem.descriptor=Non-constant logger field <code>#ref</code> #loc
public.method.without.logging.display.name='public' method without logging
-public.method.without.logging.problem.descriptor='public' method <code>#ref()</code> has no logging statement #loc
+public.method.without.logging.problem.descriptor='public' method <code>#ref()</code> has no logging call #loc
action.reset.telemetry.description=Reset telemetry data
telemetry.table.column.inspection.name=Inspection
@@ -886,7 +886,7 @@ iterator.next.does.not.throw.nosuchelementexception.problem.descriptor=<code>Ite
infinite.loop.statement.problem.descriptor=<code>#ref</code> statement cannot complete without throwing an exception #loc
confusing.floating.point.literal.problem.descriptor=Confusing floating point literal <code>#ref</code> #loc
overly.complex.arithmetic.expression.problem.descriptor=Overly complex arithmetic expression #loc
-overly.complex.boolean.expression.problem.descriptor=Overly complex boolean expression #loc
+overly.complex.boolean.expression.problem.descriptor=Overly complex boolean expression ({0} terms) #loc
labeled.statement.problem.descriptor=Labeled statement <code>#ref:</code> #loc
break.statement.with.label.problem.descriptor=<code>#ref</code> statement with label #loc
continue.statement.with.label.problem.descriptor=<code>#ref</code> statement with label #loc
@@ -1226,7 +1226,7 @@ object.notify.replace.quickfix=Replace with 'notifyAll()'
safe.lock.problem.descriptor=''{0}'' should be locked in front of a ''try'' block and unlocked in the corresponding ''finally'' block #loc
synchronized.method.problem.descriptor=Method ''{0}()'' declared <code>#ref</code> #loc
synchronized.method.include.option=Include native methods
-synchronized.method.ignore.synchronized.super.option=Ignore overrides synchronized methods
+synchronized.method.ignore.synchronized.super.option=Ignore methods overriding a synchronized method
synchronized.method.move.quickfix=Move synchronization into method
thread.run.replace.quickfix=Replace with 'start()'
volatile.field.problem.descriptor=Volatile field <code>#ref</code> of type ''{0}'' #loc
@@ -1245,9 +1245,9 @@ encapsulate.variable.quickfix=Encapsulate field ''{0}''
extract.method.quickfix=Extract method
inline.call.quickfix=Inline call
inline.variable.quickfix=Inline variable
-pointless.nullcheck.display.name=Pointless 'null' check
-pointless.nullcheck.problem.descriptor=Pointless 'null' check can be removed
-pointless.nullcheck.simplify.quickfix=Simplify
+pointless.nullcheck.display.name=Unnecessary 'null' check before 'instanceof' expression
+pointless.nullcheck.problem.descriptor=Unnecessary 'null' check before 'instanceof' expression
+pointless.nullcheck.simplify.quickfix=Remove unnecessary ''{0}'' condition
introduce.constant.quickfix=Introduce constant
make.class.cloneable.quickfix=Make class 'Cloneable'
make.interface.cloneable.quickfix=Make interface 'Cloneable'
@@ -1345,8 +1345,7 @@ unnecessarily.qualified.static.usage.problem.descriptor1=Unnecessarily qualified
unnecessarily.qualified.static.usage.ignore.field.option=Ignore unnecessarily qualified field accesses
unnecessarily.qualified.static.usage.ignore.method.option=Ignore unnecessarily qualified method calls
unnecessary.interface.modifier.problem.descriptor=Modifier <code>#ref</code> is redundant for interfaces #loc
-unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor=Modifier <code>#ref</code> is redundant for inner interfaces of interfaces #loc
-unnecessary.interface.modifier.inner.interface.of.class.problem.descriptor=Modifier <code>#ref</code> is redundant for inner interfaces of classes #loc
+unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor=Modifier <code>#ref</code> is redundant for inner interfaces #loc
unnecessary.interface.modifier.problem.descriptor2=Modifier <code>#ref</code> is redundant for interface methods #loc
unnecessary.interface.modifier.problem.descriptor3=Modifier <code>#ref</code> is redundant for inner classes of interfaces #loc
unnecessary.interface.modifier.problem.descriptor4=Modifier <code>#ref</code> is redundant for interface fields #loc
@@ -1474,7 +1473,7 @@ choose.class.type.to.ignore=Choose class type to ignore
loop.condition.not.updated.inside.loop.display.name=Loop variable not updated inside loop
loop.condition.not.updated.inside.loop.problem.descriptor='#ref' is not updated inside loop #loc
utility.class.without.private.constructor.option=Ignore classes with only a main method
-super.class.logger.option=Ignore classes with an accessible logger declared in a super class
+super.class.logger.option=Ignore classes with an accessible logger declared in a superclass
static.method.only.used.in.one.class.display.name=Static method only used from one other class
static.method.only.used.in.one.class.problem.descriptor=Static method <code>#ref()</code> is only used from class ''{0}'' #loc
static.method.only.used.in.one.class.problem.descriptor.anonymous.implementing=Static method <code>#ref()</code> is only used from an anonymous class implementing ''{0}'' #loc
@@ -1695,7 +1694,7 @@ unnecessary.constant.array.creation.expression.display.name=Constant array creat
unnecessary.constant.array.creation.expression.problem.descriptor=<code>#ref</code> can be replaced with array initializer expression #loc
unnecessary.constant.array.creation.expression.quickfix=Replace with array initializer expression
ambiguous.method.call.display.name=Inherited method called, while local method might have been expected
-ambiguous.method.call.problem.descriptor=Method <code>#ref()</code> from super class ''{0}'' called, when method from class ''{1}'' might have been expected #loc
+ambiguous.method.call.problem.descriptor=Method <code>#ref()</code> from superclass ''{0}'' called, when method from class ''{1}'' might have been expected #loc
ambiguous.method.call.quickfix=Add 'super' qualifier to method call
change.modifier.quickfix=Make ''{0}''
the.whole.project=the whole project
@@ -1708,11 +1707,12 @@ logger.initialized.with.foreign.class.display.name=Logger initialized with forei
logger.factory.method.name=Logger factory method name
logger.factory.class.name=Logger factory class name
make.static.final.quickfix=Make ''{0}'' static final
-logging.condition.disagrees.with.log.statement.display.name=Logging condition does not match log statement
-logging.condition.disagrees.with.log.statement.problem.descriptor=Logging condition <code>#ref()</code> does not match ''{0}()'' log statement #loc
-log.statement.guarded.by.log.condition.display.name=Log statement not guarded by log condition
-log.statement.guarded.by.log.condition.problem.descriptor=<code>#ref()</code> log statement not guarded by log condition #loc
+logging.condition.disagrees.with.log.statement.display.name=Log condition does not match logging call
+logging.condition.disagrees.with.log.statement.problem.descriptor=Log condition <code>#ref()</code> does not match ''{0}()'' logging call #loc
+log.statement.guarded.by.log.condition.display.name=Logging call not guarded by log condition
+log.statement.guarded.by.log.condition.problem.descriptor=<code>#ref()</code> logging calls not guarded by log condition #loc
log.statement.guarded.by.log.condition.quickfix=Surround with log condition
+log.statement.guarded.by.log.condition.flag.all.unguarded.option=Flag all unguarded logging calls
key.set.iteration.may.use.entry.set.display.name=Iteration over 'keySet()' may be replaced with 'entrySet()' iteration
key.set.iteration.may.use.entry.set.problem.descriptor=Iteration over <code>#ref</code> may be replaced with 'entrySet()' iteration #loc
key.set.iteration.may.use.entry.set.quickfix=Replace with 'entrySet()' iteration
@@ -1809,7 +1809,7 @@ logger.class.name=Logger class name
ignore.exceptions.declared.in.tests.option=Ignore exceptions declared in &tests
ignore.exceptions.declared.on.library.override.option=Ignore exceptions declared on methods overriding a &library method
allow.resource.to.be.opened.inside.a.try.block=Allow resource to be opened inside a 'try' block
-log.method.name=Log method name
+log.method.name=Logging method name
log.condition.text=Log condition text
ignore.if.annotated.by=Ignore if annotated by
only.weaken.to.an.interface=Only weaken to an interface
@@ -1860,7 +1860,7 @@ boxing.boxed.value.quickfix=Remove unnecessary boxing
unnecessary.javadoc.link.option=Ignore inline links to super methods
constant.junit.assert.argument.display.name=Constant JUnit assert argument
constant.junit.assert.argument.problem.descriptor=Argument <code>#ref</code> is constant #loc
-test.case.with.no.test.methods.option=Ignore test cases which have super classes with test methods
+test.case.with.no.test.methods.option=Ignore test cases which have superclasses with test methods
package.dot.html.may.be.package.info.display.name='package.html' may be converted to 'package-info.java'
package.dot.html.may.be.package.info.exists.problem.descriptor=<code>package.html</code> is ignored because <code>package-info.java</code> exists
package.dot.html.may.be.package.info.problem.descriptor=<code>package.html</code> may be converted to <code>package-info.java</code>
@@ -1897,6 +1897,7 @@ arrays.hash.code.quickfix=Replace with 'Arrays.hashCode()'
method.can.be.variable.arity.method.display.name=Method can be variable arity method
method.can.be.variable.arity.method.problem.descriptor=<code>#ref()</code> can be converted to variable arity method #loc
method.can.be.variable.arity.method.ignore.byte.short.option=<html>Ignore methods with a last parameter of type byte[] or short[]</html>
+method.can.be.variable.arity.method.ignore.overriding.methods=Ignore methods overriding a super method
convert.to.variable.arity.method.quickfix=Convert to variable arity method
mismatched.string.builder.query.update.display.name=Mismatched query and update of StringBuilder
mismatched.string.builder.updated.problem.descriptor=Contents of {0} <code>#ref</code> are updated, but never queried #loc
@@ -1970,9 +1971,9 @@ throws.runtime.exception.quickfix=Remove ''{0}'' from ''throws'' clause
throws.runtime.exception.move.quickfix=Move ''{0}'' to Javadoc ''@throws'' tag
empty.class.ignore.parameterization.option=Ignore class if it is a parameterization of a super type
ambiguous.field.access.display.name=Inherited field accessed while local variable, parameter or field access from surrounding class might be expected
-ambiguous.field.access.hides.local.variable.problem.descriptor=Field <code>#ref</code> from super class ''{0}'' accessed, while local variable access might be expected #loc
-ambiguous.field.access.hides.parameter.problem.descriptor=Field <code>#ref</code> from super class ''{0}'' accessed, while parameter access might be expected #loc
-ambiguous.field.access.hides.field.problem.descriptor=Field <code>#ref</code> from super class ''{0}'' accessed, while field access from surrounding class might be expected #loc
+ambiguous.field.access.hides.local.variable.problem.descriptor=Field <code>#ref</code> from superclass ''{0}'' accessed, while local variable access might be expected #loc
+ambiguous.field.access.hides.parameter.problem.descriptor=Field <code>#ref</code> from superclass ''{0}'' accessed, while parameter access might be expected #loc
+ambiguous.field.access.hides.field.problem.descriptor=Field <code>#ref</code> from superclass ''{0}'' accessed, while field access from surrounding class might be expected #loc
ambiguous.field.access.quickfix=Add 'super' qualifier to field access
string.builder.replaceable.by.string.quickfix=Replace 'StringBuilder' with 'String'
string.buffer.replaceable.by.string.quickfix=Replace 'StringBuffer' with 'String'
@@ -1984,7 +1985,7 @@ externalizable.without.public.no.arg.constructor.problem.descriptor=Externalizab
make.constructor.public=Make constructor 'public'
string.concatenation.missing.whitespace.display.name=String literal concatenation missing whitespace
string.concatenation.missing.whitespace.problem.descriptor=String literal concatenation missing whitespace #loc
-string.concatenation.missing.whitespace.option=Ignore when one or both sides are not string literals
+string.concatenation.missing.whitespace.option=Ignore when one or both sides are not literals
negated.equality.expression.display.name=Negated equality expression
negated.equality.expression.problem.descriptor=Negating ''{0}'' #loc
negated.equality.expression.quickfix=Remove negation
@@ -2013,4 +2014,9 @@ arrays.as.list.with.one.argument.quickfix=Replace with call to 'Collections.sing
arrays.as.list.with.zero.arguments.quickfix=Replace with call to 'Collections.emptyList()'
ignore.classes.extending.throwable.option=Ignore classes extending 'Throwable'
string.concatenation.argument.to.log.call.display.name=Non-constant string concatenation as argument to logging call
-string.concatenation.argument.to.log.call.problem.descriptor=Non-constant string concatenation as argument to <code>#ref()</code> logging call #loc \ No newline at end of file
+string.concatenation.argument.to.log.call.problem.descriptor=Non-constant string concatenation as argument to <code>#ref()</code> logging call #loc
+placeholder.count.matches.argument.count.display.name=Number of placeholders does not match number of arguments in logging call
+placeholder.count.matches.argument.count.more.problem.descriptor=<code>#ref()</code> call has more arguments ({0}) than placeholders ({1}) #loc
+placeholder.count.matches.argument.count.fewer.problem.descriptor=<code>#ref()</code> call has fewer arguments ({0}) than placeholders ({1}) #loc
+assignment.to.superclass.field.display.name=Constructor assigns value to field defined in superclass
+assignment.to.superclass.field.problem.descriptor=Assignment to field ''{0}'' defined in superclass ''{1}''
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java
index bbedd0243112..835046511e74 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/TypeMayBeWeakenedInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2012 Bas Leijdekkers
+ * Copyright 2006-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,48 +64,36 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
@NonNls final StringBuilder builder = new StringBuilder();
final Iterator<PsiClass> iterator = weakerClasses.iterator();
if (iterator.hasNext()) {
- builder.append('\'');
- builder.append(iterator.next().getQualifiedName());
- builder.append('\'');
+ builder.append('\'').append(iterator.next().getQualifiedName()).append('\'');
while (iterator.hasNext()) {
- builder.append(", '");
- builder.append(iterator.next().getQualifiedName());
- builder.append('\'');
+ builder.append(", '").append(iterator.next().getQualifiedName()).append('\'');
}
}
final Object info = infos[0];
if (info instanceof PsiField) {
- return InspectionGadgetsBundle.message(
- "type.may.be.weakened.field.problem.descriptor",
+ return InspectionGadgetsBundle.message("type.may.be.weakened.field.problem.descriptor",
builder.toString());
}
else if (info instanceof PsiParameter) {
- return InspectionGadgetsBundle.message(
- "type.may.be.weakened.parameter.problem.descriptor",
+ return InspectionGadgetsBundle.message("type.may.be.weakened.parameter.problem.descriptor",
builder.toString());
}
else if (info instanceof PsiMethod) {
- return InspectionGadgetsBundle.message(
- "type.may.be.weakened.method.problem.descriptor",
+ return InspectionGadgetsBundle.message("type.may.be.weakened.method.problem.descriptor",
builder.toString());
}
- return InspectionGadgetsBundle.message(
- "type.may.be.weakened.problem.descriptor", builder.toString());
+ return InspectionGadgetsBundle.message("type.may.be.weakened.problem.descriptor", builder.toString());
}
@Override
@Nullable
public JComponent createOptionsPanel() {
- final MultipleCheckboxOptionsPanel optionsPanel =
- new MultipleCheckboxOptionsPanel(this);
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "type.may.be.weakened.ignore.option"),
+ final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("type.may.be.weakened.ignore.option"),
"useRighthandTypeAsWeakestTypeInAssignments");
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "type.may.be.weakened.collection.method.option"),
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("type.may.be.weakened.collection.method.option"),
"useParameterizedTypeForCollectionMethods");
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "type.may.be.weakened.do.not.weaken.to.object.option"),
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("type.may.be.weakened.do.not.weaken.to.object.option"),
"doNotWeakenToJavaLangObject");
optionsPanel.addCheckbox(InspectionGadgetsBundle.message("only.weaken.to.an.interface"),
"onlyWeakentoInterface");
@@ -137,19 +125,16 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "type.may.be.weakened.quickfix", fqClassName);
+ return InspectionGadgetsBundle.message("type.may.be.weakened.quickfix", fqClassName);
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
final PsiTypeElement typeElement;
if (parent instanceof PsiVariable) {
- final PsiVariable variable =
- (PsiVariable)parent;
+ final PsiVariable variable = (PsiVariable)parent;
typeElement = variable.getTypeElement();
}
else if (parent instanceof PsiMethod) {
@@ -162,8 +147,7 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
if (typeElement == null) {
return;
}
- final PsiJavaCodeReferenceElement componentReferenceElement =
- typeElement.getInnermostComponentReferenceElement();
+ final PsiJavaCodeReferenceElement componentReferenceElement = typeElement.getInnermostComponentReferenceElement();
if (componentReferenceElement == null) {
return;
}
@@ -179,28 +163,23 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
if (aClass == null) {
return;
}
- final PsiTypeParameter[] typeParameters =
- aClass.getTypeParameters();
+ final PsiTypeParameter[] typeParameters = aClass.getTypeParameters();
final PsiElementFactory factory = facade.getElementFactory();
final PsiClassType type;
- if (typeParameters.length != 0 &&
- typeParameters.length == parameterTypes.length) {
- final Map<PsiTypeParameter, PsiType> typeParameterMap =
- new HashMap();
+ if (typeParameters.length != 0 && typeParameters.length == parameterTypes.length) {
+ final Map<PsiTypeParameter, PsiType> typeParameterMap = new HashMap();
for (int i = 0; i < typeParameters.length; i++) {
final PsiTypeParameter typeParameter = typeParameters[i];
final PsiType parameterType = parameterTypes[i];
typeParameterMap.put(typeParameter, parameterType);
}
- final PsiSubstitutor substitutor =
- factory.createSubstitutor(typeParameterMap);
+ final PsiSubstitutor substitutor = factory.createSubstitutor(typeParameterMap);
type = factory.createType(aClass, substitutor);
}
else {
type = factory.createTypeByFQClassName(fqClassName, scope);
}
- final PsiJavaCodeReferenceElement referenceElement =
- factory.createReferenceElementByType(type);
+ final PsiJavaCodeReferenceElement referenceElement = factory.createReferenceElementByType(type);
componentReferenceElement.replace(referenceElement);
}
}
@@ -217,8 +196,7 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
super.visitVariable(variable);
if (variable instanceof PsiParameter) {
final PsiParameter parameter = (PsiParameter)variable;
- final PsiElement declarationScope =
- parameter.getDeclarationScope();
+ final PsiElement declarationScope = parameter.getDeclarationScope();
if (declarationScope instanceof PsiCatchSection) {
// do not weaken catch block parameters
return;
@@ -235,8 +213,7 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
// super methods
return;
}
- final Query<PsiMethod> overridingSearch =
- OverridingMethodsSearch.search(method);
+ final Query<PsiMethod> overridingSearch = OverridingMethodsSearch.search(method);
if (overridingSearch.findFirst() != null) {
// do not try to weaken parameters of methods with
// overriding methods.
@@ -255,21 +232,16 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
if (variable instanceof PsiParameter) {
final PsiElement parent = variable.getParent();
if (parent instanceof PsiForeachStatement) {
- final PsiForeachStatement foreachStatement =
- (PsiForeachStatement)parent;
- final PsiExpression iteratedValue =
- foreachStatement.getIteratedValue();
- if (!(iteratedValue instanceof PsiNewExpression) &&
- !(iteratedValue instanceof
- PsiTypeCastExpression)) {
+ final PsiForeachStatement foreachStatement = (PsiForeachStatement)parent;
+ final PsiExpression iteratedValue = foreachStatement.getIteratedValue();
+ if (!(iteratedValue instanceof PsiNewExpression) && !(iteratedValue instanceof PsiTypeCastExpression)) {
return;
}
}
}
else {
final PsiExpression initializer = variable.getInitializer();
- if (!(initializer instanceof PsiNewExpression) &&
- !(initializer instanceof PsiTypeCastExpression)) {
+ if (!(initializer instanceof PsiNewExpression) && !(initializer instanceof PsiTypeCastExpression)) {
return;
}
}
@@ -281,14 +253,11 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
if (doNotWeakenToJavaLangObject) {
final Project project = variable.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
- final PsiClass javaLangObjectClass =
- facade.findClass(CommonClassNames.JAVA_LANG_OBJECT,
- variable.getResolveScope());
+ final PsiClass javaLangObjectClass = facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, variable.getResolveScope());
weakestClasses.remove(javaLangObjectClass);
}
if (onlyWeakentoInterface) {
- for (Iterator<PsiClass> iterator = weakestClasses.iterator();
- iterator.hasNext(); ) {
+ for (Iterator<PsiClass> iterator = weakestClasses.iterator(); iterator.hasNext(); ) {
final PsiClass weakestClass = iterator.next();
if (!weakestClass.isInterface()) {
iterator.remove();
@@ -313,8 +282,7 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
// do not try to weaken methods with super methods
return;
}
- final Query<PsiMethod> overridingSearch =
- OverridingMethodsSearch.search(method);
+ final Query<PsiMethod> overridingSearch = OverridingMethodsSearch.search(method);
if (overridingSearch.findFirst() != null) {
// do not try to weaken methods with overriding methods.
return;
@@ -326,9 +294,7 @@ public class TypeMayBeWeakenedInspection extends BaseInspection {
if (doNotWeakenToJavaLangObject) {
final Project project = method.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
- final PsiClass javaLangObjectClass =
- facade.findClass(CommonClassNames.JAVA_LANG_OBJECT,
- method.getResolveScope());
+ final PsiClass javaLangObjectClass = facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, method.getResolveScope());
weakestClasses.remove(javaLangObjectClass);
}
if (onlyWeakentoInterface) {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspection.java
new file mode 100644
index 000000000000..a28257d497c5
--- /dev/null
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspection.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2000-2013 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.assignment;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class AssignmentToSuperclassFieldInspection extends BaseInspection {
+
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("assignment.to.superclass.field.display.name");
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)infos[0];
+ final PsiClass superclass = (PsiClass)infos[1];
+ return InspectionGadgetsBundle.message("assignment.to.superclass.field.problem.descriptor",
+ referenceExpression.getReferenceName(), superclass.getName());
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new AssignmentToSuperclassFieldVisitor();
+ }
+
+ private static class AssignmentToSuperclassFieldVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitAssignmentExpression(PsiAssignmentExpression expression) {
+ super.visitAssignmentExpression(expression);
+ final PsiExpression lhs = expression.getLExpression();
+ checkSuperclassField(lhs);
+ }
+
+ @Override
+ public void visitPrefixExpression(PsiPrefixExpression expression) {
+ super.visitPrefixExpression(expression);
+ final PsiExpression operand = expression.getOperand();
+ checkSuperclassField(operand);
+ }
+
+ @Override
+ public void visitPostfixExpression(PsiPostfixExpression expression) {
+ super.visitPostfixExpression(expression);
+ final PsiExpression operand = expression.getOperand();
+ checkSuperclassField(operand);
+ }
+
+ private void checkSuperclassField(PsiExpression expression) {
+ if (!(expression instanceof PsiReferenceExpression)) {
+ return;
+ }
+ final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiClass.class);
+ if (method == null || !method.isConstructor()) {
+ return;
+ }
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
+ final PsiExpression qualifierExpression = referenceExpression.getQualifierExpression();
+ if (qualifierExpression != null &&
+ !(qualifierExpression instanceof PsiThisExpression) && !(qualifierExpression instanceof PsiSuperExpression)) {
+ return;
+ }
+ final PsiElement target = referenceExpression.resolve();
+ if (!(target instanceof PsiField)) {
+ return;
+ }
+ final PsiField field = (PsiField)target;
+ final PsiClass fieldClass = field.getContainingClass();
+ if (fieldClass == null) {
+ return;
+ }
+ final PsiClass assignmentClass = method.getContainingClass();
+ final String name = fieldClass.getQualifiedName();
+ if (name == null || !InheritanceUtil.isInheritor(assignmentClass, true, name)) {
+ return;
+ }
+ registerError(expression, referenceExpression, fieldClass);
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java
index 873a2407a5cc..c476f9a6af38 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/IgnoreResultOfCallInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.ui.CheckBox;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -77,8 +78,7 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "result.of.method.call.ignored.display.name");
+ return InspectionGadgetsBundle.message("result.of.method.call.ignored.display.name");
}
@Override
@@ -86,9 +86,7 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
public String buildErrorString(Object... infos) {
final PsiClass containingClass = (PsiClass)infos[0];
final String className = containingClass.getName();
- return InspectionGadgetsBundle.message(
- "result.of.method.call.ignored.problem.descriptor",
- className);
+ return InspectionGadgetsBundle.message("result.of.method.call.ignored.problem.descriptor", className);
}
@Override
@@ -106,9 +104,9 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel(new BorderLayout());
- final ListTable table = new ListTable(new ListWrappingTableModel(Arrays.asList(classNames, methodNamePatterns), InspectionGadgetsBundle
- .message("result.of.method.call.ignored.class.column.title"), InspectionGadgetsBundle
- .message("result.of.method.call.ignored.method.column.title")));
+ final ListTable table = new ListTable(new ListWrappingTableModel(
+ Arrays.asList(classNames, methodNamePatterns), InspectionGadgetsBundle.message("result.of.method.call.ignored.class.column.title"),
+ InspectionGadgetsBundle.message("result.of.method.call.ignored.method.column.title")));
final JPanel tablePanel = UiUtils.createAddRemovePanel(table);
final CheckBox checkBox =
new CheckBox(InspectionGadgetsBundle.message("result.of.method.call.ignored.non.library.option"), this, "m_reportAllNonLibraryCalls");
@@ -130,15 +128,13 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
private class IgnoreResultOfCallVisitor extends BaseInspectionVisitor {
@Override
- public void visitExpressionStatement(
- @NotNull PsiExpressionStatement statement) {
+ public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
super.visitExpressionStatement(statement);
final PsiExpression expression = statement.getExpression();
if (!(expression instanceof PsiMethodCallExpression)) {
return;
}
- final PsiMethodCallExpression call =
- (PsiMethodCallExpression)expression;
+ final PsiMethodCallExpression call = (PsiMethodCallExpression)expression;
final PsiMethod method = call.resolveMethod();
if (method == null || method.isConstructor()) {
return;
@@ -151,13 +147,14 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
if (aClass == null) {
return;
}
- if (m_reportAllNonLibraryCalls &&
- !LibraryUtil.classIsInLibrary(aClass)) {
+ if (PsiUtilCore.hasErrorElementChild(statement)) {
+ return;
+ }
+ if (m_reportAllNonLibraryCalls && !LibraryUtil.classIsInLibrary(aClass)) {
registerMethodCallError(call, aClass);
return;
}
- final PsiReferenceExpression methodExpression =
- call.getMethodExpression();
+ final PsiReferenceExpression methodExpression = call.getMethodExpression();
final String methodName = methodExpression.getReferenceName();
if (methodName == null) {
return;
@@ -176,8 +173,7 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
}
}
- private boolean methodNamesMatch(String methodName,
- String methodNamePattern) {
+ private boolean methodNamesMatch(String methodName, String methodNamePattern) {
Pattern pattern;
if (patternCache != null) {
pattern = patternCache.get(methodNamePattern);
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspection.java
index 71f2ae53732f..90921cdb2cc1 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2008 Dave Griffith, Bas Leijdekkers
+ * Copyright 2006-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,21 +23,18 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import org.jetbrains.annotations.NotNull;
-public class PrimitiveArrayArgumentToVariableArgMethodInspection
- extends BaseInspection {
+public class PrimitiveArrayArgumentToVariableArgMethodInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "primitive.array.argument.to.var.arg.method.display.name");
+ return InspectionGadgetsBundle.message("primitive.array.argument.to.var.arg.method.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "primitive.array.argument.to.var.arg.method.problem.descriptor");
+ return InspectionGadgetsBundle.message("primitive.array.argument.to.var.arg.method.problem.descriptor");
}
@Override
@@ -50,12 +47,10 @@ public class PrimitiveArrayArgumentToVariableArgMethodInspection
return new PrimitiveArrayArgumentToVariableArgVisitor();
}
- private static class PrimitiveArrayArgumentToVariableArgVisitor
- extends BaseInspectionVisitor {
+ private static class PrimitiveArrayArgumentToVariableArgVisitor extends BaseInspectionVisitor {
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression call) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
super.visitMethodCallExpression(call);
if (!PsiUtil.isLanguageLevel5OrHigher(call)) {
return;
@@ -70,7 +65,8 @@ public class PrimitiveArrayArgumentToVariableArgMethodInspection
if (!isPrimitiveArrayType(argumentType)) {
return;
}
- final PsiMethod method = call.resolveMethod();
+ final JavaResolveResult result = call.resolveMethodGenerics();
+ final PsiMethod method = (PsiMethod)result.getElement();
if (method == null) {
return;
}
@@ -79,13 +75,12 @@ public class PrimitiveArrayArgumentToVariableArgMethodInspection
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
- final PsiParameter lastParameter =
- parameters[parameters.length - 1];
+ final PsiParameter lastParameter = parameters[parameters.length - 1];
if (!lastParameter.isVarArgs()) {
return;
}
final PsiType parameterType = lastParameter.getType();
- if (isDeepPrimitiveArrayType(parameterType)) {
+ if (isDeepPrimitiveArrayType(parameterType, result.getSubstitutor())) {
return;
}
registerError(lastArgument);
@@ -93,9 +88,6 @@ public class PrimitiveArrayArgumentToVariableArgMethodInspection
}
private static boolean isPrimitiveArrayType(PsiType type) {
- if (type == null) {
- return false;
- }
if (!(type instanceof PsiArrayType)) {
return false;
}
@@ -103,11 +95,12 @@ public class PrimitiveArrayArgumentToVariableArgMethodInspection
return TypeConversionUtil.isPrimitiveAndNotNull(componentType);
}
- private static boolean isDeepPrimitiveArrayType(PsiType type) {
- if (!(type instanceof PsiArrayType)) {
+ private static boolean isDeepPrimitiveArrayType(PsiType type, PsiSubstitutor substitutor) {
+ if (!(type instanceof PsiEllipsisType)) {
return false;
}
final PsiType componentType = type.getDeepComponentType();
- return TypeConversionUtil.isPrimitiveAndNotNull(componentType);
+ final PsiType substitute = substitutor.substitute(componentType);
+ return TypeConversionUtil.isPrimitiveAndNotNull(substitute.getDeepComponentType());
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspection.java
index bb3c3d3cdc41..eace327f462d 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,40 +23,33 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import org.jetbrains.annotations.NotNull;
-public class ResultOfObjectAllocationIgnoredInspection
- extends BaseInspection {
+public class ResultOfObjectAllocationIgnoredInspection extends BaseInspection {
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "result.of.object.allocation.ignored.display.name");
+ return InspectionGadgetsBundle.message("result.of.object.allocation.ignored.display.name");
}
@NotNull
public String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "result.of.object.allocation.ignored.problem.descriptor");
+ return InspectionGadgetsBundle.message("result.of.object.allocation.ignored.problem.descriptor");
}
public BaseInspectionVisitor buildVisitor() {
- return new IgnoreResultOfCallVisitor();
+ return new ResultOfObjectAllocationIgnoredVisitor();
}
- private static class IgnoreResultOfCallVisitor
- extends BaseInspectionVisitor {
+ private static class ResultOfObjectAllocationIgnoredVisitor extends BaseInspectionVisitor {
@Override
- public void visitExpressionStatement(
- @NotNull PsiExpressionStatement statement) {
+ public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
super.visitExpressionStatement(statement);
final PsiExpression expression = statement.getExpression();
if (!(expression instanceof PsiNewExpression)) {
return;
}
- final PsiNewExpression newExpression =
- (PsiNewExpression)expression;
- final PsiExpression[] arrayDimensions =
- newExpression.getArrayDimensions();
+ final PsiNewExpression newExpression = (PsiNewExpression)expression;
+ final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
if (arrayDimensions.length != 0) {
return;
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StringConcatenationMissingWhitespaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StringConcatenationMissingWhitespaceInspection.java
index f8157a8d301a..2d4ae7233d51 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StringConcatenationMissingWhitespaceInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StringConcatenationMissingWhitespaceInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -22,7 +22,9 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.psiutils.ExpressionUtils;
+import com.siyeh.ig.psiutils.FormatUtils;
import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -68,11 +70,12 @@ public class StringConcatenationMissingWhitespaceInspection extends BaseInspecti
if (!JavaTokenType.PLUS.equals(tokenType) || !ExpressionUtils.hasStringType(expression)) {
return;
}
+ final boolean formatCall = FormatUtils.isFormatCallArgument(expression);
final PsiExpression[] operands = expression.getOperands();
PsiExpression lhs = operands[0];
for (int i = 1; i < operands.length; i++) {
final PsiExpression rhs = operands[i];
- if (isMissingWhitespace(lhs, rhs)) {
+ if (isMissingWhitespace(lhs, rhs, formatCall)) {
final PsiJavaToken token = expression.getTokenBeforeOperand(rhs);
if (token != null) {
registerError(token);
@@ -82,39 +85,38 @@ public class StringConcatenationMissingWhitespaceInspection extends BaseInspecti
}
}
- private boolean isMissingWhitespace(PsiExpression lhs, PsiExpression rhs) {
- final boolean lhsIsString = ExpressionUtils.hasStringType(lhs);
- final PsiLiteralExpression lhsLiteral = ExpressionUtils.getLiteral(lhs);
- final PsiLiteralExpression rhsLiteral = ExpressionUtils.getLiteral(rhs);
- if (lhsLiteral != null && lhsIsString) {
- final String value = (String)lhsLiteral.getValue();
- if (value == null) {
+ private boolean isMissingWhitespace(PsiExpression lhs, PsiExpression rhs, boolean formatCall) {
+ @NonNls final String lhsLiteral = ExpressionUtils.getLiteralString(lhs);
+ if (lhsLiteral != null) {
+ final int length = lhsLiteral.length();
+ if (length == 0) {
return false;
}
- final int length = value.length();
- if (length == 0) {
+ if (formatCall && lhsLiteral.endsWith("%n")) {
return false;
}
- final char c = value.charAt(length - 1);
+ final char c = lhsLiteral.charAt(length - 1);
if (Character.isWhitespace(c) || !Character.isLetterOrDigit(c)) {
return false;
}
}
- else if (ignoreNonStringLiterals || rhsLiteral == null || lhsIsString) {
+ else if (ignoreNonStringLiterals) {
return false;
}
- final boolean rhsIsString = ExpressionUtils.hasStringType(rhs);
- if (rhsLiteral != null && rhsIsString) {
- final String value = (String)rhsLiteral.getValue();
- if ((value == null) || value.isEmpty()) {
+ @NonNls final String rhsLiteral = ExpressionUtils.getLiteralString(rhs);
+ if (rhsLiteral != null) {
+ if (rhsLiteral.isEmpty()) {
+ return false;
+ }
+ if (formatCall && rhsLiteral.startsWith("%n")) {
return false;
}
- final char c = value.charAt(0);
+ final char c = rhsLiteral.charAt(0);
if (Character.isWhitespace(c) || !Character.isLetterOrDigit(c)) {
return false;
}
}
- else if (ignoreNonStringLiterals || rhsIsString) {
+ else if (ignoreNonStringLiterals) {
return false;
}
return true;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/NonFinalUtilityClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/NonFinalUtilityClassInspection.java
index 0f6498eebb94..71041c17cea0 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/NonFinalUtilityClassInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/NonFinalUtilityClassInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -64,7 +64,8 @@ public class NonFinalUtilityClassInspection extends BaseInspection {
if (!UtilityClassUtil.isUtilityClass(aClass)) {
return;
}
- if (aClass.hasModifierProperty(PsiModifier.FINAL)) {
+ if (aClass.hasModifierProperty(PsiModifier.FINAL) ||
+ aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
registerClassError(aClass, aClass);
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
index 4e06728a7a75..088dbf977482 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
@@ -119,9 +119,20 @@ public class ConstantIfStatementInspection extends BaseInspection {
final PsiStatement[] statements = block.getStatements();
if (statements.length > 0) {
assert containingElement != null;
- final PsiElement added =
- containingElement.addRangeBefore(statements[0],
- statements[statements.length - 1], statement);
+ final PsiJavaToken lBrace = block.getLBrace();
+ final PsiJavaToken rBrace = block.getRBrace();
+ PsiElement added = null;
+ if (lBrace != null && rBrace != null) {
+ final PsiElement firstNonBrace = lBrace.getNextSibling();
+ final PsiElement lastNonBrace = rBrace.getPrevSibling();
+ if (firstNonBrace != null && lastNonBrace != null) {
+ added = containingElement.addRangeBefore(firstNonBrace, lastNonBrace, statement);
+ }
+ }
+ if (added == null) {
+ added = containingElement.addRangeBefore(statements[0],
+ statements[statements.length - 1], statement);
+ }
final Project project = statement.getProject();
final CodeStyleManager codeStyleManager =
CodeStyleManager.getInstance(project);
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java
index e53d902dad71..2bd2fcae11d1 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 Dave Griffith, Bas Leijdekkers
+ * Copyright 2006-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,39 +31,33 @@ public class DuplicateBooleanBranchInspection extends BaseInspection {
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "duplicate.boolean.branch.display.name");
+ return InspectionGadgetsBundle.message("duplicate.boolean.branch.display.name");
}
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "duplicate.boolean.branch.problem.descriptor");
+ return InspectionGadgetsBundle.message("duplicate.boolean.branch.problem.descriptor");
}
public BaseInspectionVisitor buildVisitor() {
return new DuplicateBooleanBranchVisitor();
}
- private static class DuplicateBooleanBranchVisitor
- extends BaseInspectionVisitor {
+ private static class DuplicateBooleanBranchVisitor extends BaseInspectionVisitor {
@Override
- public void visitBinaryExpression(PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
+ public void visitPolyadicExpression(PsiPolyadicExpression expression) {
+ super.visitPolyadicExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
- if (!tokenType.equals(JavaTokenType.ANDAND) &&
- !tokenType.equals(JavaTokenType.OROR)) {
+ if (!tokenType.equals(JavaTokenType.ANDAND) && !tokenType.equals(JavaTokenType.OROR)) {
return;
}
-
PsiElement parent = expression.getParent();
while (parent instanceof PsiParenthesizedExpression) {
parent = parent.getParent();
}
if (parent instanceof PsiBinaryExpression) {
- final PsiBinaryExpression parentExpression =
- (PsiBinaryExpression)parent;
+ final PsiBinaryExpression parentExpression = (PsiBinaryExpression)parent;
if (tokenType.equals(parentExpression.getOperationTokenType())) {
return;
}
@@ -74,8 +68,7 @@ public class DuplicateBooleanBranchInspection extends BaseInspection {
if (numConditions < 2) {
return;
}
- final PsiExpression[] conditionArray =
- conditions.toArray(new PsiExpression[numConditions]);
+ final PsiExpression[] conditionArray = conditions.toArray(new PsiExpression[numConditions]);
final boolean[] matched = new boolean[conditionArray.length];
Arrays.fill(matched, false);
for (int i = 0; i < conditionArray.length; i++) {
@@ -88,9 +81,7 @@ public class DuplicateBooleanBranchInspection extends BaseInspection {
continue;
}
final PsiExpression testCondition = conditionArray[j];
- final boolean areEquivalent =
- EquivalenceChecker.expressionsAreEquivalent(
- condition, testCondition);
+ final boolean areEquivalent = EquivalenceChecker.expressionsAreEquivalent(condition, testCondition);
if (areEquivalent) {
registerError(testCondition);
if (!matched[i]) {
@@ -103,29 +94,24 @@ public class DuplicateBooleanBranchInspection extends BaseInspection {
}
}
- private static void collectConditions(PsiExpression condition,
- Set<PsiExpression> conditions,
- IElementType tokenType) {
+ private static void collectConditions(PsiExpression condition, Set<PsiExpression> conditions, IElementType tokenType) {
if (condition == null) {
return;
}
if (condition instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)condition;
- final PsiExpression contents =
- parenthesizedExpression.getExpression();
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)condition;
+ final PsiExpression contents = parenthesizedExpression.getExpression();
collectConditions(contents, conditions, tokenType);
return;
}
- if (condition instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)condition;
- final IElementType testTokeType = binaryExpression.getOperationTokenType();
+ if (condition instanceof PsiPolyadicExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)condition;
+ final IElementType testTokeType = polyadicExpression.getOperationTokenType();
if (testTokeType.equals(tokenType)) {
- final PsiExpression lhs = binaryExpression.getLOperand();
- collectConditions(lhs, conditions, tokenType);
- final PsiExpression rhs = binaryExpression.getROperand();
- collectConditions(rhs, conditions, tokenType);
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ for (PsiExpression operand : operands) {
+ collectConditions(operand, conditions, tokenType);
+ }
return;
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java
index 0962eb7784ab..905868060d5c 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/DuplicateConditionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,30 +42,25 @@ public class DuplicateConditionInspection extends BaseInspection {
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "duplicate.condition.display.name");
+ return InspectionGadgetsBundle.message("duplicate.condition.display.name");
}
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "duplicate.condition.problem.descriptor");
+ return InspectionGadgetsBundle.message("duplicate.condition.problem.descriptor");
}
@Nullable
public JComponent createOptionsPanel() {
- return new SingleCheckboxOptionsPanel(
- InspectionGadgetsBundle.message(
- "duplicate.condition.ignore.method.calls.option"),
- this, "ignoreMethodCalls");
+ return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("duplicate.condition.ignore.method.calls.option"),
+ this, "ignoreMethodCalls");
}
public BaseInspectionVisitor buildVisitor() {
return new DuplicateConditionVisitor();
}
- private class DuplicateConditionVisitor
- extends BaseInspectionVisitor {
+ private class DuplicateConditionVisitor extends BaseInspectionVisitor {
@Override
public void visitIfStatement(@NotNull PsiIfStatement statement) {
@@ -84,8 +79,7 @@ public class DuplicateConditionInspection extends BaseInspection {
if (numConditions < 2) {
return;
}
- final PsiExpression[] conditionArray =
- conditions.toArray(new PsiExpression[numConditions]);
+ final PsiExpression[] conditionArray = conditions.toArray(new PsiExpression[numConditions]);
final boolean[] matched = new boolean[conditionArray.length];
Arrays.fill(matched, false);
for (int i = 0; i < conditionArray.length; i++) {
@@ -98,60 +92,51 @@ public class DuplicateConditionInspection extends BaseInspection {
continue;
}
final PsiExpression testCondition = conditionArray[j];
- final boolean areEquivalent =
- EquivalenceChecker.expressionsAreEquivalent(
- condition, testCondition);
+ final boolean areEquivalent = EquivalenceChecker.expressionsAreEquivalent(condition, testCondition);
if (areEquivalent) {
+ if (!ignoreMethodCalls || !containsMethodCallExpression(testCondition)) {
+ registerError(testCondition);
+ if (!matched[i]) {
+ registerError(condition);
+ }
+ }
matched[i] = true;
matched[j] = true;
- if (ignoreMethodCalls &&
- containsMethodCallExpression(testCondition)) {
- break;
- }
- registerError(testCondition);
- if (!matched[i]) {
- registerError(condition);
- }
}
}
}
}
- private void collectConditionsForIfStatement(
- PsiIfStatement statement, Set<PsiExpression> conditions, int depth) {
- if (depth > LIMIT_DEPTH) return;
-
+ private void collectConditionsForIfStatement(PsiIfStatement statement, Set<PsiExpression> conditions, int depth) {
+ if (depth > LIMIT_DEPTH) {
+ return;
+ }
final PsiExpression condition = statement.getCondition();
collectConditionsForExpression(condition, conditions);
final PsiStatement branch = statement.getElseBranch();
if (branch instanceof PsiIfStatement) {
- collectConditionsForIfStatement((PsiIfStatement)branch,
- conditions, depth + 1);
+ collectConditionsForIfStatement((PsiIfStatement)branch, conditions, depth + 1);
}
}
- private void collectConditionsForExpression(
- PsiExpression condition, Set<PsiExpression> conditions) {
+ private void collectConditionsForExpression(PsiExpression condition, Set<PsiExpression> conditions) {
if (condition == null) {
return;
}
if (condition instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)condition;
- final PsiExpression contents =
- parenthesizedExpression.getExpression();
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)condition;
+ final PsiExpression contents = parenthesizedExpression.getExpression();
collectConditionsForExpression(contents, conditions);
return;
}
- if (condition instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)condition;
- final IElementType tokenType = binaryExpression.getOperationTokenType();
+ if (condition instanceof PsiPolyadicExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)condition;
+ final IElementType tokenType = polyadicExpression.getOperationTokenType();
if (JavaTokenType.OROR.equals(tokenType)) {
- final PsiExpression lhs = binaryExpression.getLOperand();
- collectConditionsForExpression(lhs, conditions);
- final PsiExpression rhs = binaryExpression.getROperand();
- collectConditionsForExpression(rhs, conditions);
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ for (PsiExpression operand : operands) {
+ collectConditionsForExpression(operand, conditions);
+ }
return;
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/FallthruInSwitchStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/FallthruInSwitchStatementInspection.java
index b98a32051bb3..fd09a2c674b3 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/FallthruInSwitchStatementInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/FallthruInSwitchStatementInspection.java
@@ -80,19 +80,19 @@ public class FallthruInSwitchStatementInspection extends BaseInspection {
private static final Pattern commentPattern = Pattern.compile("(?i)falls?\\s*thro?u");
@Override
- public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
- super.visitSwitchStatement(statement);
- final PsiCodeBlock body = statement.getBody();
+ public void visitSwitchStatement(@NotNull PsiSwitchStatement switchStatement) {
+ super.visitSwitchStatement(switchStatement);
+ final PsiCodeBlock body = switchStatement.getBody();
if (body == null) {
return;
}
final PsiStatement[] statements = body.getStatements();
for (int i = 1; i < statements.length; i++) {
- final PsiStatement child = statements[i];
- if (!(child instanceof PsiSwitchLabelStatement)) {
+ final PsiStatement statement = statements[i];
+ if (!(statement instanceof PsiSwitchLabelStatement)) {
continue;
}
- final PsiElement previousSibling = PsiTreeUtil.skipSiblingsBackward(child, PsiWhiteSpace.class);
+ final PsiElement previousSibling = PsiTreeUtil.skipSiblingsBackward(statement, PsiWhiteSpace.class);
if (previousSibling instanceof PsiComment) {
final PsiComment comment = (PsiComment)previousSibling;
final String commentText = comment.getText();
@@ -100,9 +100,13 @@ public class FallthruInSwitchStatementInspection extends BaseInspection {
continue;
}
}
- final PsiStatement previousStatement = PsiTreeUtil.getPrevSiblingOfType(child, PsiStatement.class);
+ final PsiStatement previousStatement = PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class);
+ if (previousStatement instanceof PsiSwitchLabelStatement) {
+ // don't warn if there are no regular statements after the switch label
+ continue;
+ }
if (ControlFlowUtils.statementMayCompleteNormally(previousStatement)) {
- registerError(child);
+ registerError(statement);
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java
index 02d49095d541..b24f5203b0b2 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,30 +24,23 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.ExtractMethodFix;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import javax.swing.JComponent;
-import javax.swing.JFormattedTextField;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
+import javax.swing.*;
+import java.awt.*;
import java.text.NumberFormat;
import java.util.HashSet;
import java.util.Set;
-public class OverlyComplexBooleanExpressionInspection
- extends BaseInspection {
+public class OverlyComplexBooleanExpressionInspection extends BaseInspection {
- private static final Set<String> s_booleanOperators =
- new HashSet<String>(5);
+ private static final Set<IElementType> s_booleanOperators = new HashSet<IElementType>(5);
static {
- s_booleanOperators.add("&&");
- s_booleanOperators.add("||");
- s_booleanOperators.add("^");
- s_booleanOperators.add("&");
- s_booleanOperators.add("|");
+ s_booleanOperators.add(JavaTokenType.ANDAND);
+ s_booleanOperators.add(JavaTokenType.OROR);
+ s_booleanOperators.add(JavaTokenType.XOR);
+ s_booleanOperators.add(JavaTokenType.AND);
+ s_booleanOperators.add(JavaTokenType.OR);
}
/**
@@ -63,32 +56,28 @@ public class OverlyComplexBooleanExpressionInspection
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "overly.complex.boolean.expression.display.name");
+ return InspectionGadgetsBundle.message("overly.complex.boolean.expression.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "overly.complex.boolean.expression.problem.descriptor");
+ final Integer termCount = (Integer)infos[0];
+ return InspectionGadgetsBundle.message("overly.complex.boolean.expression.problem.descriptor", termCount);
}
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final CheckBox ignoreConjunctionsDisjunctionsCheckBox =
- new CheckBox(InspectionGadgetsBundle.message(
- "overly.complex.boolean.expression.ignore.option"),
+ new CheckBox(InspectionGadgetsBundle.message("overly.complex.boolean.expression.ignore.option"),
this, "m_ignorePureConjunctionsDisjunctions");
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
- final JFormattedTextField termLimitTextField =
- prepareNumberEditor("m_limit");
+ final JFormattedTextField termLimitTextField = prepareNumberEditor("m_limit");
final GridBagConstraints constraints = new GridBagConstraints();
- final JLabel label = new JLabel(InspectionGadgetsBundle.message(
- "overly.complex.boolean.expression.max.terms.option"));
+ final JLabel label = new JLabel(InspectionGadgetsBundle.message("overly.complex.boolean.expression.max.terms.option"));
constraints.anchor = GridBagConstraints.BASELINE_LEADING;
constraints.fill = GridBagConstraints.HORIZONTAL;
@@ -122,26 +111,22 @@ public class OverlyComplexBooleanExpressionInspection
return new OverlyComplexBooleanExpressionVisitor();
}
- private class OverlyComplexBooleanExpressionVisitor
- extends BaseInspectionVisitor {
+ private class OverlyComplexBooleanExpressionVisitor extends BaseInspectionVisitor {
@Override
- public void visitBinaryExpression(
- @NotNull PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
+ public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) {
+ super.visitPolyadicExpression(expression);
checkExpression(expression);
}
@Override
- public void visitPrefixExpression(
- @NotNull PsiPrefixExpression expression) {
+ public void visitPrefixExpression(@NotNull PsiPrefixExpression expression) {
super.visitPrefixExpression(expression);
checkExpression(expression);
}
@Override
- public void visitParenthesizedExpression(
- @NotNull PsiParenthesizedExpression expression) {
+ public void visitParenthesizedExpression(@NotNull PsiParenthesizedExpression expression) {
super.visitParenthesizedExpression(expression);
checkExpression(expression);
}
@@ -150,112 +135,78 @@ public class OverlyComplexBooleanExpressionInspection
if (!isBoolean(expression)) {
return;
}
- if (isParentBoolean(expression)) {
+ final PsiElement parent = expression.getParent();
+ if (parent instanceof PsiExpression && isBoolean((PsiExpression)parent)) {
return;
}
final int numTerms = countTerms(expression);
if (numTerms <= m_limit) {
return;
}
- if (m_ignorePureConjunctionsDisjunctions &&
- expression instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final PsiJavaToken sign = binaryExpression.getOperationSign();
- final String signText = sign.getText();
- if (s_booleanOperators.contains(signText)) {
- if (isPureConjunctionDisJunction(expression, signText)) {
- return;
- }
- }
+ if (m_ignorePureConjunctionsDisjunctions && isPureConjunctionDisjunction(expression)) {
+ return;
}
- registerError(expression);
+ registerError(expression, Integer.valueOf(numTerms));
}
private int countTerms(PsiExpression expression) {
if (!isBoolean(expression)) {
return 1;
}
- if (expression instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final PsiExpression lhs = binaryExpression.getLOperand();
- final PsiExpression rhs = binaryExpression.getROperand();
- return countTerms(lhs) + countTerms(rhs);
+ if (expression instanceof PsiPolyadicExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ int count = 0;
+ for (PsiExpression operand : operands) {
+ count += countTerms(operand);
+ }
+ return count;
}
else if (expression instanceof PsiPrefixExpression) {
- final PsiPrefixExpression prefixExpression =
- (PsiPrefixExpression)expression;
- final PsiExpression operand = prefixExpression.getOperand();
- return countTerms(operand);
+ final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression;
+ return countTerms(prefixExpression.getOperand());
}
else if (expression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)expression;
- final PsiExpression contents =
- parenthesizedExpression.getExpression();
- return countTerms(contents);
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
+ return countTerms(parenthesizedExpression.getExpression());
}
return 1;
}
- private boolean isParentBoolean(PsiExpression expression) {
- final PsiElement parent = expression.getParent();
- if (!(parent instanceof PsiExpression)) {
- return false;
- }
- return isBoolean((PsiExpression)parent);
- }
-
private boolean isBoolean(PsiExpression expression) {
- if (expression instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final PsiJavaToken sign = binaryExpression.getOperationSign();
- final String signText = sign.getText();
- return s_booleanOperators.contains(signText);
+ if (expression instanceof PsiPolyadicExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ return s_booleanOperators.contains(polyadicExpression.getOperationTokenType());
}
else if (expression instanceof PsiPrefixExpression) {
- final PsiPrefixExpression prefixExpression =
- (PsiPrefixExpression)expression;
- final IElementType tokenType = prefixExpression.getOperationTokenType();
- return tokenType.equals(JavaTokenType.EXCL);
+ final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression;
+ return JavaTokenType.EXCL.equals(prefixExpression.getOperationTokenType());
}
else if (expression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)expression;
- final PsiExpression contents =
- parenthesizedExpression.getExpression();
- return isBoolean(contents);
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
+ return isBoolean(parenthesizedExpression.getExpression());
}
return false;
}
- private boolean isPureConjunctionDisJunction(
- @Nullable PsiExpression expression,
- @NotNull String operator) {
- if (expression == null) {
+ private boolean isPureConjunctionDisjunction(PsiExpression expression) {
+ if (!(expression instanceof PsiPolyadicExpression)) {
return false;
}
- if (expression instanceof PsiPrefixExpression ||
- expression instanceof PsiParenthesizedExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ final IElementType sign = polyadicExpression.getOperationTokenType();
+ if (!s_booleanOperators.contains(sign)) {
return false;
}
- if (!(expression instanceof PsiBinaryExpression)) {
- return true;
- }
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final PsiJavaToken sign = binaryExpression.getOperationSign();
- final String signText = sign.getText();
- if (s_booleanOperators.contains(signText) &&
- !operator.equals(signText)) {
- return false;
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ for (PsiExpression operand : operands) {
+ if (!(operand instanceof PsiReferenceExpression) &&
+ !(operand instanceof PsiMethodCallExpression) &&
+ !(operand instanceof PsiLiteralExpression)) {
+ return false;
+ }
}
- final PsiExpression lOperand = binaryExpression.getLOperand();
- final PsiExpression rOperand = binaryExpression.getROperand();
- return isPureConjunctionDisJunction(lOperand, operator) &&
- isPureConjunctionDisJunction(rOperand, operator);
+ return true;
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java
index b522c2f1e176..953bbe18e771 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -183,17 +183,19 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
}
buildSimplifiedExpression(expressions, "==", negate, out);
}
+ else {
+ out.append(expression.getText());
+ }
}
private void buildSimplifiedExpression(List<PsiExpression> expressions, String token, boolean negate, StringBuilder out) {
if (expressions.size() == 1) {
final PsiExpression expression = expressions.get(0);
- final String expressionText = expression.getText();
if (isBoxedTypeComparison(token, expression)) {
- out.append(expressionText).append(" != null && ");
+ out.append(expression.getText()).append(" != null && ");
}
if (!negate) {
- out.append(expressionText);
+ out.append(expression.getText());
return;
}
if (ComparisonUtils.isComparison(expression)) {
@@ -206,10 +208,10 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
}
else {
if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.PREFIX_PRECEDENCE) {
- out.append("!(").append(expressionText).append(')');
+ out.append("!(").append(expression.getText()).append(')');
}
else {
- out.append('!').append(expressionText);
+ out.append('!').append(expression.getText());
}
}
}
@@ -221,11 +223,19 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
for (PsiExpression expression : expressions) {
if (useToken) {
out.append(token);
+ final PsiElement previousSibling = expression.getPrevSibling();
+ if (previousSibling instanceof PsiWhiteSpace) {
+ out.append(previousSibling.getText());
+ }
}
else {
useToken = true;
}
buildSimplifiedExpression(expression, out);
+ final PsiElement nextSibling = expression.getNextSibling();
+ if (nextSibling instanceof PsiWhiteSpace) {
+ out.append(nextSibling.getText());
+ }
}
if (negate) {
out.append(')');
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessNullCheckInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessNullCheckInspection.java
index 49d523a38e7a..1500f27a01aa 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessNullCheckInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessNullCheckInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Jetbrains
+ * Copyright 2011-2013 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.
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -63,25 +62,28 @@ public class PointlessNullCheckInspection extends BaseInspection {
@Override
public InspectionGadgetsFix buildFix(Object... infos) {
- return new PointlessNullCheckFix();
+ final PsiExpression expression = (PsiExpression)infos[0];
+ return new PointlessNullCheckFix(expression.getText());
}
private static class PointlessNullCheckFix extends InspectionGadgetsFix {
+ private final String myExpressionText;
+
+ public PointlessNullCheckFix(String expressionText) {
+ myExpressionText = expressionText;
+ }
+
@Override
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "pointless.nullcheck.simplify.quickfix");
+ return InspectionGadgetsBundle.message("pointless.nullcheck.simplify.quickfix", myExpressionText);
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
- final PsiBinaryExpression binaryExpression =
- PsiTreeUtil.getParentOfType(element,
- PsiBinaryExpression.class);
+ final PsiBinaryExpression binaryExpression = PsiTreeUtil.getParentOfType(element, PsiBinaryExpression.class);
if (binaryExpression == null) {
return;
}
@@ -164,7 +166,7 @@ public class PointlessNullCheckInspection extends BaseInspection {
if (!referencesEqual(referenceExpression1, referenceExpression2)) {
return;
}
- registerError(binaryExpression);
+ registerError(binaryExpression, binaryExpression);
}
@Nullable
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/SimplifiableEqualsExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/SimplifiableEqualsExpressionInspection.java
index 545e44c3c8f5..5469e57f6b6c 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/SimplifiableEqualsExpressionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/SimplifiableEqualsExpressionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2012 Bas Leijdekkers
+ * Copyright 2011-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiUtil;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -29,6 +28,7 @@ import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ExpressionUtils;
import com.siyeh.ig.psiutils.ParenthesesUtils;
import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -66,7 +66,7 @@ public class SimplifiableEqualsExpressionInspection extends BaseInspection {
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = ParenthesesUtils.getParentSkipParentheses(element);
if (!(parent instanceof PsiPolyadicExpression)) {
@@ -78,11 +78,13 @@ public class SimplifiableEqualsExpressionInspection extends BaseInspection {
return;
}
PsiExpression operand = ParenthesesUtils.stripParentheses(operands[1]);
+ @NonNls final StringBuilder newExpressionText = new StringBuilder();
if (operand instanceof PsiPrefixExpression) {
final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)operand;
if (!JavaTokenType.EXCL.equals(prefixExpression.getOperationTokenType())) {
return;
}
+ newExpressionText.append('!');
operand = ParenthesesUtils.stripParentheses(prefixExpression.getOperand());
}
if (!(operand instanceof PsiMethodCallExpression)) {
@@ -102,41 +104,41 @@ public class SimplifiableEqualsExpressionInspection extends BaseInspection {
}
final PsiExpression argument = arguments[0];
final PsiType type = argument.getType();
- final String newQualifierText;
if (PsiType.BOOLEAN.equals(type)) {
final Object value = ExpressionUtils.computeConstantExpression(argument);
if (Boolean.TRUE.equals(value)) {
- newQualifierText = "java.lang.Boolean.TRUE";
+ newExpressionText.append("java.lang.Boolean.TRUE");
}
else if (Boolean.FALSE.equals(value)) {
- newQualifierText = "java.lang.Boolean.FALSE";
+ newExpressionText.append("java.lang.Boolean.FALSE");
}
else {
- newQualifierText = "java.lang.Boolean.valueOf(" + argument.getText() + ")";
+ newExpressionText.append("java.lang.Boolean.valueOf(").append(argument.getText()).append(')');
}
}
else if (PsiType.BYTE.equals(type)) {
- newQualifierText = "java.lang.Byte.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Byte.valueOf(").append(argument.getText()).append(')');
}
else if (PsiType.SHORT.equals(type)) {
- newQualifierText = "java.lang.Short.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Short.valueOf(").append(argument.getText()).append(')');
}
else if (PsiType.INT.equals(type)) {
- newQualifierText = "java.lang.Integer.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Integer.valueOf(").append(argument.getText()).append(')');
}
else if (PsiType.LONG.equals(type)) {
- newQualifierText = "java.lang.Long.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Long.valueOf(").append(argument.getText()).append(')');
}
else if (PsiType.FLOAT.equals(type)) {
- newQualifierText = "java.lang.Float.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Float.valueOf(").append(argument.getText()).append(')');
}
else if (PsiType.DOUBLE.equals(type)) {
- newQualifierText = "java.lang.Double.valueOf(" + argument.getText() + ')';
+ newExpressionText.append("java.lang.Double.valueOf(").append(argument.getText()).append(')');
}
else {
- newQualifierText = argument.getText();
+ newExpressionText.append(argument.getText());
}
- replaceExpression(polyadicExpression, newQualifierText + "." + referenceName + "(" + qualifier.getText() + ")");
+ newExpressionText.append('.').append(referenceName).append('(').append(qualifier.getText()).append(')');
+ replaceExpression(polyadicExpression, newExpressionText.toString());
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/MakeClassFinalFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/MakeClassFinalFix.java
index 4abf7a9dd66d..9691da48d6a2 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/MakeClassFinalFix.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/MakeClassFinalFix.java
@@ -69,6 +69,7 @@ public class MakeClassFinalFix extends InspectionGadgetsFix {
return;
}
modifierList.setModifierProperty(PsiModifier.FINAL, true);
+ modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
return;
}
final MultiMap<PsiElement, String> conflicts = new MultiMap();
@@ -90,6 +91,7 @@ public class MakeClassFinalFix extends InspectionGadgetsFix {
final AccessToken token = WriteAction.start();
try {
modifierList.setModifierProperty(PsiModifier.FINAL, true);
+ modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
}
finally {
token.finish();
@@ -103,6 +105,7 @@ public class MakeClassFinalFix extends InspectionGadgetsFix {
}
if (conflictsDialogOK) {
modifierList.setModifierProperty(PsiModifier.FINAL, true);
+ modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoBoxingInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoBoxingInspection.java
index 58365dc85ad3..fddeb66b389a 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoBoxingInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/AutoBoxingInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,20 +17,16 @@ package com.siyeh.ig.jdk;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
-import com.intellij.lang.StdLanguages;
+import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
-import com.siyeh.ig.psiutils.ClassUtils;
-import com.siyeh.ig.psiutils.ExpectedTypeUtils;
-import com.siyeh.ig.psiutils.MethodCallUtils;
-import com.siyeh.ig.psiutils.TypeUtils;
+import com.siyeh.ig.psiutils.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -49,8 +45,7 @@ public class AutoBoxingInspection extends BaseInspection {
/**
* @noinspection StaticCollection
*/
- @NonNls static final Map<String, String> s_boxingClasses =
- new HashMap<String, String>(8);
+ @NonNls static final Map<String, String> s_boxingClasses = new HashMap<String, String>(8);
static {
s_boxingClasses.put("byte", CommonClassNames.JAVA_LANG_BYTE);
@@ -85,15 +80,13 @@ public class AutoBoxingInspection extends BaseInspection {
@Override
@NotNull
public String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "auto.boxing.problem.descriptor");
+ return InspectionGadgetsBundle.message("auto.boxing.problem.descriptor");
}
@Override
@Nullable
public JComponent createOptionsPanel() {
- return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
- "auto.boxing.ignore.added.to.collection.option"), this,
+ return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("auto.boxing.ignore.added.to.collection.option"), this,
"ignoreAddedToCollection");
}
@@ -111,17 +104,13 @@ public class AutoBoxingInspection extends BaseInspection {
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "auto.boxing.make.boxing.explicit.quickfix");
+ return InspectionGadgetsBundle.message("auto.boxing.make.boxing.explicit.quickfix");
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
- final PsiExpression expression =
- (PsiExpression)descriptor.getPsiElement();
- final PsiType expectedType =
- ExpectedTypeUtils.findExpectedType(expression, false);
+ public void doFix(Project project, ProblemDescriptor descriptor) {
+ final PsiExpression expression = (PsiExpression)descriptor.getPsiElement();
+ final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
if (expectedType == null) {
return;
}
@@ -141,7 +130,11 @@ public class AutoBoxingInspection extends BaseInspection {
if (shortcutReplace(expression, classToConstruct)) {
return;
}
- @NonNls final String expressionText = expression.getText();
+ final PsiExpression strippedExpression = ParenthesesUtils.stripParentheses(expression);
+ if (strippedExpression == null) {
+ return;
+ }
+ @NonNls final String expressionText = strippedExpression.getText();
@NonNls final String newExpression;
if ("true".equals(expressionText)) {
newExpression = "java.lang.Boolean.TRUE";
@@ -150,84 +143,59 @@ public class AutoBoxingInspection extends BaseInspection {
newExpression = "java.lang.Boolean.FALSE";
}
else {
- newExpression = classToConstruct + ".valueOf(" +
- expressionText + ')';
+ newExpression = classToConstruct + ".valueOf(" + expressionText + ')';
}
replaceExpression(expression, newExpression);
}
- private static boolean shortcutReplace(PsiExpression expression,
- String classToConstruct) {
+ private static boolean shortcutReplace(PsiExpression expression, String classToConstruct) {
if (!(expression instanceof PsiMethodCallExpression)) {
return false;
}
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)expression;
- final PsiReferenceExpression methodExpression =
- methodCallExpression.getMethodExpression();
- final PsiExpression qualifierExpression =
- methodExpression.getQualifierExpression();
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
+ final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
+ final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (qualifierExpression == null) {
return false;
}
if (classToConstruct.equals(CommonClassNames.JAVA_LANG_INTEGER)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_INTEGER, PsiType.INT,
- "intValue")) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_INTEGER, PsiType.INT, "intValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_SHORT)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_SHORT, PsiType.SHORT,
- "shortValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_SHORT)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_SHORT, PsiType.SHORT, "shortValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_BYTE)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_BYTE, PsiType.BYTE,
- "byteValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_BYTE)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_BYTE, PsiType.BYTE, "byteValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_CHARACTER)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_CHARACTER, PsiType.CHAR,
- "charValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_CHARACTER)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_CHARACTER, PsiType.CHAR, "charValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_LONG)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_LONG, PsiType.LONG,
- "longValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_LONG)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_LONG, PsiType.LONG, "longValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_FLOAT)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_FLOAT, PsiType.FLOAT,
- "floatValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_FLOAT)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_FLOAT, PsiType.FLOAT, "floatValue")) {
expression.replace(qualifierExpression);
return true;
}
}
- else if (classToConstruct.equals(
- CommonClassNames.JAVA_LANG_DOUBLE)) {
- if (MethodCallUtils.isCallToMethod(methodCallExpression,
- CommonClassNames.JAVA_LANG_DOUBLE, PsiType.DOUBLE,
- "doubleValue")) {
+ else if (classToConstruct.equals(CommonClassNames.JAVA_LANG_DOUBLE)) {
+ if (MethodCallUtils.isCallToMethod(methodCallExpression, CommonClassNames.JAVA_LANG_DOUBLE, PsiType.DOUBLE, "doubleValue")) {
expression.replace(qualifierExpression);
return true;
}
@@ -240,7 +208,7 @@ public class AutoBoxingInspection extends BaseInspection {
@Override
public void visitElement(PsiElement element) {
- if (element.getLanguage() != StdLanguages.JAVA) {
+ if (element.getLanguage() != JavaLanguage.INSTANCE) {
return;
}
if (!PsiUtil.isLanguageLevel5OrHigher(element)) {
@@ -250,79 +218,74 @@ public class AutoBoxingInspection extends BaseInspection {
}
@Override
- public void visitArrayAccessExpression(
- PsiArrayAccessExpression expression) {
+ public void visitArrayAccessExpression(PsiArrayAccessExpression expression) {
super.visitArrayAccessExpression(expression);
checkExpression(expression);
}
@Override
- public void visitBinaryExpression(
- PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
+ public void visitAssignmentExpression(PsiAssignmentExpression expression) {
+ super.visitAssignmentExpression(expression);
checkExpression(expression);
}
@Override
- public void visitConditionalExpression(
- PsiConditionalExpression expression) {
+ public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
checkExpression(expression);
}
@Override
- public void visitLiteralExpression(
- PsiLiteralExpression expression) {
+ public void visitInstanceOfExpression(PsiInstanceOfExpression expression) {
+ super.visitInstanceOfExpression(expression);
+ checkExpression(expression);
+ }
+
+ @Override
+ public void visitLiteralExpression(PsiLiteralExpression expression) {
super.visitLiteralExpression(expression);
checkExpression(expression);
}
@Override
- public void visitPostfixExpression(
- PsiPostfixExpression expression) {
- super.visitPostfixExpression(expression);
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
+ super.visitMethodCallExpression(expression);
checkExpression(expression);
}
@Override
- public void visitPrefixExpression(
- PsiPrefixExpression expression) {
- super.visitPrefixExpression(expression);
+ public void visitParenthesizedExpression(PsiParenthesizedExpression expression) {
+ super.visitParenthesizedExpression(expression);
checkExpression(expression);
}
@Override
- public void visitReferenceExpression(
- PsiReferenceExpression expression) {
- super.visitReferenceExpression(expression);
+ public void visitPolyadicExpression(PsiPolyadicExpression expression) {
+ super.visitPolyadicExpression(expression);
checkExpression(expression);
}
@Override
- public void visitMethodCallExpression(
- PsiMethodCallExpression expression) {
- super.visitMethodCallExpression(expression);
+ public void visitPostfixExpression(PsiPostfixExpression expression) {
+ super.visitPostfixExpression(expression);
checkExpression(expression);
}
@Override
- public void visitTypeCastExpression(
- PsiTypeCastExpression expression) {
- super.visitTypeCastExpression(expression);
+ public void visitPrefixExpression(PsiPrefixExpression expression) {
+ super.visitPrefixExpression(expression);
checkExpression(expression);
}
@Override
- public void visitAssignmentExpression(
- PsiAssignmentExpression expression) {
- super.visitAssignmentExpression(expression);
+ public void visitReferenceExpression(PsiReferenceExpression expression) {
+ super.visitReferenceExpression(expression);
checkExpression(expression);
}
@Override
- public void visitParenthesizedExpression(
- PsiParenthesizedExpression expression) {
- super.visitParenthesizedExpression(expression);
+ public void visitTypeCastExpression(PsiTypeCastExpression expression) {
+ super.visitTypeCastExpression(expression);
checkExpression(expression);
}
@@ -331,35 +294,22 @@ public class AutoBoxingInspection extends BaseInspection {
return;
}
final PsiType expressionType = expression.getType();
- if (expressionType == null) {
+ if (expressionType == null || expressionType.equals(PsiType.VOID) || !TypeConversionUtil.isPrimitiveAndNotNull(expressionType)) {
return;
}
- if (expressionType.equals(PsiType.VOID)) {
- return;
- }
- if (!TypeConversionUtil.isPrimitiveAndNotNull(expressionType)) {
- return;
- }
- final PsiPrimitiveType primitiveType =
- (PsiPrimitiveType)expressionType;
- final PsiClassType boxedType =
- primitiveType.getBoxedType(expression);
+ final PsiPrimitiveType primitiveType = (PsiPrimitiveType)expressionType;
+ final PsiClassType boxedType = primitiveType.getBoxedType(expression);
if (boxedType == null) {
return;
}
- final PsiType expectedType =
- ExpectedTypeUtils.findExpectedType(expression, false);
- if (expectedType == null) {
- return;
- }
- if (ClassUtils.isPrimitive(expectedType)) {
+ final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
+ if (expectedType == null || ClassUtils.isPrimitive(expectedType)) {
return;
}
if (!expectedType.isAssignableFrom(boxedType)) {
// JLS 5.2 Assignment Conversion
// check if a narrowing primitive conversion is applicable
- if (!(expectedType instanceof PsiClassType) ||
- !PsiUtil.isConstantExpression(expression)) {
+ if (!(expectedType instanceof PsiClassType) || !PsiUtil.isConstantExpression(expression)) {
return;
}
final PsiClassType classType = (PsiClassType)expectedType;
@@ -367,10 +317,8 @@ public class AutoBoxingInspection extends BaseInspection {
if (!convertableBoxedClassNames.contains(className)) {
return;
}
- if (!PsiType.BYTE.equals(expressionType) &&
- !PsiType.CHAR.equals(expressionType) &&
- !PsiType.SHORT.equals(expressionType) &&
- !PsiType.INT.equals(expressionType)) {
+ if (!PsiType.BYTE.equals(expressionType) && !PsiType.CHAR.equals(expressionType) &&
+ !PsiType.SHORT.equals(expressionType) && !PsiType.INT.equals(expressionType)) {
return;
}
}
@@ -390,21 +338,14 @@ public class AutoBoxingInspection extends BaseInspection {
if (!(grandParent instanceof PsiMethodCallExpression)) {
return false;
}
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)grandParent;
- final PsiReferenceExpression methodExpression =
- methodCallExpression.getMethodExpression();
- @NonNls final String methodName =
- methodExpression.getReferenceName();
- if (!"put".equals(methodName) && !"set".equals(methodName) &&
- !"add".equals(methodName)) {
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
+ final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
+ @NonNls final String methodName = methodExpression.getReferenceName();
+ if (!"put".equals(methodName) && !"set".equals(methodName) && !"add".equals(methodName)) {
return false;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
- return TypeUtils.expressionHasTypeOrSubtype(qualifier,
- CommonClassNames.JAVA_UTIL_COLLECTION,
- CommonClassNames.JAVA_UTIL_MAP) != null;
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
+ return TypeUtils.expressionHasTypeOrSubtype(qualifier, CommonClassNames.JAVA_UTIL_COLLECTION, CommonClassNames.JAVA_UTIL_MAP) != null;
}
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java
index 564e93955541..ecbb3a369540 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/jdk/ForeachStatementInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
+import com.intellij.psi.util.InheritanceUtil;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -137,6 +138,10 @@ public class ForeachStatementInspection extends BaseInspection {
@Override
public void visitForeachStatement(@NotNull PsiForeachStatement statement) {
super.visitForeachStatement(statement);
+ final PsiExpression iteratedValue = statement.getIteratedValue();
+ if (iteratedValue == null || !InheritanceUtil.isInheritor(iteratedValue.getType(), CommonClassNames.JAVA_LANG_ITERABLE)) {
+ return;
+ }
registerStatementError(statement);
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/logging/LogStatementGuardedByLogConditionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/LogStatementGuardedByLogConditionInspection.java
index 8a773ed83bf9..95a1b73e0a11 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/logging/LogStatementGuardedByLogConditionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/LogStatementGuardedByLogConditionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2012 Bas Leijdekkers
+ * Copyright 2008-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.ui.CheckBox;
import com.intellij.util.ui.FormBuilder;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -57,6 +58,9 @@ public class LogStatementGuardedByLogConditionInspection extends BaseInspection
final List<String> logMethodNameList = new ArrayList();
final List<String> logConditionMethodNameList = new ArrayList();
+ @SuppressWarnings("PublicField")
+ public boolean flagAllUnguarded = false;
+
public LogStatementGuardedByLogConditionInspection() {
parseString(loggerMethodAndconditionMethodNames, logMethodNameList, logConditionMethodNameList);
}
@@ -84,6 +88,8 @@ public class LogStatementGuardedByLogConditionInspection extends BaseInspection
InspectionGadgetsBundle.message("log.condition.text")));
panel.add(UiUtils.createAddRemovePanel(table), BorderLayout.CENTER);
panel.add(FormBuilder.createFormBuilder().addLabeledComponent(classNameLabel, loggerClassNameField).getPanel(), BorderLayout.NORTH);
+ panel.add(new CheckBox(InspectionGadgetsBundle.message("log.statement.guarded.by.log.condition.flag.all.unguarded.option"),
+ this, "flagAllUnguarded"), BorderLayout.SOUTH);
return panel;
}
@@ -215,9 +221,17 @@ public class LogStatementGuardedByLogConditionInspection extends BaseInspection
if (arguments.length == 0) {
return;
}
- final PsiExpression firstArgument = arguments[0];
- if (PsiUtil.isConstantExpression(firstArgument)) {
- return;
+ if (!flagAllUnguarded) {
+ boolean constant = true;
+ for (PsiExpression argument : arguments) {
+ if (!PsiUtil.isConstantExpression(argument)) {
+ constant = false;
+ break;
+ }
+ }
+ if (constant) {
+ return;
+ }
}
registerMethodCallError(expression);
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java
new file mode 100644
index 000000000000..0a6ef31fcc7e
--- /dev/null
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspection.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2013 Bas Leijdekkers
+ *
+ * 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.logging;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.util.containers.ContainerUtilRt;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.psiutils.ExpressionUtils;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Set;
+
+public class PlaceholderCountMatchesArgumentCountInspection extends BaseInspection {
+
+ @NonNls
+ private static final Set<String> loggingMethodNames = ContainerUtilRt.newHashSet("trace", "debug", "info", "warn", "error");
+
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.display.name");
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ final int argumentCount = ((Integer)infos[0]).intValue();
+ final int placeholderCount = ((Integer)infos[1]).intValue();
+ if (argumentCount > placeholderCount) {
+ return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.more.problem.descriptor",
+ argumentCount, placeholderCount);
+ }
+ else {
+ return InspectionGadgetsBundle.message("placeholder.count.matches.argument.count.fewer.problem.descriptor",
+ argumentCount, placeholderCount);
+ }
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new PlaceholderCountMatchesArgumentCountVisitor();
+ }
+
+ private static class PlaceholderCountMatchesArgumentCountVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
+ super.visitMethodCallExpression(expression);
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+ final String name = methodExpression.getReferenceName();
+ if (!loggingMethodNames.contains(name)) {
+ return;
+ }
+ final PsiExpressionList argumentList = expression.getArgumentList();
+ final PsiExpression[] arguments = argumentList.getExpressions();
+ if (arguments.length == 0) {
+ return;
+ }
+ final PsiExpression firstArgument = arguments[0];
+ final int placeholderCount;
+ final int argumentCount;
+ if (InheritanceUtil.isInheritor(firstArgument.getType(), "org.slf4j.Marker")) {
+ if (arguments.length < 2) {
+ return;
+ }
+ final PsiExpression secondArgument = arguments[1];
+ if (!ExpressionUtils.hasStringType(secondArgument)) {
+ return;
+ }
+ final String value = (String)ExpressionUtils.computeConstantExpression(secondArgument);
+ if (value == null) {
+ return;
+ }
+ placeholderCount = countPlaceholders(value);
+ argumentCount = hasThrowableType(arguments[arguments.length - 1]) ? arguments.length - 3 : arguments.length - 2;
+ }
+ else if (ExpressionUtils.hasStringType(firstArgument)) {
+ final String value = (String)ExpressionUtils.computeConstantExpression(firstArgument);
+ if (value == null) {
+ return;
+ }
+ placeholderCount = countPlaceholders(value);
+ argumentCount = hasThrowableType(arguments[arguments.length - 1]) ? arguments.length - 2 : arguments.length - 1;
+ } else {
+ return;
+ }
+ if (placeholderCount == argumentCount) {
+ return;
+ }
+ registerMethodCallError(expression, argumentCount, placeholderCount);
+ }
+
+ private static boolean hasThrowableType(PsiExpression lastArgument) {
+ return InheritanceUtil.isInheritor(lastArgument.getType(), "java.lang.Throwable");
+ }
+
+ public static int countPlaceholders(String value) {
+ int count = 0;
+ int index = value.indexOf("{}");
+ while (index >= 0) {
+ if (index <= 0 || value.charAt(index - 1) != '\\') {
+ count++;
+ }
+ index = value.indexOf("{}", index + 1);
+ }
+ return count;
+ }
+ }
+}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspection.java
index 85adba71c3bc..4c96475dd177 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -25,9 +25,11 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ExpressionUtils;
+import com.siyeh.ig.psiutils.ParenthesesUtils;
import com.siyeh.ig.psiutils.TypeUtils;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -40,6 +42,7 @@ import java.util.Set;
*/
public class StringConcatenationArgumentToLogCallInspection extends BaseInspection {
+ @NonNls
private static final Set<String> logNames = new THashSet<String>();
static {
logNames.add("trace");
@@ -95,8 +98,8 @@ public class StringConcatenationArgumentToLogCallInspection extends BaseInspecti
if (arguments.length == 0) {
return;
}
- final StringBuilder newMethodCall = new StringBuilder(methodCallExpression.getMethodExpression().getText());
- newMethodCall.append("(");
+ @NonNls final StringBuilder newMethodCall = new StringBuilder(methodCallExpression.getMethodExpression().getText());
+ newMethodCall.append('(');
PsiExpression argument = arguments[0];
int usedArguments;
if (!(argument instanceof PsiPolyadicExpression)) {
@@ -137,11 +140,11 @@ public class StringConcatenationArgumentToLogCallInspection extends BaseInspecti
boolean inStringLiteral = false;
for (PsiExpression operand : operands) {
if (ExpressionUtils.isEvaluatedAtCompileTime(operand)) {
- if (ExpressionUtils.hasStringType(operand)) {
+ if (ExpressionUtils.hasStringType(operand) && operand instanceof PsiLiteralExpression) {
final String text = operand.getText();
final int count = StringUtil.getOccurrenceCount(text, "{}");
for (int i = 0; i < count && usedArguments + i < arguments.length; i++) {
- newArguments.add((PsiExpression)arguments[i + usedArguments].copy());
+ newArguments.add(ParenthesesUtils.stripParentheses((PsiExpression)arguments[i + usedArguments].copy()));
}
usedArguments += count;
if (!inStringLiteral) {
@@ -165,7 +168,7 @@ public class StringConcatenationArgumentToLogCallInspection extends BaseInspecti
}
}
else {
- newArguments.add((PsiExpression)operand.copy());
+ newArguments.add(ParenthesesUtils.stripParentheses((PsiExpression)operand.copy()));
if (!inStringLiteral) {
if (addPlus) {
newMethodCall.append('+');
@@ -193,13 +196,18 @@ public class StringConcatenationArgumentToLogCallInspection extends BaseInspecti
else {
comma =true;
}
- newMethodCall.append(newArgument.getText());
+ if (newArgument != null) {
+ newMethodCall.append(newArgument.getText());
+ }
}
newMethodCall.append('}');
}
else {
for (PsiExpression newArgument : newArguments) {
- newMethodCall.append(',').append(newArgument.getText());
+ newMethodCall.append(',');
+ if (newArgument != null) {
+ newMethodCall.append(newArgument.getText());
+ }
}
}
newMethodCall.append(')');
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
index 743f5b98f49d..c5a57122701d 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfCanBeSwitchInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Bas Leijdekkers
+ * Copyright 2011-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,19 +15,20 @@
*/
package com.siyeh.ig.migration;
+import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.ui.DocumentAdapter;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ControlFlowUtils;
import com.siyeh.ig.psiutils.EquivalenceChecker;
+import com.siyeh.ig.psiutils.ParenthesesUtils;
import com.siyeh.ig.psiutils.SwitchUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
@@ -71,8 +72,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
@NotNull
@Override
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "if.can.be.switch.problem.descriptor");
+ return InspectionGadgetsBundle.message("if.can.be.switch.problem.descriptor");
}
@Override
@@ -83,12 +83,10 @@ public class IfCanBeSwitchInspection extends BaseInspection {
@Override
public JComponent createOptionsPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
- final JLabel label = new JLabel(InspectionGadgetsBundle.message(
- "if.can.be.switch.minimum.branch.option"));
+ final JLabel label = new JLabel(InspectionGadgetsBundle.message("if.can.be.switch.minimum.branch.option"));
final NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
- final JFormattedTextField valueField =
- new JFormattedTextField(formatter);
+ final JFormattedTextField valueField = new JFormattedTextField(formatter);
valueField.setValue(Integer.valueOf(minimumBranches));
valueField.setColumns(2);
final Document document = valueField.getDocument();
@@ -122,9 +120,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 2;
- final JCheckBox checkBox1 = new JCheckBox(
- InspectionGadgetsBundle.message("if.can.be.switch.int.option"),
- suggestIntSwitches);
+ final JCheckBox checkBox1 = new JCheckBox(InspectionGadgetsBundle.message("if.can.be.switch.int.option"), suggestIntSwitches);
final ButtonModel model1 = checkBox1.getModel();
model1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
@@ -134,9 +130,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
panel.add(checkBox1, constraints);
constraints.gridy = 2;
constraints.weighty = 1.0;
- final JCheckBox checkBox2 = new JCheckBox(
- InspectionGadgetsBundle.message("if.can.be.switch.enum.option"),
- suggestEnumSwitches);
+ final JCheckBox checkBox2 = new JCheckBox(InspectionGadgetsBundle.message("if.can.be.switch.enum.option"), suggestEnumSwitches);
final ButtonModel model2 = checkBox2.getModel();
model2.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
@@ -160,8 +154,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement().getParent();
if (!(element instanceof PsiIfStatement)) {
return;
@@ -171,41 +164,31 @@ public class IfCanBeSwitchInspection extends BaseInspection {
PsiStatement breakTarget = null;
String labelString = "";
if (ControlFlowUtils.statementContainsNakedBreak(ifStatement)) {
- breakTarget = PsiTreeUtil.getParentOfType(ifStatement,
- PsiLoopStatement.class, PsiSwitchStatement.class);
+ breakTarget = PsiTreeUtil.getParentOfType(ifStatement, PsiLoopStatement.class, PsiSwitchStatement.class);
if (breakTarget != null) {
final PsiElement parent = breakTarget.getParent();
if (parent instanceof PsiLabeledStatement) {
- final PsiLabeledStatement labeledStatement =
- (PsiLabeledStatement)parent;
- labelString =
- labeledStatement.getLabelIdentifier().getText();
+ final PsiLabeledStatement labeledStatement = (PsiLabeledStatement)parent;
+ labelString = labeledStatement.getLabelIdentifier().getText();
breakTarget = labeledStatement;
breaksNeedRelabeled = true;
}
else {
- labelString =
- SwitchUtils.findUniqueLabelName(ifStatement,
- "label");
+ labelString = SwitchUtils.findUniqueLabelName(ifStatement, "label");
breaksNeedRelabeled = true;
}
}
}
final PsiIfStatement statementToReplace = ifStatement;
-
- final List<IfStatementBranch> branches =
- new ArrayList<IfStatementBranch>(20);
- final PsiExpression switchExpression =
- SwitchUtils.getSwitchExpression(ifStatement,
- myMinimumBranches);
+ final PsiExpression switchExpression = SwitchUtils.getSwitchExpression(ifStatement, myMinimumBranches);
if (switchExpression == null) {
return;
}
+ final List<IfStatementBranch> branches = new ArrayList<IfStatementBranch>(20);
while (true) {
final PsiExpression condition = ifStatement.getCondition();
final PsiStatement thenBranch = ifStatement.getThenBranch();
- final IfStatementBranch ifBranch =
- new IfStatementBranch(thenBranch, false);
+ final IfStatementBranch ifBranch = new IfStatementBranch(thenBranch, false);
extractCaseExpressions(condition, switchExpression, ifBranch);
if (!branches.isEmpty()) {
extractIfComments(ifStatement, ifBranch);
@@ -220,8 +203,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
break;
}
else {
- final IfStatementBranch elseIfBranch =
- new IfStatementBranch(elseBranch, true);
+ final IfStatementBranch elseIfBranch = new IfStatementBranch(elseBranch, true);
final PsiKeyword elseKeyword = ifStatement.getElseElement();
extractIfComments(elseKeyword, elseIfBranch);
extractStatementComments(elseBranch, elseIfBranch);
@@ -230,14 +212,10 @@ public class IfCanBeSwitchInspection extends BaseInspection {
}
}
- @NonNls final StringBuilder switchStatementText =
- new StringBuilder();
- switchStatementText.append("switch(");
- switchStatementText.append(switchExpression.getText());
- switchStatementText.append("){");
+ @NonNls final StringBuilder switchStatementText = new StringBuilder();
+ switchStatementText.append("switch(").append(switchExpression.getText()).append("){");
final PsiType type = switchExpression.getType();
- final boolean castToInt = type != null &&
- type.equalsToText(CommonClassNames.JAVA_LANG_INTEGER);
+ final boolean castToInt = type != null && type.equalsToText(CommonClassNames.JAVA_LANG_INTEGER);
for (IfStatementBranch branch : branches) {
boolean hasConflicts = false;
for (IfStatementBranch testBranch : branches) {
@@ -248,40 +226,30 @@ public class IfCanBeSwitchInspection extends BaseInspection {
hasConflicts = true;
}
}
- dumpBranch(branch, castToInt, hasConflicts, breaksNeedRelabeled,
- labelString, switchStatementText);
+ dumpBranch(branch, castToInt, hasConflicts, breaksNeedRelabeled, labelString, switchStatementText);
}
switchStatementText.append('}');
- final JavaPsiFacade psiFacade =
- JavaPsiFacade.getInstance(element.getProject());
+ final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(element.getProject());
final PsiElementFactory factory = psiFacade.getElementFactory();
if (breaksNeedRelabeled) {
final StringBuilder out = new StringBuilder();
if (!(breakTarget instanceof PsiLabeledStatement)) {
- out.append(labelString);
- out.append(':');
+ out.append(labelString).append(':');
}
- termReplace(out, breakTarget, statementToReplace,
- switchStatementText);
+ termReplace(breakTarget, statementToReplace, switchStatementText, out);
final String newStatementText = out.toString();
- final PsiStatement newStatement =
- factory.createStatementFromText(newStatementText,
- element);
+ final PsiStatement newStatement = factory.createStatementFromText(newStatementText, element);
breakTarget.replace(newStatement);
}
else {
- final PsiStatement newStatement =
- factory.createStatementFromText(
- switchStatementText.toString(), element);
+ final PsiStatement newStatement = factory.createStatementFromText(switchStatementText.toString(), element);
statementToReplace.replace(newStatement);
}
}
@Nullable
- public static <T extends PsiElement> T getPrevSiblingOfType(
- @Nullable PsiElement element,
- @NotNull Class<T> aClass,
- @NotNull Class<? extends PsiElement>... stopAt) {
+ public static <T extends PsiElement> T getPrevSiblingOfType(@Nullable PsiElement element, @NotNull Class<T> aClass,
+ @NotNull Class<? extends PsiElement>... stopAt) {
if (element == null) {
return null;
}
@@ -297,18 +265,15 @@ public class IfCanBeSwitchInspection extends BaseInspection {
return (T)sibling;
}
- private static void extractIfComments(PsiElement element,
- IfStatementBranch out) {
- PsiComment comment = getPrevSiblingOfType(element,
- PsiComment.class, PsiStatement.class);
+ private static void extractIfComments(PsiElement element, IfStatementBranch out) {
+ PsiComment comment = getPrevSiblingOfType(element, PsiComment.class, PsiStatement.class);
while (comment != null) {
final PsiElement sibling = comment.getPrevSibling();
final String commentText;
if (sibling instanceof PsiWhiteSpace) {
final String whiteSpaceText = sibling.getText();
if (whiteSpaceText.startsWith("\n")) {
- commentText = whiteSpaceText.substring(1) +
- comment.getText();
+ commentText = whiteSpaceText.substring(1) + comment.getText();
}
else {
commentText = comment.getText();
@@ -318,23 +283,19 @@ public class IfCanBeSwitchInspection extends BaseInspection {
commentText = comment.getText();
}
out.addComment(commentText);
- comment = getPrevSiblingOfType(comment, PsiComment.class,
- PsiStatement.class);
+ comment = getPrevSiblingOfType(comment, PsiComment.class, PsiStatement.class);
}
}
- private static void extractStatementComments(PsiElement element,
- IfStatementBranch out) {
- PsiComment comment = getPrevSiblingOfType(element,
- PsiComment.class, PsiStatement.class, PsiKeyword.class);
+ private static void extractStatementComments(PsiElement element, IfStatementBranch out) {
+ PsiComment comment = getPrevSiblingOfType(element, PsiComment.class, PsiStatement.class, PsiKeyword.class);
while (comment != null) {
final PsiElement sibling = comment.getPrevSibling();
final String commentText;
if (sibling instanceof PsiWhiteSpace) {
final String whiteSpaceText = sibling.getText();
if (whiteSpaceText.startsWith("\n")) {
- commentText = whiteSpaceText.substring(1) +
- comment.getText();
+ commentText = whiteSpaceText.substring(1) + comment.getText();
}
else {
commentText = comment.getText();
@@ -344,14 +305,11 @@ public class IfCanBeSwitchInspection extends BaseInspection {
commentText = comment.getText();
}
out.addStatementComment(commentText);
- comment = getPrevSiblingOfType(comment, PsiComment.class,
- PsiStatement.class, PsiKeyword.class);
+ comment = getPrevSiblingOfType(comment, PsiComment.class, PsiStatement.class, PsiKeyword.class);
}
}
- private static void termReplace(
- StringBuilder out, PsiElement target,
- PsiElement replace, StringBuilder stringToReplaceWith) {
+ private static void termReplace(PsiElement target, PsiElement replace, StringBuilder stringToReplaceWith, StringBuilder out) {
if (target.equals(replace)) {
out.append(stringToReplaceWith);
}
@@ -361,95 +319,75 @@ public class IfCanBeSwitchInspection extends BaseInspection {
else {
final PsiElement[] children = target.getChildren();
for (final PsiElement child : children) {
- termReplace(out, child, replace, stringToReplaceWith);
+ termReplace(child, replace, stringToReplaceWith, out);
}
}
}
- private static void extractCaseExpressions(
- PsiExpression expression, PsiExpression switchExpression,
- IfStatementBranch values) {
+ private static void extractCaseExpressions(PsiExpression expression, PsiExpression switchExpression, IfStatementBranch branch) {
if (expression instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)expression;
- final PsiExpressionList argumentList =
- methodCallExpression.getArgumentList();
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
+ final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
final PsiExpression argument = arguments[0];
- final PsiReferenceExpression methodExpression =
- methodCallExpression.getMethodExpression();
- final PsiExpression qualifierExpression =
- methodExpression.getQualifierExpression();
- if (EquivalenceChecker.expressionsAreEquivalent(switchExpression,
- argument)) {
- values.addCaseExpression(qualifierExpression);
+ final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
+ final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
+ if (EquivalenceChecker.expressionsAreEquivalent(switchExpression, argument)) {
+ branch.addCaseExpression(qualifierExpression);
}
else {
- values.addCaseExpression(argument);
+ branch.addCaseExpression(argument);
}
}
- else if (expression instanceof PsiBinaryExpression) {
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final PsiExpression lhs = binaryExpression.getLOperand();
- final PsiExpression rhs = binaryExpression.getROperand();
- final IElementType tokenType = binaryExpression.getOperationTokenType();
+ else if (expression instanceof PsiPolyadicExpression) {
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ final IElementType tokenType = polyadicExpression.getOperationTokenType();
if (JavaTokenType.OROR.equals(tokenType)) {
- extractCaseExpressions(lhs, switchExpression,
- values);
- extractCaseExpressions(rhs, switchExpression,
- values);
+ for (PsiExpression operand : operands) {
+ extractCaseExpressions(operand, switchExpression, branch);
+ }
}
- else {
- if (EquivalenceChecker.expressionsAreEquivalent(
- switchExpression, rhs)) {
- values.addCaseExpression(lhs);
+ else if (operands.length == 2) {
+ final PsiExpression lhs = operands[0];
+ final PsiExpression rhs = operands[1];
+ if (EquivalenceChecker.expressionsAreEquivalent(switchExpression, rhs)) {
+ branch.addCaseExpression(lhs);
}
else {
- values.addCaseExpression(rhs);
+ branch.addCaseExpression(rhs);
}
}
}
else if (expression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)expression;
- final PsiExpression contents =
- parenthesizedExpression.getExpression();
- extractCaseExpressions(contents, switchExpression, values);
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)expression;
+ final PsiExpression contents = parenthesizedExpression.getExpression();
+ extractCaseExpressions(contents, switchExpression, branch);
}
}
- private static void dumpBranch(
- IfStatementBranch branch, boolean castToInt, boolean wrap,
- boolean renameBreaks, String breakLabelName,
- @NonNls StringBuilder switchStatementText) {
+ private static void dumpBranch(IfStatementBranch branch, boolean castToInt, boolean wrap, boolean renameBreaks, String breakLabelName,
+ @NonNls StringBuilder switchStatementText) {
dumpComments(branch.getComments(), switchStatementText);
if (branch.isElse()) {
switchStatementText.append("default: ");
}
else {
- for (PsiExpression caseExpression : branch.getConditions()) {
- switchStatementText.append("case ");
- switchStatementText.append(getCaseLabelText(caseExpression,
- castToInt));
- switchStatementText.append(": ");
+ for (PsiExpression caseExpression : branch.getCaseExpressions()) {
+ switchStatementText.append("case ").append(getCaseLabelText(caseExpression, castToInt)).append(": ");
}
}
dumpComments(branch.getStatementComments(), switchStatementText);
- dumpBody(branch.getStatement(), wrap, renameBreaks, breakLabelName,
- switchStatementText);
+ dumpBody(branch.getStatement(), wrap, renameBreaks, breakLabelName, switchStatementText);
}
@NonNls
- private static String getCaseLabelText(PsiExpression expression,
- boolean castToInt) {
+ private static String getCaseLabelText(PsiExpression expression, boolean castToInt) {
if (expression instanceof PsiReferenceExpression) {
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)expression;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
final PsiElement target = referenceExpression.resolve();
if (target instanceof PsiEnumConstant) {
- final PsiEnumConstant enumConstant =
- (PsiEnumConstant)target;
+ final PsiEnumConstant enumConstant = (PsiEnumConstant)target;
return enumConstant.getName();
}
}
@@ -470,42 +408,34 @@ public class IfCanBeSwitchInspection extends BaseInspection {
return expression.getText();
}
- private static void dumpComments(List<String> comments,
- StringBuilder switchStatementText) {
+ private static void dumpComments(List<String> comments, StringBuilder switchStatementText) {
if (comments.isEmpty()) {
return;
}
switchStatementText.append('\n');
for (String comment : comments) {
- switchStatementText.append(comment);
- switchStatementText.append('\n');
+ switchStatementText.append(comment).append('\n');
}
}
- private static void dumpBody(
- PsiStatement bodyStatement, boolean wrap, boolean renameBreaks,
- String breakLabelName,
- @NonNls StringBuilder switchStatementText) {
+ private static void dumpBody(PsiStatement bodyStatement, boolean wrap, boolean renameBreaks, String breakLabelName,
+ @NonNls StringBuilder switchStatementText) {
if (wrap) {
switchStatementText.append('{');
}
if (bodyStatement instanceof PsiBlockStatement) {
- final PsiCodeBlock codeBlock =
- ((PsiBlockStatement)bodyStatement).getCodeBlock();
+ final PsiCodeBlock codeBlock = ((PsiBlockStatement)bodyStatement).getCodeBlock();
final PsiElement[] children = codeBlock.getChildren();
//skip the first and last members, to unwrap the block
for (int i = 1; i < children.length - 1; i++) {
final PsiElement child = children[i];
- appendElement(switchStatementText, child, renameBreaks,
- breakLabelName);
+ appendElement(child, renameBreaks, breakLabelName, switchStatementText);
}
}
else {
- appendElement(switchStatementText, bodyStatement,
- renameBreaks, breakLabelName);
+ appendElement(bodyStatement, renameBreaks, breakLabelName, switchStatementText);
}
- if (ControlFlowUtils.statementMayCompleteNormally(
- bodyStatement)) {
+ if (ControlFlowUtils.statementMayCompleteNormally(bodyStatement)) {
switchStatementText.append("break;");
}
if (wrap) {
@@ -513,38 +443,44 @@ public class IfCanBeSwitchInspection extends BaseInspection {
}
}
- private static void appendElement(
- @NonNls StringBuilder switchStatementText,
- PsiElement element, boolean renameBreakElements,
- String breakLabelString) {
+ private static void appendElement(PsiElement element, boolean renameBreakElements, String breakLabelString,
+ @NonNls StringBuilder switchStatementText) {
final String text = element.getText();
if (!renameBreakElements) {
switchStatementText.append(text);
}
else if (element instanceof PsiBreakStatement) {
- final PsiIdentifier identifier =
- ((PsiBreakStatement)element).getLabelIdentifier();
+ final PsiBreakStatement breakStatement = (PsiBreakStatement)element;
+ final PsiIdentifier identifier = breakStatement.getLabelIdentifier();
if (identifier == null) {
- switchStatementText.append("break ");
- switchStatementText.append(breakLabelString);
- switchStatementText.append(';');
+ switchStatementText.append("break ").append(breakLabelString).append(';');
}
else {
switchStatementText.append(text);
}
}
- else if (element instanceof PsiBlockStatement ||
- element instanceof PsiCodeBlock ||
- element instanceof PsiIfStatement) {
+ else if (element instanceof PsiBlockStatement || element instanceof PsiCodeBlock || element instanceof PsiIfStatement) {
final PsiElement[] children = element.getChildren();
for (final PsiElement child : children) {
- appendElement(switchStatementText, child,
- renameBreakElements, breakLabelString);
+ appendElement(child, renameBreakElements, breakLabelString, switchStatementText);
}
}
else {
switchStatementText.append(text);
}
+ final PsiElement lastChild = element.getLastChild();
+ if (isEndOfLineComment(lastChild)) {
+ switchStatementText.append('\n');
+ }
+ }
+
+ private static boolean isEndOfLineComment(PsiElement element) {
+ if (!(element instanceof PsiComment)) {
+ return false;
+ }
+ final PsiComment comment = (PsiComment)element;
+ final IElementType tokenType = comment.getTokenType();
+ return JavaTokenType.END_OF_LINE_COMMENT.equals(tokenType);
}
}
@@ -562,11 +498,18 @@ public class IfCanBeSwitchInspection extends BaseInspection {
if (parent instanceof PsiIfStatement) {
return;
}
- final PsiExpression switchExpression =
- SwitchUtils.getSwitchExpression(statement, minimumBranches);
+ final PsiExpression switchExpression = SwitchUtils.getSwitchExpression(statement, minimumBranches);
if (switchExpression == null) {
return;
}
+ final PsiExpression unwrappedExpression = ParenthesesUtils.stripParentheses(switchExpression);
+ if (unwrappedExpression instanceof PsiReferenceExpression) {
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)unwrappedExpression;
+ final PsiElement target = referenceExpression.resolve();
+ if (target instanceof PsiModifierListOwner && NullableNotNullManager.isNullable((PsiModifierListOwner)target)) {
+ return;
+ }
+ }
final PsiType type = switchExpression.getType();
if (!suggestIntSwitches) {
if (type instanceof PsiClassType) {
@@ -577,10 +520,7 @@ public class IfCanBeSwitchInspection extends BaseInspection {
return;
}
}
- else if (PsiType.INT.equals(type) ||
- PsiType.SHORT.equals(type) ||
- PsiType.BYTE.equals(type) ||
- PsiType.CHAR.equals(type)) {
+ else if (PsiType.INT.equals(type) || PsiType.SHORT.equals(type) || PsiType.BYTE.equals(type) || PsiType.CHAR.equals(type)) {
return;
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfStatementBranch.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfStatementBranch.java
index 6d5513ac4d3f..2efb2a90f817 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfStatementBranch.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/IfStatementBranch.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ class IfStatementBranch {
private final Set<String> topLevelVariables = new HashSet<String>(3);
private final LinkedList<String> comments = new LinkedList<String>();
private final LinkedList<String> statementComments = new LinkedList<String>();
- private final List<PsiExpression> conditions = new ArrayList<PsiExpression>(3);
+ private final List<PsiExpression> caseExpressions = new ArrayList<PsiExpression>(3);
private final PsiStatement statement;
private final boolean elseBranch;
@@ -43,29 +43,27 @@ class IfStatementBranch {
}
public void addCaseExpression(PsiExpression expression) {
- conditions.add(expression);
+ caseExpressions.add(expression);
}
public PsiStatement getStatement() {
return statement;
}
- public List<PsiExpression> getConditions() {
- return Collections.unmodifiableList(conditions);
+ public List<PsiExpression> getCaseExpressions() {
+ return Collections.unmodifiableList(caseExpressions);
}
public boolean isElse() {
return elseBranch;
}
- public boolean topLevelDeclarationsConflictWith(
- IfStatementBranch testBranch) {
+ public boolean topLevelDeclarationsConflictWith(IfStatementBranch testBranch) {
final Set<String> topLevel = testBranch.topLevelVariables;
return intersects(topLevelVariables, topLevel);
}
- private static boolean intersects(Set<String> set1,
- Set<String> set2) {
+ private static boolean intersects(Set<String> set1, Set<String> set2) {
for (final String s : set1) {
if (set2.contains(s)) {
return true;
@@ -87,10 +85,8 @@ class IfStatementBranch {
return;
}
if (statement instanceof PsiDeclarationStatement) {
- final PsiDeclarationStatement declarationStatement =
- (PsiDeclarationStatement)statement;
- final PsiElement[] elements =
- declarationStatement.getDeclaredElements();
+ final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)statement;
+ final PsiElement[] elements = declarationStatement.getDeclaredElements();
for (PsiElement element : elements) {
final PsiVariable variable = (PsiVariable)element;
final String varName = variable.getName();
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
index 1c171d52fc5d..f4ea3c7365a2 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Bas Leijdekkers
+ * Copyright 2011-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
package com.siyeh.ig.migration;
import com.intellij.codeInspection.ProblemDescriptor;
-import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
+import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
+import com.intellij.psi.search.searches.SuperMethodsSearch;
import com.intellij.psi.util.PsiUtil;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -36,26 +36,30 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
@SuppressWarnings({"PublicField"})
public boolean ignoreByteAndShortArrayParameters = false;
+ @SuppressWarnings("PublicField")
+ public boolean ignoreOverridingMethods = false;
+
@Nls
@NotNull
@Override
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "method.can.be.variable.arity.method.display.name");
+ return InspectionGadgetsBundle.message("method.can.be.variable.arity.method.display.name");
}
@NotNull
@Override
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "method.can.be.variable.arity.method.problem.descriptor");
+ return InspectionGadgetsBundle.message("method.can.be.variable.arity.method.problem.descriptor");
}
@Override
public JComponent createOptionsPanel() {
- return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
- "method.can.be.variable.arity.method.ignore.byte.short.option"),
- this, "ignoreByteAndShortArrayParameters");
+ final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(this);
+ panel.addCheckbox(InspectionGadgetsBundle.message("method.can.be.variable.arity.method.ignore.byte.short.option"),
+ "ignoreByteAndShortArrayParameters");
+ panel.addCheckbox(InspectionGadgetsBundle.message("method.can.be.variable.arity.method.ignore.overriding.methods"),
+ "ignoreOverridingMethods");
+ return panel;
}
@Override
@@ -63,19 +67,16 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
return new MethodCanBeVariableArityMethodFix();
}
- private static class MethodCanBeVariableArityMethodFix
- extends InspectionGadgetsFix {
+ private static class MethodCanBeVariableArityMethodFix extends InspectionGadgetsFix {
@NotNull
@Override
public String getName() {
- return InspectionGadgetsBundle.message(
- "convert.to.variable.arity.method.quickfix");
+ return InspectionGadgetsBundle.message("convert.to.variable.arity.method.quickfix");
}
@Override
- protected void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
if (!(parent instanceof PsiMethod)) {
@@ -87,19 +88,15 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
- final PsiParameter lastParameter =
- parameters[parameters.length - 1];
+ final PsiParameter lastParameter = parameters[parameters.length - 1];
final PsiType type = lastParameter.getType();
if (!(type instanceof PsiArrayType)) {
return;
}
final PsiArrayType arrayType = (PsiArrayType)type;
final PsiType componentType = arrayType.getComponentType();
- final PsiElementFactory factory =
- JavaPsiFacade.getElementFactory(project);
- final PsiTypeElement newTypeElement =
- factory.createTypeElementFromText(
- componentType.getCanonicalText() + "...", method);
+ final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
+ final PsiTypeElement newTypeElement = factory.createTypeElementFromText(componentType.getCanonicalText() + "...", method);
final PsiTypeElement typeElement = lastParameter.getTypeElement();
if (typeElement != null) {
typeElement.replace(newTypeElement);
@@ -112,8 +109,7 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
return new MethodCanBeVariableArityMethodVisitor();
}
- private class MethodCanBeVariableArityMethodVisitor
- extends BaseInspectionVisitor {
+ private class MethodCanBeVariableArityMethodVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(PsiMethod method) {
@@ -126,8 +122,7 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
return;
}
final PsiParameter[] parameters = parameterList.getParameters();
- final PsiParameter lastParameter =
- parameters[parameters.length - 1];
+ final PsiParameter lastParameter = parameters[parameters.length - 1];
final PsiType type = lastParameter.getType();
if (!(type instanceof PsiArrayType)) {
return;
@@ -142,14 +137,16 @@ public class MethodCanBeVariableArityMethodInspection extends BaseInspection {
return;
}
if (ignoreByteAndShortArrayParameters) {
- if (PsiType.BYTE.equals(componentType) ||
- PsiType.SHORT.equals(componentType)) {
+ if (PsiType.BYTE.equals(componentType) || PsiType.SHORT.equals(componentType)) {
return;
}
}
if (LibraryUtil.isOverrideOfLibraryMethod(method)) {
return;
}
+ if (ignoreOverridingMethods && SuperMethodsSearch.search(method, null, true, false).findFirst() != null) {
+ return;
+ }
registerMethodError(method);
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java
index c14c170ca84a..f4bddcd25294 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/TryFinallyCanBeTryWithResourcesInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -84,6 +84,10 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
if (tryBlock == null) {
return;
}
+ final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
+ if (finallyBlock == null) {
+ return;
+ }
final PsiElement[] tryBlockChildren = tryBlock.getChildren();
final Set<PsiLocalVariable> variables = new HashSet();
for (PsiLocalVariable variable : collectVariables(tryStatement)) {
@@ -145,8 +149,6 @@ public class TryFinallyCanBeTryWithResourcesInspection extends BaseInspection {
for (PsiCatchSection catchSection : catchSections) {
newTryStatementText.append(catchSection.getText());
}
- final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
- assert finallyBlock != null;
final PsiElement[] finallyChildren = finallyBlock.getChildren();
boolean appended = false;
final int finallyChildrenLength = finallyChildren.length - 1;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/WhileCanBeForeachInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/WhileCanBeForeachInspection.java
index 0d04a5cbf93a..a2907b363187 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/migration/WhileCanBeForeachInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/migration/WhileCanBeForeachInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,15 +50,13 @@ public class WhileCanBeForeachInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "while.can.be.foreach.display.name");
+ return InspectionGadgetsBundle.message("while.can.be.foreach.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "while.can.be.foreach.problem.descriptor");
+ return InspectionGadgetsBundle.message("while.can.be.foreach.problem.descriptor");
}
@Override
@@ -79,43 +77,33 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement whileElement = descriptor.getPsiElement();
- final PsiWhileStatement whileStatement =
- (PsiWhileStatement)whileElement.getParent();
+ final PsiWhileStatement whileStatement = (PsiWhileStatement)whileElement.getParent();
replaceWhileWithForEach(whileStatement);
}
- private static void replaceWhileWithForEach(
- @NotNull PsiWhileStatement whileStatement)
- throws IncorrectOperationException {
+ private static void replaceWhileWithForEach(@NotNull PsiWhileStatement whileStatement) {
final PsiStatement body = whileStatement.getBody();
if (body == null) {
return;
}
- final PsiStatement initialization =
- getPreviousStatement(whileStatement);
- final PsiDeclarationStatement declaration =
- (PsiDeclarationStatement)initialization;
+ final PsiStatement initialization = getPreviousStatement(whileStatement);
+ final PsiDeclarationStatement declaration = (PsiDeclarationStatement)initialization;
if (declaration == null) {
return;
}
- final PsiElement declaredElement =
- declaration.getDeclaredElements()[0];
+ final PsiElement declaredElement = declaration.getDeclaredElements()[0];
if (!(declaredElement instanceof PsiLocalVariable)) {
return;
}
final PsiLocalVariable iterator = (PsiLocalVariable)declaredElement;
- final PsiMethodCallExpression initializer =
- (PsiMethodCallExpression)iterator.getInitializer();
+ final PsiMethodCallExpression initializer = (PsiMethodCallExpression)iterator.getInitializer();
if (initializer == null) {
return;
}
- final PsiReferenceExpression methodExpression =
- initializer.getMethodExpression();
- final PsiExpression collection =
- methodExpression.getQualifierExpression();
+ final PsiReferenceExpression methodExpression = initializer.getMethodExpression();
+ final PsiExpression collection = methodExpression.getQualifierExpression();
if (collection == null) {
return;
}
@@ -125,85 +113,62 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
final Project project = whileStatement.getProject();
final PsiStatement firstStatement = getFirstStatement(body);
- final boolean isDeclaration =
- isIteratorNextDeclaration(firstStatement, iterator,
- contentType);
+ final boolean isDeclaration = isIteratorNextDeclaration(firstStatement, iterator, contentType);
final PsiStatement statementToSkip;
- @NonNls String contentVariableName;
+ @NonNls final String contentVariableName;
if (isDeclaration) {
- final PsiDeclarationStatement declarationStatement =
- (PsiDeclarationStatement)firstStatement;
+ final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)firstStatement;
if (declarationStatement == null) {
return;
}
- final PsiElement[] declaredElements =
- declarationStatement.getDeclaredElements();
- final PsiLocalVariable localVariable =
- (PsiLocalVariable)declaredElements[0];
+ final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
+ final PsiLocalVariable localVariable = (PsiLocalVariable)declaredElements[0];
contentVariableName = localVariable.getName();
statementToSkip = declarationStatement;
}
else {
if (collection instanceof PsiReferenceExpression) {
- final PsiJavaCodeReferenceElement referenceElement
- = (PsiJavaCodeReferenceElement)collection;
- final String collectionName =
- referenceElement.getReferenceName();
- contentVariableName = createNewVariableName(
- whileStatement, contentType, collectionName);
+ final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)collection;
+ final String collectionName = referenceElement.getReferenceName();
+ contentVariableName = createNewVariableName(whileStatement, contentType, collectionName);
}
else {
- contentVariableName =
- createNewVariableName(whileStatement, contentType,
- null);
+ contentVariableName = createNewVariableName(whileStatement, contentType, null);
}
statementToSkip = null;
}
- final CodeStyleSettings codeStyleSettings =
- CodeStyleSettingsManager.getSettings(project);
- @NonNls final String finalString =
- codeStyleSettings.GENERATE_FINAL_PARAMETERS ? "final " : "";
+ final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
@NonNls final StringBuilder out = new StringBuilder();
out.append("for(");
- out.append(finalString);
- out.append(contentType.getCanonicalText());
- out.append(' ');
- out.append(contentVariableName);
- out.append(": ");
- out.append(collection.getText());
- out.append(')');
- // add cast if type returned by collection is not assignable to
- // the iterator type.
- final PsiType iteratorContentType =
- getContentType(iterator.getType(), iterator);
- if (iteratorContentType != null &&
- !TypeConversionUtil.isAssignable(iteratorContentType,
- contentType)) {
- final String typeText = iteratorContentType.getCanonicalText();
- contentVariableName = '(' + typeText + ')' +
- contentVariableName;
- }
- replaceIteratorNext(body, contentVariableName,
- iterator, contentType, statementToSkip, out);
- final Query<PsiReference> query =
- ReferencesSearch.search(iterator, iterator.getUseScope());
+ if (codeStyleSettings.GENERATE_FINAL_PARAMETERS) {
+ out.append("final ");
+ }
+ final PsiType iteratorContentType = getContentType(iterator.getType(), iterator);
+ if (iteratorContentType == null) {
+ return;
+ }
+ out.append(iteratorContentType.getCanonicalText()).append(' ').append(contentVariableName).append(": ");
+ if (!TypeConversionUtil.isAssignable(iteratorContentType, contentType)) {
+ out.append("(java.lang.Iterable<").append(iteratorContentType.getCanonicalText()).append(">)");
+ }
+ out.append(collection.getText()).append(')');
+
+ replaceIteratorNext(body, contentVariableName, iterator, contentType, statementToSkip, out);
+ final Query<PsiReference> query = ReferencesSearch.search(iterator, iterator.getUseScope());
boolean deleteIterator = true;
for (PsiReference usage : query) {
final PsiElement element = usage.getElement();
if (PsiTreeUtil.isAncestor(whileStatement, element, true)) {
continue;
}
- final PsiAssignmentExpression assignment =
- PsiTreeUtil.getParentOfType(element,
- PsiAssignmentExpression.class);
+ final PsiAssignmentExpression assignment = PsiTreeUtil.getParentOfType(element, PsiAssignmentExpression.class);
if (assignment == null) {
// iterator is read after while loop,
// so cannot be deleted
deleteIterator = false;
break;
}
- final PsiExpression expression =
- assignment.getRExpression();
+ final PsiExpression expression = assignment.getRExpression();
initializer.delete();
iterator.setInitializer(expression);
final PsiElement statement = assignment.getParent();
@@ -231,8 +196,7 @@ public class WhileCanBeForeachInspection extends BaseInspection {
if (parameters.length == 1) {
final PsiType parameterType = parameters[0];
if (parameterType instanceof PsiCapturedWildcardType) {
- final PsiCapturedWildcardType wildcardType =
- (PsiCapturedWildcardType)parameterType;
+ final PsiCapturedWildcardType wildcardType = (PsiCapturedWildcardType)parameterType;
final PsiType bound = wildcardType.getUpperBound();
if (bound != null) {
return bound;
@@ -245,10 +209,8 @@ public class WhileCanBeForeachInspection extends BaseInspection {
return TypeUtils.getObjectType(context);
}
- private static void replaceIteratorNext(
- @NotNull PsiElement element, String contentVariableName,
- PsiVariable iterator, PsiType contentType,
- PsiElement childToSkip, StringBuilder out) {
+ private static void replaceIteratorNext(@NotNull PsiElement element, String contentVariableName, PsiVariable iterator,
+ PsiType contentType, PsiElement childToSkip, StringBuilder out) {
if (isIteratorNext(element, iterator, contentType)) {
out.append(contentVariableName);
}
@@ -266,43 +228,30 @@ public class WhileCanBeForeachInspection extends BaseInspection {
else if (child.equals(childToSkip)) {
skippingWhiteSpace = true;
}
- else if (child instanceof PsiWhiteSpace &&
- skippingWhiteSpace) {
- //don't do anything
- }
- else {
+ else if (!(child instanceof PsiWhiteSpace) || !skippingWhiteSpace) {
skippingWhiteSpace = false;
- replaceIteratorNext(child, contentVariableName,
- iterator, contentType, childToSkip, out);
+ replaceIteratorNext(child, contentVariableName, iterator, contentType, childToSkip, out);
}
}
}
}
}
- private static boolean shouldSkip(PsiVariable iterator,
- PsiType contentType,
- PsiElement child) {
+ private static boolean shouldSkip(PsiVariable iterator, PsiType contentType, PsiElement child) {
if (!(child instanceof PsiExpressionStatement)) {
return false;
}
- final PsiExpressionStatement expressionStatement =
- (PsiExpressionStatement)child;
- final PsiExpression expression =
- expressionStatement.getExpression();
+ final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)child;
+ final PsiExpression expression = expressionStatement.getExpression();
return isIteratorNext(expression, iterator, contentType);
}
- private static boolean isIteratorNextDeclaration(
- PsiStatement statement, PsiVariable iterator,
- PsiType contentType) {
+ private static boolean isIteratorNextDeclaration(PsiStatement statement, PsiVariable iterator, PsiType contentType) {
if (!(statement instanceof PsiDeclarationStatement)) {
return false;
}
- final PsiDeclarationStatement declarationStatement =
- (PsiDeclarationStatement)statement;
- final PsiElement[] elements =
- declarationStatement.getDeclaredElements();
+ final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)statement;
+ final PsiElement[] elements = declarationStatement.getDeclaredElements();
if (elements.length != 1) {
return false;
}
@@ -315,15 +264,12 @@ public class WhileCanBeForeachInspection extends BaseInspection {
return isIteratorNext(initializer, iterator, contentType);
}
- private static boolean isIteratorNext(PsiElement element,
- PsiVariable iterator,
- PsiType contentType) {
+ private static boolean isIteratorNext(PsiElement element, PsiVariable iterator, PsiType contentType) {
if (element == null) {
return false;
}
if (element instanceof PsiTypeCastExpression) {
- final PsiTypeCastExpression castExpression =
- (PsiTypeCastExpression)element;
+ final PsiTypeCastExpression castExpression = (PsiTypeCastExpression)element;
final PsiType type = castExpression.getType();
if (type == null) {
return false;
@@ -331,23 +277,19 @@ public class WhileCanBeForeachInspection extends BaseInspection {
if (!type.equals(contentType)) {
return false;
}
- final PsiExpression operand =
- castExpression.getOperand();
+ final PsiExpression operand = castExpression.getOperand();
return isIteratorNext(operand, iterator, contentType);
}
if (!(element instanceof PsiMethodCallExpression)) {
return false;
}
- final PsiMethodCallExpression callExpression =
- (PsiMethodCallExpression)element;
- final PsiExpressionList argumentList =
- callExpression.getArgumentList();
+ final PsiMethodCallExpression callExpression = (PsiMethodCallExpression)element;
+ final PsiExpressionList argumentList = callExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 0) {
return false;
}
- final PsiReferenceExpression reference =
- callExpression.getMethodExpression();
+ final PsiReferenceExpression reference = callExpression.getMethodExpression();
@NonNls final String referenceName = reference.getReferenceName();
if (!HardcodedMethodConstants.NEXT.equals(referenceName)) {
return false;
@@ -356,26 +298,20 @@ public class WhileCanBeForeachInspection extends BaseInspection {
if (!(expression instanceof PsiReferenceExpression)) {
return false;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)expression;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
final PsiElement target = referenceExpression.resolve();
return iterator.equals(target);
}
- private static String createNewVariableName(
- @NotNull PsiWhileStatement scope, PsiType type,
- String containerName) {
+ private static String createNewVariableName(@NotNull PsiWhileStatement scope, PsiType type, String containerName) {
final Project project = scope.getProject();
- final JavaCodeStyleManager codeStyleManager =
- JavaCodeStyleManager.getInstance(project);
+ final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
@NonNls String baseName;
if (containerName != null) {
baseName = StringUtils.createSingularFromName(containerName);
}
else {
- final SuggestedNameInfo suggestions =
- codeStyleManager.suggestVariableName(
- VariableKind.LOCAL_VARIABLE, null, null, type);
+ final SuggestedNameInfo suggestions = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, type);
final String[] names = suggestions.names;
if (names != null && names.length > 0) {
baseName = names[0];
@@ -387,13 +323,11 @@ public class WhileCanBeForeachInspection extends BaseInspection {
if (baseName == null || baseName.length() == 0) {
baseName = "value";
}
- return codeStyleManager.suggestUniqueVariableName(baseName, scope,
- true);
+ return codeStyleManager.suggestUniqueVariableName(baseName, scope, true);
}
@Nullable
- private static PsiStatement getFirstStatement(
- @NotNull PsiStatement body) {
+ private static PsiStatement getFirstStatement(@NotNull PsiStatement body) {
if (body instanceof PsiBlockStatement) {
final PsiBlockStatement block = (PsiBlockStatement)body;
final PsiCodeBlock codeBlock = block.getCodeBlock();
@@ -410,12 +344,10 @@ public class WhileCanBeForeachInspection extends BaseInspection {
return new WhileCanBeForeachVisitor();
}
- private static class WhileCanBeForeachVisitor
- extends BaseInspectionVisitor {
+ private static class WhileCanBeForeachVisitor extends BaseInspectionVisitor {
@Override
- public void visitWhileStatement(
- @NotNull PsiWhileStatement whileStatement) {
+ public void visitWhileStatement(@NotNull PsiWhileStatement whileStatement) {
super.visitWhileStatement(whileStatement);
if (!PsiUtil.isLanguageLevel5OrHigher(whileStatement)) {
return;
@@ -512,59 +444,47 @@ public class WhileCanBeForeachInspection extends BaseInspection {
return true;
}
- private static boolean isHasNextCalled(PsiVariable iterator,
- PsiExpression condition) {
+ private static boolean isHasNextCalled(PsiVariable iterator, PsiExpression condition) {
if (!(condition instanceof PsiMethodCallExpression)) {
return false;
}
- final PsiMethodCallExpression call =
- (PsiMethodCallExpression)condition;
+ final PsiMethodCallExpression call = (PsiMethodCallExpression)condition;
final PsiExpressionList argumentList = call.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 0) {
return false;
}
- final PsiReferenceExpression methodExpression =
- call.getMethodExpression();
- @NonNls final String methodName =
- methodExpression.getReferenceName();
+ final PsiReferenceExpression methodExpression = call.getMethodExpression();
+ @NonNls final String methodName = methodExpression.getReferenceName();
if (!HardcodedMethodConstants.HAS_NEXT.equals(methodName)) {
return false;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null) {
return true;
}
if (!(qualifier instanceof PsiReferenceExpression)) {
return false;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)qualifier;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier;
final PsiElement target = referenceExpression.resolve();
return iterator.equals(target);
}
- private static int calculateCallsToIteratorNext(PsiVariable iterator,
- PsiElement context) {
- final NumCallsToIteratorNextVisitor visitor =
- new NumCallsToIteratorNextVisitor(iterator);
+ private static int calculateCallsToIteratorNext(PsiVariable iterator, PsiElement context) {
+ final NumCallsToIteratorNextVisitor visitor = new NumCallsToIteratorNextVisitor(iterator);
context.accept(visitor);
return visitor.getNumCallsToIteratorNext();
}
- private static boolean isIteratorRemoveCalled(PsiVariable iterator,
- PsiElement context) {
- final IteratorMethodCallVisitor visitor =
- new IteratorMethodCallVisitor(iterator);
+ private static boolean isIteratorRemoveCalled(PsiVariable iterator, PsiElement context) {
+ final IteratorMethodCallVisitor visitor = new IteratorMethodCallVisitor(iterator);
context.accept(visitor);
return visitor.isMethodCalled();
}
- private static boolean isIteratorHasNextCalled(PsiVariable iterator,
- PsiElement context) {
- final IteratorHasNextVisitor visitor =
- new IteratorHasNextVisitor(iterator);
+ private static boolean isIteratorHasNextCalled(PsiVariable iterator, PsiElement context) {
+ final IteratorHasNextVisitor visitor = new IteratorHasNextVisitor(iterator);
context.accept(visitor);
return visitor.isHasNextCalled();
}
@@ -572,17 +492,14 @@ public class WhileCanBeForeachInspection extends BaseInspection {
@Nullable
public static PsiStatement getPreviousStatement(PsiElement context) {
- final PsiElement prevStatement =
- PsiTreeUtil.skipSiblingsBackward(context,
- PsiWhiteSpace.class, PsiComment.class);
+ final PsiElement prevStatement = PsiTreeUtil.skipSiblingsBackward(context, PsiWhiteSpace.class, PsiComment.class);
if (!(prevStatement instanceof PsiStatement)) {
return null;
}
return (PsiStatement)prevStatement;
}
- private static class NumCallsToIteratorNextVisitor
- extends JavaRecursiveElementVisitor {
+ private static class NumCallsToIteratorNextVisitor extends JavaRecursiveElementVisitor {
private int numCallsToIteratorNext = 0;
private final PsiVariable iterator;
@@ -592,23 +509,18 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression callExpression) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression callExpression) {
super.visitMethodCallExpression(callExpression);
- final PsiReferenceExpression methodExpression =
- callExpression.getMethodExpression();
- @NonNls final String methodName =
- methodExpression.getReferenceName();
+ final PsiReferenceExpression methodExpression = callExpression.getMethodExpression();
+ @NonNls final String methodName = methodExpression.getReferenceName();
if (!HardcodedMethodConstants.NEXT.equals(methodName)) {
return;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression)) {
return;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)qualifier;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier;
final PsiElement target = referenceExpression.resolve();
if (!iterator.equals(target)) {
return;
@@ -621,8 +533,7 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
}
- private static class IteratorMethodCallVisitor
- extends JavaRecursiveElementVisitor {
+ private static class IteratorMethodCallVisitor extends JavaRecursiveElementVisitor {
private boolean methodCalled = false;
private final PsiVariable iterator;
@@ -639,25 +550,21 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
if (methodCalled) {
return;
}
super.visitMethodCallExpression(expression);
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final String name = methodExpression.getReferenceName();
if (HardcodedMethodConstants.NEXT.equals(name)) {
return;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression)) {
return;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)qualifier;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier;
final PsiElement target = referenceExpression.resolve();
if (iterator.equals(target)) {
methodCalled = true;
@@ -669,8 +576,7 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
}
- private static class IteratorHasNextVisitor
- extends JavaRecursiveElementVisitor {
+ private static class IteratorHasNextVisitor extends JavaRecursiveElementVisitor {
private boolean hasNextCalled = false;
private final PsiVariable iterator;
@@ -687,22 +593,18 @@ public class WhileCanBeForeachInspection extends BaseInspection {
}
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
@NonNls final String name = methodExpression.getReferenceName();
if (!HardcodedMethodConstants.HAS_NEXT.equals(name)) {
return;
}
- final PsiExpression qualifier =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression)) {
return;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)qualifier;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifier;
final PsiElement target = referenceExpression.resolve();
if (iterator.equals(target)) {
hasNextCalled = true;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java
index b75a3030b72c..4745746b8474 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/DivideByZeroInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,51 +48,43 @@ public class DivideByZeroInspection extends BaseInspection {
private static class DivisionByZeroVisitor extends BaseInspectionVisitor {
@Override
- public void visitBinaryExpression(
- @NotNull PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
- final PsiExpression rhs = expression.getROperand();
- if (rhs == null) {
- return;
- }
+ public void visitPolyadicExpression(PsiPolyadicExpression expression) {
+ super.visitPolyadicExpression(expression);
final IElementType tokenType = expression.getOperationTokenType();
- if (!tokenType.equals(JavaTokenType.DIV) &&
- !tokenType.equals(JavaTokenType.PERC)) {
+ if (!JavaTokenType.DIV.equals(tokenType) && !JavaTokenType.PERC.equals(tokenType)) {
return;
}
- final Object value =
- ConstantExpressionUtil.computeCastTo(rhs, PsiType.DOUBLE);
- if (!(value instanceof Double)) {
- return;
- }
- final double constantValue = ((Double)value).doubleValue();
- if (constantValue == 0.0 || constantValue == -0.0) {
- registerError(expression);
+ final PsiExpression[] operands = expression.getOperands();
+ for (int i = 1; i < operands.length; i++) {
+ final PsiExpression operand = operands[i];
+ if (isZero(operand)) {
+ registerError(operand);
+ return;
+ }
}
}
@Override
- public void visitAssignmentExpression(
- PsiAssignmentExpression expression) {
+ public void visitAssignmentExpression(PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
final PsiExpression rhs = expression.getRExpression();
if (rhs == null) {
return;
}
final IElementType tokenType = expression.getOperationTokenType();
- if (!tokenType.equals(JavaTokenType.DIVEQ)
- && !tokenType.equals(JavaTokenType.PERCEQ)) {
+ if (!tokenType.equals(JavaTokenType.DIVEQ) && !tokenType.equals(JavaTokenType.PERCEQ) || isZero(rhs)) {
return;
}
- final Object value = ConstantExpressionUtil.computeCastTo(rhs,
- PsiType.DOUBLE);
+ registerError(expression);
+ }
+
+ private static boolean isZero(PsiExpression expression) {
+ final Object value = ConstantExpressionUtil.computeCastTo(expression, PsiType.DOUBLE);
if (!(value instanceof Double)) {
- return;
+ return false;
}
final double constantValue = ((Double)value).doubleValue();
- if (constantValue == 0.0 || constantValue == -0.0) {
- registerError(expression);
- }
+ return constantValue == 0.0 || constantValue == -0.0;
}
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java
index ef871d3fa632..c8271b32f46d 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,9 +19,8 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
-import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.tree.IElementType;
-import com.intellij.util.IncorrectOperationException;
+import com.intellij.psi.util.PsiUtil;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
@@ -30,21 +29,19 @@ import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.ClassUtils;
import com.siyeh.ig.psiutils.ExpectedTypeUtils;
import com.siyeh.ig.psiutils.ParenthesesUtils;
+import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
-import java.util.HashMap;
-import java.util.Map;
public class ImplicitNumericConversionInspection extends BaseInspection {
/**
* @noinspection StaticCollection
*/
- private static final Map<PsiType, Integer> typePrecisions =
- new HashMap<PsiType, Integer>(7);
+ private static final gnu.trove.TObjectIntHashMap<PsiType> typePrecisions = new TObjectIntHashMap<PsiType>(7);
static {
typePrecisions.put(PsiType.BYTE, 1);
@@ -68,22 +65,17 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.display.name");
+ return InspectionGadgetsBundle.message("implicit.numeric.conversion.display.name");
}
@Override
public JComponent createOptionsPanel() {
- final MultipleCheckboxOptionsPanel optionsPanel =
- new MultipleCheckboxOptionsPanel(this);
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.ignore.widening.conversion.option"),
+ final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("implicit.numeric.conversion.ignore.widening.conversion.option"),
"ignoreWideningConversions");
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.ignore.char.conversion.option"),
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("implicit.numeric.conversion.ignore.char.conversion.option"),
"ignoreCharConversions");
- optionsPanel.addCheckbox(InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.ignore.constant.conversion.option"),
+ optionsPanel.addCheckbox(InspectionGadgetsBundle.message("implicit.numeric.conversion.ignore.constant.conversion.option"),
"ignoreConstantConversions");
return optionsPanel;
}
@@ -93,8 +85,7 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
public String buildErrorString(Object... infos) {
final PsiType type = (PsiType)infos[1];
final PsiType expectedType = (PsiType)infos[2];
- return InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.problem.descriptor",
+ return InspectionGadgetsBundle.message("implicit.numeric.conversion.problem.descriptor",
type.getPresentableText(), expectedType.getPresentableText());
}
@@ -105,25 +96,19 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
@Override
public InspectionGadgetsFix buildFix(Object... infos) {
- return new ImplicitNumericConversionFix((PsiExpression)infos[0],
- (PsiType)infos[2]);
+ return new ImplicitNumericConversionFix((PsiExpression)infos[0], (PsiType)infos[2]);
}
- private static class ImplicitNumericConversionFix
- extends InspectionGadgetsFix {
+ private static class ImplicitNumericConversionFix extends InspectionGadgetsFix {
private final String m_name;
- ImplicitNumericConversionFix(PsiExpression expression,
- PsiType expectedType) {
+ ImplicitNumericConversionFix(PsiExpression expression, PsiType expectedType) {
if (isConvertible(expression, expectedType)) {
- m_name = InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.convert.quickfix",
- expectedType.getCanonicalText());
+ m_name = InspectionGadgetsBundle.message("implicit.numeric.conversion.convert.quickfix", expectedType.getCanonicalText());
}
else {
- m_name = InspectionGadgetsBundle.message(
- "implicit.numeric.conversion.make.explicit.quickfix");
+ m_name = InspectionGadgetsBundle.message("implicit.numeric.conversion.make.explicit.quickfix");
}
}
@@ -133,18 +118,14 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
- final PsiExpression expression = (
- PsiExpression)descriptor.getPsiElement();
- final PsiType expectedType =
- ExpectedTypeUtils.findExpectedType(expression, true);
+ public void doFix(Project project, ProblemDescriptor descriptor) {
+ final PsiExpression expression = (PsiExpression)descriptor.getPsiElement();
+ final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, true);
if (expectedType == null) {
return;
}
if (isConvertible(expression, expectedType)) {
- final String newExpression =
- convertExpression(expression, expectedType);
+ final String newExpression = convertExpression(expression, expectedType);
if (newExpression == null) {
return;
}
@@ -152,14 +133,11 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
}
else {
final String newExpression;
- if (ParenthesesUtils.getPrecedence(expression) <=
- ParenthesesUtils.TYPE_CAST_PRECEDENCE) {
- newExpression = '(' + expectedType.getCanonicalText() +
- ')' + expression.getText();
+ if (ParenthesesUtils.getPrecedence(expression) <= ParenthesesUtils.TYPE_CAST_PRECEDENCE) {
+ newExpression = '(' + expectedType.getCanonicalText() + ')' + expression.getText();
}
else {
- newExpression = '(' + expectedType.getCanonicalText() +
- ")(" + expression.getText() + ')';
+ newExpression = '(' + expectedType.getCanonicalText() + ")(" + expression.getText() + ')';
}
replaceExpression(expression, newExpression);
}
@@ -167,50 +145,41 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
@Nullable
@NonNls
- private static String convertExpression(
- PsiExpression expression, PsiType expectedType) {
+ private static String convertExpression(PsiExpression expression, PsiType expectedType) {
final PsiType expressionType = expression.getType();
if (expressionType == null) {
return null;
}
- if (expressionType.equals(PsiType.INT) &&
- expectedType.equals(PsiType.LONG)) {
+ if (expressionType.equals(PsiType.INT) && expectedType.equals(PsiType.LONG)) {
return expression.getText() + 'L';
}
- if (expressionType.equals(PsiType.INT) &&
- expectedType.equals(PsiType.FLOAT)) {
+ if (expressionType.equals(PsiType.INT) && expectedType.equals(PsiType.FLOAT)) {
return expression.getText() + ".0F";
}
- if (expressionType.equals(PsiType.INT) &&
- expectedType.equals(PsiType.DOUBLE)) {
+ if (expressionType.equals(PsiType.INT) && expectedType.equals(PsiType.DOUBLE)) {
return expression.getText() + ".0";
}
- if (expressionType.equals(PsiType.LONG) &&
- expectedType.equals(PsiType.FLOAT)) {
+ if (expressionType.equals(PsiType.LONG) && expectedType.equals(PsiType.FLOAT)) {
final String text = expression.getText();
final int length = text.length();
return text.substring(0, length - 1) + ".0F";
}
- if (expressionType.equals(PsiType.LONG) &&
- expectedType.equals(PsiType.DOUBLE)) {
+ if (expressionType.equals(PsiType.LONG) && expectedType.equals(PsiType.DOUBLE)) {
final String text = expression.getText();
final int length = text.length();
return text.substring(0, length - 1) + ".0";
}
- if (expressionType.equals(PsiType.DOUBLE) &&
- expectedType.equals(PsiType.FLOAT)) {
+ if (expressionType.equals(PsiType.DOUBLE) && expectedType.equals(PsiType.FLOAT)) {
final String text = expression.getText();
final int length = text.length();
- if (text.charAt(length - 1) == 'd' ||
- text.charAt(length - 1) == 'D') {
+ if (text.charAt(length - 1) == 'd' || text.charAt(length - 1) == 'D') {
return text.substring(0, length - 1) + 'F';
}
else {
return text + 'F';
}
}
- if (expressionType.equals(PsiType.FLOAT) &&
- expectedType.equals(PsiType.DOUBLE)) {
+ if (expressionType.equals(PsiType.FLOAT) && expectedType.equals(PsiType.DOUBLE)) {
final String text = expression.getText();
final int length = text.length();
return text.substring(0, length - 1);
@@ -218,10 +187,8 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
return null; //can't happen
}
- private static boolean isConvertible(PsiExpression expression,
- PsiType expectedType) {
- if (!(expression instanceof PsiLiteralExpression) &&
- !isNegatedLiteral(expression)) {
+ private static boolean isConvertible(PsiExpression expression, PsiType expectedType) {
+ if (!(expression instanceof PsiLiteralExpression) && !isNegatedLiteral(expression)) {
return false;
}
final PsiType expressionType = expression.getType();
@@ -237,16 +204,14 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
if (isIntegral(expressionType) && isFloatingPoint(expectedType)) {
return true;
}
- return isFloatingPoint(expressionType) &&
- isFloatingPoint(expectedType);
+ return isFloatingPoint(expressionType) && isFloatingPoint(expectedType);
}
private static boolean isNegatedLiteral(PsiExpression expression) {
if (!(expression instanceof PsiPrefixExpression)) {
return false;
}
- final PsiPrefixExpression prefixExpression =
- (PsiPrefixExpression)expression;
+ final PsiPrefixExpression prefixExpression = (PsiPrefixExpression)expression;
final IElementType tokenType = prefixExpression.getOperationTokenType();
if (!JavaTokenType.MINUS.equals(tokenType)) {
return false;
@@ -256,85 +221,72 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
}
private static boolean isIntegral(@Nullable PsiType expressionType) {
- return PsiType.INT.equals(expressionType) ||
- PsiType.LONG.equals(expressionType);
+ return PsiType.INT.equals(expressionType) || PsiType.LONG.equals(expressionType);
}
private static boolean isFloatingPoint(@Nullable PsiType expressionType) {
- return PsiType.FLOAT.equals(expressionType) ||
- PsiType.DOUBLE.equals(expressionType);
+ return PsiType.FLOAT.equals(expressionType) || PsiType.DOUBLE.equals(expressionType);
}
}
- private class ImplicitNumericConversionVisitor
- extends BaseInspectionVisitor {
+ private class ImplicitNumericConversionVisitor extends BaseInspectionVisitor {
@Override
- public void visitBinaryExpression(
- PsiBinaryExpression expression) {
- super.visitBinaryExpression(expression);
+ public void visitPolyadicExpression(PsiPolyadicExpression expression) {
+ super.visitPolyadicExpression(expression);
checkExpression(expression);
}
@Override
- public void visitConditionalExpression(
- PsiConditionalExpression expression) {
+ public void visitConditionalExpression(PsiConditionalExpression expression) {
super.visitConditionalExpression(expression);
checkExpression(expression);
}
@Override
- public void visitLiteralExpression(
- PsiLiteralExpression expression) {
+ public void visitLiteralExpression(PsiLiteralExpression expression) {
super.visitLiteralExpression(expression);
checkExpression(expression);
}
@Override
- public void visitPostfixExpression(
- PsiPostfixExpression expression) {
+ public void visitPostfixExpression(PsiPostfixExpression expression) {
super.visitPostfixExpression(expression);
checkExpression(expression);
}
@Override
- public void visitPrefixExpression(
- PsiPrefixExpression expression) {
+ public void visitPrefixExpression(PsiPrefixExpression expression) {
super.visitPrefixExpression(expression);
checkExpression(expression);
}
@Override
- public void visitReferenceExpression(
- PsiReferenceExpression expression) {
+ public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
checkExpression(expression);
}
@Override
- public void visitMethodCallExpression(
- PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
checkExpression(expression);
}
@Override
- public void visitTypeCastExpression(
- PsiTypeCastExpression expression) {
+ public void visitTypeCastExpression(PsiTypeCastExpression expression) {
super.visitTypeCastExpression(expression);
checkExpression(expression);
}
@Override
- public void visitAssignmentExpression(
- PsiAssignmentExpression expression) {
+ public void visitAssignmentExpression(PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
checkExpression(expression);
}
@Override
- public void visitParenthesizedExpression(
- PsiParenthesizedExpression expression) {
+ public void visitParenthesizedExpression(PsiParenthesizedExpression expression) {
super.visitParenthesizedExpression(expression);
checkExpression(expression);
}
@@ -347,42 +299,28 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
if (ignoreConstantConversions) {
PsiExpression rootExpression = expression;
while (rootExpression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)rootExpression;
+ final PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression)rootExpression;
rootExpression = parenthesizedExpression.getExpression();
}
- if (rootExpression instanceof PsiLiteralExpression) {
- return;
- }
- else if (PsiUtil.isConstantExpression(rootExpression)) {
+ if (rootExpression instanceof PsiLiteralExpression || PsiUtil.isConstantExpression(rootExpression)) {
return;
}
}
final PsiType expressionType = expression.getType();
- if (expressionType == null) {
+ if (expressionType == null || !ClassUtils.isPrimitiveNumericType(expressionType)) {
return;
}
- if (!ClassUtils.isPrimitiveNumericType(expressionType)) {
+ if (PsiType.CHAR.equals(expressionType) && (ignoreCharConversions || isArgumentOfStringIndexOf(parent))) {
return;
}
- if (PsiType.CHAR.equals(expressionType)) {
- if (ignoreCharConversions) {
- return;
- }
- if (isArgumentOfStringIndexOf(parent)) {
- return;
- }
- }
- final PsiType expectedType =
- ExpectedTypeUtils.findExpectedType(expression, true);
+ final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, true);
if (!ClassUtils.isPrimitiveNumericType(expectedType)) {
return;
}
if (expressionType.equals(expectedType)) {
return;
}
- if (ignoreWideningConversions && hasLowerPrecision(expressionType,
- expectedType)) {
+ if (ignoreWideningConversions && hasLowerPrecision(expressionType, expectedType)) {
return;
}
if (ignoreCharConversions && PsiType.CHAR.equals(expectedType)) {
@@ -399,13 +337,10 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
if (!(grandParent instanceof PsiMethodCallExpression)) {
return false;
}
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)grandParent;
- final PsiReferenceExpression methodExpression =
- methodCallExpression.getMethodExpression();
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
+ final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
final String methodName = methodExpression.getReferenceName();
- if (!HardcodedMethodConstants.INDEX_OF.equals(methodName) &&
- !HardcodedMethodConstants.LAST_INDEX_OF.equals(methodName)) {
+ if (!HardcodedMethodConstants.INDEX_OF.equals(methodName) && !HardcodedMethodConstants.LAST_INDEX_OF.equals(methodName)) {
return false;
}
final PsiMethod method = methodCallExpression.resolveMethod();
@@ -421,10 +356,9 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
}
}
- static boolean hasLowerPrecision(PsiType expressionType,
- PsiType expectedType) {
- final Integer operandPrecision = typePrecisions.get(expressionType);
- final Integer castPrecision = typePrecisions.get(expectedType);
+ static boolean hasLowerPrecision(PsiType expressionType, PsiType expectedType) {
+ final int operandPrecision = typePrecisions.get(expressionType);
+ final int castPrecision = typePrecisions.get(expectedType);
return operandPrecision <= castPrecision;
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
index 7760b9377942..8a71995910f1 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/numeric/UnnecessaryExplicitNumericCastInspection.java
@@ -180,10 +180,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
else if (parent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
final PsiType lhsType = assignmentExpression.getType();
- if (!castType.equals(lhsType)) {
- return true;
- }
- return !isLegalAssignmentConversion(operand, lhsType);
+ return !castType.equals(lhsType) || !isLegalAssignmentConversion(operand, lhsType);
}
else if (parent instanceof PsiVariable) {
final PsiVariable variable = (PsiVariable)parent;
@@ -235,12 +232,9 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
if (targetMethod != newMethodCall.resolveMethod()) {
return true;
}
- return false;
- }
- else {
- final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
- return !castType.equals(expectedType) || !isLegalWideningConversion(operand, castType);
}
+ final PsiType expectedType = ExpectedTypeUtils.findExpectedType(expression, false);
+ return !castType.equals(expectedType) || !isLegalWideningConversion(operand, castType);
}
static boolean isLegalWideningConversion(PsiExpression expression, PsiType requiredType) {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ControlFlowUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ControlFlowUtils.java
index bb76ee23d292..7fe4542d12fd 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ControlFlowUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ControlFlowUtils.java
@@ -16,6 +16,7 @@
package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
+import com.intellij.psi.impl.source.jsp.jspJava.JspClassLevelDeclarationStatement;
import com.intellij.psi.impl.source.jsp.jspJava.JspTemplateStatement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
@@ -93,7 +94,7 @@ public class ControlFlowUtils {
else if (statement instanceof PsiSwitchStatement) {
return switchStatementMayCompleteNormally((PsiSwitchStatement)statement);
}
- else if (statement instanceof JspTemplateStatement) {
+ else if (statement instanceof JspTemplateStatement || statement instanceof JspClassLevelDeclarationStatement) {
return true;
}
else {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java
index c79a60d198f7..15edeedc9246 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2012 Bas Leijdekkers
+ * Copyright 2005-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -155,6 +155,19 @@ public class ExpressionUtils {
}
@Nullable
+ public static String getLiteralString(@Nullable PsiExpression expression) {
+ final PsiLiteralExpression literal = getLiteral(expression);
+ if (literal == null) {
+ return null;
+ }
+ final Object value = literal.getValue();
+ if (value == null) {
+ return null;
+ }
+ return value.toString();
+ }
+
+ @Nullable
public static PsiLiteralExpression getLiteral(@Nullable PsiExpression expression) {
expression = ParenthesesUtils.stripParentheses(expression);
if (expression instanceof PsiLiteralExpression) {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FormatUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FormatUtils.java
index 2265a74437e0..68e431e5652f 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FormatUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/FormatUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012 Bas Leijdekkers
+ * Copyright 2010-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.siyeh.ig.psiutils;
import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -46,10 +47,8 @@ public class FormatUtils {
private FormatUtils() {}
- public static boolean isFormatCall(
- PsiMethodCallExpression expression) {
- final PsiReferenceExpression methodExpression =
- expression.getMethodExpression();
+ public static boolean isFormatCall(PsiMethodCallExpression expression) {
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
final String name = methodExpression.getReferenceName();
if (!formatMethodNames.contains(name)) {
return false;
@@ -66,6 +65,16 @@ public class FormatUtils {
return formatClassNames.contains(className);
}
+ public static boolean isFormatCallArgument(PsiElement element) {
+ final PsiExpressionList expressionList =
+ PsiTreeUtil.getParentOfType(element, PsiExpressionList.class, true, PsiCodeBlock.class, PsiStatement.class, PsiClass.class);
+ if (expressionList == null) {
+ return false;
+ }
+ final PsiElement parent = expressionList.getParent();
+ return parent instanceof PsiMethodCallExpression && isFormatCall((PsiMethodCallExpression)parent);
+ }
+
@Nullable
public static PsiExpression getFormatArgument(PsiExpressionList argumentList) {
final PsiExpression[] arguments = argumentList.getExpressions();
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java
index 74535a305bb8..8523c161d0fa 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ParenthesesUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -259,12 +259,15 @@ public class ParenthesesUtils {
return;
}
else if (parent instanceof PsiArrayAccessExpression) {
- // use addAfter() + delete() instead of replace() to
- // workaround automatic insertion of parentheses by psi
- final PsiExpression newExpression = (PsiExpression)parent.addAfter(body, parenthesizedExpression);
- parenthesizedExpression.delete();
- removeParentheses(newExpression, ignoreClarifyingParentheses);
- return;
+ final PsiArrayAccessExpression arrayAccessExpression = (PsiArrayAccessExpression)parent;
+ if (parenthesizedExpression == arrayAccessExpression.getIndexExpression()) {
+ // use addAfter() + delete() instead of replace() to
+ // workaround automatic insertion of parentheses by psi
+ final PsiExpression newExpression = (PsiExpression)parent.addAfter(body, parenthesizedExpression);
+ parenthesizedExpression.delete();
+ removeParentheses(newExpression, ignoreClarifyingParentheses);
+ return;
+ }
}
final PsiExpression parentExpression = (PsiExpression)parent;
final int parentPrecedence = getPrecedence(parentExpression);
@@ -441,18 +444,36 @@ public class ParenthesesUtils {
if (child == null) {
return true;
}
+ if (parent instanceof PsiArrayAccessExpression) {
+ final PsiArrayAccessExpression arrayAccessExpression = (PsiArrayAccessExpression)parent;
+ final PsiExpression indexExpression = arrayAccessExpression.getIndexExpression();
+ if (expression == indexExpression) {
+ return false;
+ }
+ }
return areParenthesesNeeded(child, (PsiExpression)parent, ignoreClarifyingParentheses);
}
- public static boolean areParenthesesNeeded(PsiExpression expression, PsiExpression parentExpression,
- boolean ignoreClarifyingParentheses) {
- if (parentExpression instanceof PsiParenthesizedExpression || parentExpression instanceof PsiArrayAccessExpression ||
- parentExpression instanceof PsiArrayInitializerExpression) {
+ private static boolean areParenthesesNeeded(PsiExpression expression, PsiExpression parentExpression,
+ boolean ignoreClarifyingParentheses) {
+ if (parentExpression instanceof PsiParenthesizedExpression || parentExpression instanceof PsiArrayInitializerExpression) {
return false;
}
final int parentPrecedence = getPrecedence(parentExpression);
final int childPrecedence = getPrecedence(expression);
if (parentPrecedence > childPrecedence) {
+ if (ignoreClarifyingParentheses) {
+ if (expression instanceof PsiPolyadicExpression) {
+ if (parentExpression instanceof PsiPolyadicExpression ||
+ parentExpression instanceof PsiConditionalExpression ||
+ parentExpression instanceof PsiInstanceOfExpression) {
+ return true;
+ }
+ }
+ else if (expression instanceof PsiInstanceOfExpression) {
+ return true;
+ }
+ }
return false;
}
if (parentExpression instanceof PsiPolyadicExpression && expression instanceof PsiPolyadicExpression) {
@@ -484,9 +505,11 @@ public class ParenthesesUtils {
}
}
final IElementType parentOperator = parentPolyadicExpression.getOperationTokenType();
- final IElementType childOperator = childPolyadicExpression.getOperationTokenType();
- if (ignoreClarifyingParentheses && !childOperator.equals(parentOperator)) {
- return true;
+ if (ignoreClarifyingParentheses) {
+ final IElementType childOperator = childPolyadicExpression.getOperationTokenType();
+ if (!childOperator.equals(parentOperator)) {
+ return true;
+ }
}
final PsiExpression[] parentOperands = parentPolyadicExpression.getOperands();
if (!PsiTreeUtil.isAncestor(parentOperands[0], expression, false)) {
@@ -494,8 +517,7 @@ public class ParenthesesUtils {
return true;
}
}
- return false;
}
- return parentPrecedence != childPrecedence;
+ return parentPrecedence < childPrecedence;
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java
index 43a243ef9c03..653038346c10 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/SwitchUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.siyeh.ig.psiutils;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -25,11 +26,9 @@ import org.jetbrains.annotations.Nullable;
public class SwitchUtils {
- private SwitchUtils() {
- }
+ private SwitchUtils() {}
- public static int calculateBranchCount(
- @NotNull PsiSwitchStatement statement) {
+ public static int calculateBranchCount(@NotNull PsiSwitchStatement statement) {
final PsiCodeBlock body = statement.getBody();
int branches = 0;
if (body == null) {
@@ -45,25 +44,17 @@ public class SwitchUtils {
}
@Nullable
- public static PsiExpression getSwitchExpression(PsiIfStatement statement,
- int minimumBranches) {
+ public static PsiExpression getSwitchExpression(PsiIfStatement statement, int minimumBranches) {
final PsiExpression condition = statement.getCondition();
- final LanguageLevel languageLevel =
- PsiUtil.getLanguageLevel(statement);
- final PsiExpression possibleSwitchExpression =
- determinePossibleSwitchExpressions(condition, languageLevel);
- if (possibleSwitchExpression == null) {
- return null;
- }
- if (SideEffectChecker.mayHaveSideEffects(possibleSwitchExpression)) {
+ final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(statement);
+ final PsiExpression possibleSwitchExpression = determinePossibleSwitchExpressions(condition, languageLevel);
+ if (!canBeSwitchExpression(possibleSwitchExpression, languageLevel)) {
return null;
}
int branchCount = 0;
while (true) {
branchCount++;
- final PsiExpression caseCondition = statement.getCondition();
- if (!canBeMadeIntoCase(caseCondition, possibleSwitchExpression,
- languageLevel)) {
+ if (!canBeMadeIntoCase(statement.getCondition(), possibleSwitchExpression, languageLevel)) {
break;
}
final PsiStatement elseBranch = statement.getElseBranch();
@@ -81,103 +72,48 @@ public class SwitchUtils {
return null;
}
- private static boolean canBeMadeIntoCase(
- PsiExpression expression, PsiExpression switchExpression,
- LanguageLevel languageLevel) {
- while (expression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)expression;
- expression = parenthesizedExpression.getExpression();
- }
+ private static boolean canBeMadeIntoCase(PsiExpression expression, PsiExpression switchExpression, LanguageLevel languageLevel) {
+ expression = ParenthesesUtils.stripParentheses(expression);
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) {
- final PsiExpression stringCaseExpression =
- determinePossibleStringSwitchExpression(expression);
- if (EquivalenceChecker.expressionsAreEquivalent(switchExpression,
- stringCaseExpression)) {
+ final PsiExpression stringSwitchExpression = determinePossibleStringSwitchExpression(expression);
+ if (EquivalenceChecker.expressionsAreEquivalent(switchExpression, stringSwitchExpression)) {
return true;
}
}
- if (!(expression instanceof PsiBinaryExpression)) {
+ if (!(expression instanceof PsiPolyadicExpression)) {
return false;
}
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final IElementType operation = binaryExpression.getOperationTokenType();
- final PsiExpression lhs = binaryExpression.getLOperand();
- final PsiExpression rhs = binaryExpression.getROperand();
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ final IElementType operation = polyadicExpression.getOperationTokenType();
+ final PsiExpression[] operands = polyadicExpression.getOperands();
if (operation.equals(JavaTokenType.OROR)) {
- return canBeMadeIntoCase(lhs, switchExpression, languageLevel) &&
- canBeMadeIntoCase(rhs, switchExpression, languageLevel);
- }
- else if (operation.equals(JavaTokenType.EQEQ)) {
- return (canBeCaseLabel(lhs, languageLevel) &&
- EquivalenceChecker.expressionsAreEquivalent(
- switchExpression, rhs))
- ||
- (canBeCaseLabel(rhs, languageLevel) &&
- EquivalenceChecker.expressionsAreEquivalent(
- switchExpression, lhs));
- }
- else {
- return false;
- }
- }
-
- private static PsiExpression determinePossibleSwitchExpressions(
- PsiExpression expression, LanguageLevel languageLevel) {
- while (expression instanceof PsiParenthesizedExpression) {
- final PsiParenthesizedExpression parenthesizedExpression =
- (PsiParenthesizedExpression)expression;
- expression = parenthesizedExpression.getExpression();
- }
- if (expression == null) {
- return null;
- }
- if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) {
- final PsiExpression jdk17Expression =
- determinePossibleStringSwitchExpression(expression);
- if (jdk17Expression != null) {
- return jdk17Expression;
+ for (PsiExpression operand : operands) {
+ if (!canBeMadeIntoCase(operand, switchExpression, languageLevel)) {
+ return false;
+ }
}
+ return true;
}
- if (!(expression instanceof PsiBinaryExpression)) {
- return null;
- }
- final PsiBinaryExpression binaryExpression =
- (PsiBinaryExpression)expression;
- final IElementType operation = binaryExpression.getOperationTokenType();
- final PsiExpression lhs = binaryExpression.getLOperand();
- final PsiExpression rhs = binaryExpression.getROperand();
- if (operation.equals(JavaTokenType.OROR)) {
- return determinePossibleSwitchExpressions(lhs, languageLevel);
+ else if (operation.equals(JavaTokenType.EQEQ) && operands.length == 2) {
+ return (canBeCaseLabel(operands[0], languageLevel) && EquivalenceChecker.expressionsAreEquivalent(switchExpression, operands[1])) ||
+ (canBeCaseLabel(operands[1], languageLevel) && EquivalenceChecker.expressionsAreEquivalent(switchExpression, operands[0]));
}
- else if (operation.equals(JavaTokenType.EQEQ)) {
- if (canBeCaseLabel(lhs, languageLevel) &&
- canBeSwitchExpression(rhs, languageLevel)) {
- return rhs;
- }
- else if (canBeCaseLabel(rhs, languageLevel) &&
- canBeSwitchExpression(lhs, languageLevel)) {
- return lhs;
- }
+ else {
+ return false;
}
- return null;
}
private static boolean canBeSwitchExpression(PsiExpression expression, LanguageLevel languageLevel) {
- if (expression == null) {
+ if (expression == null || SideEffectChecker.mayHaveSideEffects(expression)) {
return false;
}
final PsiType type = expression.getType();
- if (PsiType.CHAR.equals(type) || PsiType.BYTE.equals(type) ||
- PsiType.SHORT.equals(type) || PsiType.INT.equals(type)) {
+ if (PsiType.CHAR.equals(type) || PsiType.BYTE.equals(type) || PsiType.SHORT.equals(type) || PsiType.INT.equals(type)) {
return true;
}
else if (type instanceof PsiClassType) {
- if (type.equalsToText(CommonClassNames.JAVA_LANG_CHARACTER) ||
- type.equalsToText(CommonClassNames.JAVA_LANG_BYTE) ||
- type.equalsToText(CommonClassNames.JAVA_LANG_SHORT) ||
- type.equalsToText(CommonClassNames.JAVA_LANG_INTEGER)) {
+ if (type.equalsToText(CommonClassNames.JAVA_LANG_CHARACTER) || type.equalsToText(CommonClassNames.JAVA_LANG_BYTE) ||
+ type.equalsToText(CommonClassNames.JAVA_LANG_SHORT) || type.equalsToText(CommonClassNames.JAVA_LANG_INTEGER)) {
return true;
}
if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) {
@@ -187,30 +123,57 @@ public class SwitchUtils {
return true;
}
}
- if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7) &&
- type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
+ if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7) && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return true;
}
}
return false;
}
- private static PsiExpression determinePossibleStringSwitchExpression(
- PsiExpression expression) {
+ private static PsiExpression determinePossibleSwitchExpressions(PsiExpression expression, LanguageLevel languageLevel) {
+ expression = ParenthesesUtils.stripParentheses(expression);
+ if (expression == null) {
+ return null;
+ }
+ if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) {
+ final PsiExpression jdk17Expression = determinePossibleStringSwitchExpression(expression);
+ if (jdk17Expression != null) {
+ return jdk17Expression;
+ }
+ }
+ if (!(expression instanceof PsiPolyadicExpression)) {
+ return null;
+ }
+ final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
+ final IElementType operation = polyadicExpression.getOperationTokenType();
+ final PsiExpression[] operands = polyadicExpression.getOperands();
+ if (operation.equals(JavaTokenType.OROR) && operands.length > 0) {
+ return determinePossibleSwitchExpressions(operands[0], languageLevel);
+ }
+ else if (operation.equals(JavaTokenType.EQEQ) && operands.length == 2) {
+ final PsiExpression lhs = operands[0];
+ final PsiExpression rhs = operands[1];
+ if (canBeCaseLabel(lhs, languageLevel)) {
+ return rhs;
+ }
+ else if (canBeCaseLabel(rhs, languageLevel)) {
+ return lhs;
+ }
+ }
+ return null;
+ }
+
+ private static PsiExpression determinePossibleStringSwitchExpression(PsiExpression expression) {
if (!(expression instanceof PsiMethodCallExpression)) {
return null;
}
- final PsiMethodCallExpression methodCallExpression =
- (PsiMethodCallExpression)expression;
- final PsiReferenceExpression methodExpression =
- methodCallExpression.getMethodExpression();
- @NonNls final String referenceName =
- methodExpression.getReferenceName();
+ final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
+ final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
+ @NonNls final String referenceName = methodExpression.getReferenceName();
if (!"equals".equals(referenceName)) {
return null;
}
- final PsiExpression qualifierExpression =
- methodExpression.getQualifierExpression();
+ final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (qualifierExpression == null) {
return null;
}
@@ -218,16 +181,14 @@ public class SwitchUtils {
if (type == null || !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return null;
}
- final PsiExpressionList argumentList =
- methodCallExpression.getArgumentList();
+ final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 1) {
return null;
}
final PsiExpression argument = arguments[0];
final PsiType argumentType = argument.getType();
- if (argumentType == null ||
- !argumentType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
+ if (argumentType == null || !argumentType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return null;
}
if (PsiUtil.isConstantExpression(qualifierExpression)) {
@@ -239,36 +200,23 @@ public class SwitchUtils {
return null;
}
- private static boolean canBeCaseLabel(PsiExpression expression,
- LanguageLevel languageLevel) {
+ private static boolean canBeCaseLabel(PsiExpression expression, LanguageLevel languageLevel) {
if (expression == null) {
return false;
}
- if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5) &&
- expression instanceof PsiReferenceExpression) {
+ if (languageLevel.isAtLeast(LanguageLevel.JDK_1_5) && expression instanceof PsiReferenceExpression) {
final PsiElement referent = ((PsiReference)expression).resolve();
if (referent instanceof PsiEnumConstant) {
return true;
}
}
final PsiType type = expression.getType();
- return type != null &&
- (PsiType.INT.equals(type) || PsiType.CHAR.equals(type) ||
- PsiType.SHORT.equals(type) || PsiType.BYTE.equals(type)) &&
+ return (PsiType.INT.equals(type) || PsiType.SHORT.equals(type) || PsiType.BYTE.equals(type) || PsiType.CHAR.equals(type)) &&
PsiUtil.isConstantExpression(expression);
}
- public static String findUniqueLabelName(PsiStatement statement,
- @NonNls String baseName) {
- PsiElement ancestor = statement;
- while (ancestor.getParent() != null) {
- if (ancestor instanceof PsiMethod
- || ancestor instanceof PsiClass
- || ancestor instanceof PsiFile) {
- break;
- }
- ancestor = ancestor.getParent();
- }
+ public static String findUniqueLabelName(PsiStatement statement, @NonNls String baseName) {
+ final PsiElement ancestor = PsiTreeUtil.getParentOfType(statement, PsiMember.class);
if (!checkForLabel(baseName, ancestor)) {
return baseName;
}
@@ -288,8 +236,7 @@ public class SwitchUtils {
return visitor.isUsed();
}
- private static class LabelSearchVisitor
- extends JavaRecursiveElementWalkingVisitor {
+ private static class LabelSearchVisitor extends JavaRecursiveElementWalkingVisitor {
private final String m_labelName;
private boolean m_used = false;
@@ -308,8 +255,7 @@ public class SwitchUtils {
@Override
public void visitLabeledStatement(PsiLabeledStatement statement) {
- final PsiIdentifier labelIdentifier =
- statement.getLabelIdentifier();
+ final PsiIdentifier labelIdentifier = statement.getLabelIdentifier();
final String labelText = labelIdentifier.getText();
if (labelText.equals(m_labelName)) {
m_used = true;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
index a4045e144b5a..0d83164dff0e 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008-2012 Bas Leijdekkers
+ * Copyright 2008-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,6 @@
*/
package com.siyeh.ig.psiutils;
-import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
@@ -36,8 +35,7 @@ import java.util.*;
public class WeakestTypeFinder {
- private WeakestTypeFinder() {
- }
+ private WeakestTypeFinder() {}
@NotNull
public static Collection<PsiClass> calculateWeakestClassesNecessary(@NotNull PsiElement variableOrMethod,
@@ -56,7 +54,7 @@ public class WeakestTypeFinder {
}
}
else {
- throw new IllegalArgumentException( "PsiMethod or PsiVariable expected: " + variableOrMethod);
+ throw new IllegalArgumentException("PsiMethod or PsiVariable expected: " + variableOrMethod);
}
if (!(variableOrMethodType instanceof PsiClassType)) {
return Collections.emptyList();
@@ -66,16 +64,32 @@ public class WeakestTypeFinder {
if (variableOrMethodClass == null) {
return Collections.emptyList();
}
- final PsiManager manager = variableOrMethod.getManager();
+ Set<PsiClass> weakestTypeClasses = new HashSet<PsiClass>();
final GlobalSearchScope scope = variableOrMethod.getResolveScope();
- final Project project = manager.getProject();
- final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
- final PsiClass javaLangObjectClass = facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, scope);
- if (javaLangObjectClass == null || variableOrMethodClass.equals(javaLangObjectClass)) {
- return Collections.emptyList();
+ final JavaPsiFacade facade = JavaPsiFacade.getInstance(variableOrMethod.getProject());
+ final PsiClass lowerBoundClass;
+ if (variableOrMethod instanceof PsiResourceVariable) {
+ lowerBoundClass = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, scope);
+ if (lowerBoundClass == null || variableOrMethodClass.equals(lowerBoundClass)) {
+ return Collections.emptyList();
+ }
+ weakestTypeClasses.add(lowerBoundClass);
+ final PsiResourceVariable resourceVariable = (PsiResourceVariable)variableOrMethod;
+ @NonNls final String methodCallText = resourceVariable.getName() + ".close()";
+ final PsiMethodCallExpression methodCallExpression =
+ (PsiMethodCallExpression)facade.getElementFactory().createExpressionFromText(methodCallText, resourceVariable.getParent());
+ if (!findWeakestType(methodCallExpression, weakestTypeClasses)) {
+ return Collections.emptyList();
+ }
}
- Set<PsiClass> weakestTypeClasses = new HashSet<PsiClass>();
- weakestTypeClasses.add(javaLangObjectClass);
+ else {
+ lowerBoundClass = facade.findClass(CommonClassNames.JAVA_LANG_OBJECT, scope);
+ if (lowerBoundClass == null || variableOrMethodClass.equals(lowerBoundClass)) {
+ return Collections.emptyList();
+ }
+ weakestTypeClasses.add(lowerBoundClass);
+ }
+
final Query<PsiReference> query = ReferencesSearch.search(variableOrMethod, variableOrMethod.getUseScope());
boolean hasUsages = false;
for (PsiReference reference : query) {
@@ -311,8 +325,7 @@ public class WeakestTypeFinder {
return checkType(type, substitutor, weakestTypeClasses);
}
- private static boolean checkType(@Nullable PsiType type,
- @NotNull PsiSubstitutor substitutor,
+ private static boolean checkType(@Nullable PsiType type, @NotNull PsiSubstitutor substitutor,
@NotNull Collection<PsiClass> weakestTypeClasses) {
if (!(type instanceof PsiClassType)) {
return false;
@@ -330,28 +343,19 @@ public class WeakestTypeFinder {
return true;
}
- private static boolean findWeakestType(PsiMethodCallExpression methodCallExpression,
- Set<PsiClass> weakestTypeClasses) {
+ private static boolean findWeakestType(PsiMethodCallExpression methodCallExpression, Set<PsiClass> weakestTypeClasses) {
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
final PsiElement target = methodExpression.resolve();
if (!(target instanceof PsiMethod)) {
return false;
}
- PsiClass autoClosable = null;
- final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
- if (qualifierExpression instanceof PsiReferenceExpression) {
- final PsiElement resolve = ((PsiReferenceExpression)qualifierExpression).resolve();
- if (resolve instanceof PsiResourceVariable) {
- autoClosable = JavaPsiFacade.getInstance(resolve.getProject()).findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, resolve.getResolveScope());
- }
- }
final PsiMethod method = (PsiMethod)target;
final PsiReferenceList throwsList = method.getThrowsList();
final PsiClassType[] classTypes = throwsList.getReferencedTypes();
final Collection<PsiClassType> thrownTypes = new HashSet<PsiClassType>(Arrays.asList(classTypes));
- final PsiMethod[] superMethods = method.findDeepestSuperMethods();
+ final List<PsiMethod> superMethods = findAllSuperMethods(method);
boolean checked = false;
- if (superMethods.length > 0) {
+ if (!superMethods.isEmpty()) {
final PsiType expectedType = ExpectedTypeUtils.findExpectedType(methodCallExpression, false);
for (PsiMethod superMethod : superMethods) {
final PsiType returnType = superMethod.getReturnType();
@@ -365,9 +369,6 @@ public class WeakestTypeFinder {
continue;
}
final PsiClass containingClass = superMethod.getContainingClass();
- if (autoClosable != null && !InheritanceUtil.isInheritorOrSelf(containingClass, autoClosable, true)) {
- continue;
- }
checkClass(containingClass, weakestTypeClasses);
checked = true;
}
@@ -382,18 +383,28 @@ public class WeakestTypeFinder {
}
}
final PsiClass containingClass = method.getContainingClass();
- if (autoClosable != null && !InheritanceUtil.isInheritorOrSelf(containingClass, autoClosable, true)) {
- return false;
- }
checkClass(containingClass, weakestTypeClasses);
}
return true;
}
- private static boolean findWeakestType(PsiElement referenceElement,
- PsiAssignmentExpression assignmentExpression,
- boolean useRighthandTypeAsWeakestTypeInAssignments,
- Set<PsiClass> weakestTypeClasses) {
+ private static List<PsiMethod> findAllSuperMethods(PsiMethod method) {
+ final List<PsiMethod> methods = findAllSuperMethods(method, new ArrayList());
+ Collections.reverse(methods);
+ return methods;
+ }
+
+ private static List<PsiMethod> findAllSuperMethods(PsiMethod method, List<PsiMethod> result) {
+ final PsiMethod[] superMethods = method.findSuperMethods();
+ Collections.addAll(result, superMethods);
+ for (PsiMethod superMethod : superMethods) {
+ findAllSuperMethods(superMethod, result);
+ }
+ return result;
+ }
+
+ private static boolean findWeakestType(PsiElement referenceElement, PsiAssignmentExpression assignmentExpression,
+ boolean useRighthandTypeAsWeakestTypeInAssignments, Set<PsiClass> weakestTypeClasses) {
final IElementType tokenType = assignmentExpression.getOperationTokenType();
if (JavaTokenType.EQ != tokenType) {
return false;
@@ -410,8 +421,7 @@ public class WeakestTypeFinder {
if (rhs == null) {
return false;
}
- if (!(rhs instanceof PsiNewExpression) ||
- !(rhs instanceof PsiTypeCastExpression)) {
+ if (!(rhs instanceof PsiNewExpression) || !(rhs instanceof PsiTypeCastExpression)) {
final PsiType rhsType = rhs.getType();
if (lhsType == null || lhsType.equals(rhsType)) {
return false;
@@ -431,13 +441,11 @@ public class WeakestTypeFinder {
return checkType(componentType, weakestTypeClasses);
}
- private static boolean findWeakestType(PsiThrowStatement throwStatement,
- PsiClass variableOrMethodClass,
+ private static boolean findWeakestType(PsiThrowStatement throwStatement, PsiClass variableOrMethodClass,
Set<PsiClass> weakestTypeClasses) {
final PsiClassType runtimeExceptionType = TypeUtils.getType(CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION, throwStatement);
final PsiClass runtimeExceptionClass = runtimeExceptionType.resolve();
- if (runtimeExceptionClass != null &&
- InheritanceUtil.isInheritorOrSelf(variableOrMethodClass, runtimeExceptionClass, true)) {
+ if (runtimeExceptionClass != null && InheritanceUtil.isInheritorOrSelf(variableOrMethodClass, runtimeExceptionClass, true)) {
if (!checkType(runtimeExceptionType, weakestTypeClasses)) {
return false;
}
@@ -472,9 +480,15 @@ public class WeakestTypeFinder {
private static boolean throwsIncompatibleException(PsiMethod method, Collection<PsiClassType> exceptionTypes) {
final PsiReferenceList superThrowsList = method.getThrowsList();
final PsiClassType[] superThrownTypes = superThrowsList.getReferencedTypes();
+ outer:
for (PsiClassType superThrownType : superThrownTypes) {
if (exceptionTypes.contains(superThrownType)) {
- return true;
+ continue;
+ }
+ for (PsiClassType exceptionType : exceptionTypes) {
+ if (InheritanceUtil.isInheritor(superThrownType, exceptionType.getCanonicalText())) {
+ continue outer;
+ }
}
final PsiClass aClass = superThrownType.resolve();
if (aClass == null) {
@@ -517,8 +531,7 @@ public class WeakestTypeFinder {
}
@Nullable
- private static PsiClass getVisibleInheritor(PsiClass superClass,
- PsiElement context) {
+ private static PsiClass getVisibleInheritor(PsiClass superClass, PsiElement context) {
final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope());
for (PsiClass aClass : search) {
if (superClass.isInheritor(aClass, true)) {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
index 67246337c22b..cfa66387b071 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryInterfaceModifierInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package com.siyeh.ig.style;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
-import com.intellij.util.IncorrectOperationException;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -33,26 +32,20 @@ import java.util.Set;
public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
private static final Set<String> INTERFACE_REDUNDANT_MODIFIERS =
- new HashSet<String>(Arrays.asList(PsiModifier.ABSTRACT,
- PsiModifier.STATIC));
+ new HashSet<String>(Arrays.asList(PsiModifier.ABSTRACT, PsiModifier.STATIC));
private static final Set<String> INNER_CLASS_REDUNDANT_MODIFIERS =
- new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC,
- PsiModifier.STATIC));
+ new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.STATIC));
private static final Set<String> INNER_INTERFACE_REDUNDANT_MODIFIERS =
- new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC,
- PsiModifier.ABSTRACT, PsiModifier.STATIC));
+ new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.ABSTRACT, PsiModifier.STATIC));
private static final Set<String> FIELD_REDUNDANT_MODIFIERS =
- new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC,
- PsiModifier.STATIC, PsiModifier.FINAL));
+ new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL));
private static final Set<String> METHOD_REDUNDANT_MODIFIERS =
- new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC,
- PsiModifier.ABSTRACT));
+ new HashSet<String>(Arrays.asList(PsiModifier.PUBLIC, PsiModifier.ABSTRACT));
@Override
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.display.name");
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.display.name");
}
@Override
@@ -65,32 +58,21 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
final PsiClass containingClass = aClass.getContainingClass();
if (containingClass != null) {
if (aClass.isInterface()) {
- if (containingClass.isInterface()) {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor");
- }
- else {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.inner.interface.of.class.problem.descriptor");
- }
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.inner.interface.of.interface.problem.descriptor");
}
else {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.problem.descriptor3");
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor3");
}
}
else {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.problem.descriptor");
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor");
}
}
else if (parent instanceof PsiMethod) {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.problem.descriptor2");
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor2");
}
else {
- return InspectionGadgetsBundle.message(
- "unnecessary.interface.modifier.problem.descriptor4");
+ return InspectionGadgetsBundle.message("unnecessary.interface.modifier.problem.descriptor4");
}
}
@@ -104,8 +86,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
return new UnnecessaryInterfaceModifiersFix((String)infos[0]);
}
- private static class UnnecessaryInterfaceModifiersFix
- extends InspectionGadgetsFix {
+ private static class UnnecessaryInterfaceModifiersFix extends InspectionGadgetsFix {
private final String modifiersText;
@@ -115,13 +96,11 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
@NotNull
public String getName() {
- return InspectionGadgetsBundle.message(
- "smth.unnecessary.remove.quickfix", modifiersText);
+ return InspectionGadgetsBundle.message("smth.unnecessary.remove.quickfix", modifiersText);
}
@Override
- public void doFix(Project project, ProblemDescriptor descriptor)
- throws IncorrectOperationException {
+ public void doFix(Project project, ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
final PsiModifierList modifierList;
if (element instanceof PsiModifierList) {
@@ -142,8 +121,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
if (aClass.isInterface()) {
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
}
- final PsiClass containingClass =
- ClassUtils.getContainingClass(modifierOwner);
+ final PsiClass containingClass = ClassUtils.getContainingClass(modifierOwner);
if (containingClass != null && containingClass.isInterface()) {
// do the inner classes
modifierList.setModifierProperty(PsiModifier.PUBLIC, false);
@@ -160,8 +138,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
}
}
- private static class UnnecessaryInterfaceModifierVisitor
- extends BaseInspectionVisitor {
+ private static class UnnecessaryInterfaceModifierVisitor extends BaseInspectionVisitor {
@Override
public void visitClass(@NotNull PsiClass aClass) {
@@ -169,18 +146,15 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
if (parent != null && parent.isInterface()) {
final PsiModifierList modifiers = aClass.getModifierList();
if (aClass.isInterface()) {
- checkForRedundantModifiers(modifiers,
- INNER_INTERFACE_REDUNDANT_MODIFIERS);
+ checkForRedundantModifiers(modifiers, INNER_INTERFACE_REDUNDANT_MODIFIERS);
}
else {
- checkForRedundantModifiers(modifiers,
- INNER_CLASS_REDUNDANT_MODIFIERS);
+ checkForRedundantModifiers(modifiers, INNER_CLASS_REDUNDANT_MODIFIERS);
}
}
else if (aClass.isInterface()) {
final PsiModifierList modifiers = aClass.getModifierList();
- checkForRedundantModifiers(modifiers,
- INTERFACE_REDUNDANT_MODIFIERS);
+ checkForRedundantModifiers(modifiers, INTERFACE_REDUNDANT_MODIFIERS);
}
}
@@ -212,8 +186,7 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
checkForRedundantModifiers(modifiers, METHOD_REDUNDANT_MODIFIERS);
}
- public void checkForRedundantModifiers(PsiModifierList list,
- Set<String> modifiers) {
+ public void checkForRedundantModifiers(PsiModifierList list, Set<String> modifiers) {
if (list == null) {
return;
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java
index 88f78160511b..42e901e7c434 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/UnnecessaryParenthesesInspection.java
@@ -108,48 +108,20 @@ public class UnnecessaryParenthesesInspection extends BaseInspection {
@Override
public void visitParenthesizedExpression(PsiParenthesizedExpression expression) {
final PsiElement parent = expression.getParent();
- final PsiExpression child = expression.getExpression();
- if (child == null) {
+ if (parent instanceof PsiParenthesizedExpression) {
return;
}
- if (!(parent instanceof PsiExpression) || parent instanceof PsiParenthesizedExpression
- || parent instanceof PsiArrayAccessExpression || parent instanceof PsiArrayInitializerExpression) {
- registerError(expression);
- return;
- }
- final int parentPrecedence = ParenthesesUtils.getPrecedence((PsiExpression)parent);
- final int childPrecedence = ParenthesesUtils.getPrecedence(child);
- if (parentPrecedence > childPrecedence) {
- if (ignoreClarifyingParentheses) {
- if (child instanceof PsiPolyadicExpression) {
- if (parent instanceof PsiPolyadicExpression ||
- parent instanceof PsiConditionalExpression ||
- parent instanceof PsiInstanceOfExpression) {
- return;
- }
- }
- else if (child instanceof PsiInstanceOfExpression) {
- return;
- }
- }
- if (ignoreParenthesesOnConditionals) {
- if (parent instanceof PsiConditionalExpression) {
- final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)parent;
- final PsiExpression condition = conditionalExpression.getCondition();
- if (expression == condition) {
- return;
- }
- }
+ if (ignoreParenthesesOnConditionals && parent instanceof PsiConditionalExpression) {
+ final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)parent;
+ final PsiExpression condition = conditionalExpression.getCondition();
+ if (expression == condition) {
+ return;
}
+ }
+ if (!ParenthesesUtils.areParenthesesNeeded(expression, ignoreClarifyingParentheses)) {
registerError(expression);
return;
}
- if (parentPrecedence == childPrecedence) {
- if (!ParenthesesUtils.areParenthesesNeeded(expression, ignoreClarifyingParentheses)) {
- registerError(expression);
- return;
- }
- }
super.visitParenthesizedExpression(expression);
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspection.java
index 527a239422f9..4d17db337536 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Bas Leijdekkers
+ * Copyright 2008-2012 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,7 @@ import com.siyeh.InspectionGadgetsBundle;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
-public class SynchronizationOnLocalVariableOrMethodParameterInspection
- extends BaseInspection {
+public class SynchronizationOnLocalVariableOrMethodParameterInspection extends BaseInspection {
@SuppressWarnings({"PublicField"})
public boolean reportLocalVariables = true;
@@ -34,8 +33,7 @@ public class SynchronizationOnLocalVariableOrMethodParameterInspection
@Nls
@NotNull
public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "synchronization.on.local.variable.or.method.parameter.display.name");
+ return InspectionGadgetsBundle.message("synchronization.on.local.variable.or.method.parameter.display.name");
}
public boolean isEnabledByDefault() {
@@ -46,12 +44,10 @@ public class SynchronizationOnLocalVariableOrMethodParameterInspection
protected String buildErrorString(Object... infos) {
final Boolean localVariable = (Boolean)infos[0];
if (localVariable.booleanValue()) {
- return InspectionGadgetsBundle.message(
- "synchronization.on.local.variable.problem.descriptor");
+ return InspectionGadgetsBundle.message("synchronization.on.local.variable.problem.descriptor");
}
else {
- return InspectionGadgetsBundle.message(
- "synchronization.on.method.parameter.problem.descriptor");
+ return InspectionGadgetsBundle.message("synchronization.on.method.parameter.problem.descriptor");
}
}
@@ -59,11 +55,9 @@ public class SynchronizationOnLocalVariableOrMethodParameterInspection
return new SynchronizationOnLocalVariableVisitor();
}
- private class SynchronizationOnLocalVariableVisitor
- extends BaseInspectionVisitor {
+ private class SynchronizationOnLocalVariableVisitor extends BaseInspectionVisitor {
- public void visitSynchronizedStatement(
- PsiSynchronizedStatement statement) {
+ public void visitSynchronizedStatement(PsiSynchronizedStatement statement) {
super.visitSynchronizedStatement(statement);
if (!reportLocalVariables && !reportMethodParameters) {
return;
@@ -72,8 +66,7 @@ public class SynchronizationOnLocalVariableOrMethodParameterInspection
if (!(lockExpression instanceof PsiReferenceExpression)) {
return;
}
- final PsiReferenceExpression referenceExpression =
- (PsiReferenceExpression)lockExpression;
+ final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)lockExpression;
if (referenceExpression.isQualified()) {
return;
}
@@ -103,13 +96,16 @@ public class SynchronizationOnLocalVariableOrMethodParameterInspection
else {
return;
}
- final PsiClass parentClass =
- PsiTreeUtil.getParentOfType(statement, PsiClass.class);
- if (!PsiTreeUtil.isAncestor(parentClass, target, true)) {
- // different class, probably different thread.
+ final PsiElement statementScope = getScope(statement);
+ final PsiElement targetScope = getScope(target);
+ if (statementScope != targetScope) {
return;
}
registerError(referenceExpression, Boolean.valueOf(localVariable));
}
+
+ private PsiElement getScope(PsiElement element) {
+ return PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiLambdaExpression.class, PsiClassInitializer.class);
+ }
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AnnotationNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AnnotationNamingConvention.html
index 5868ee95bce2..db2187b5aaa0 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/AnnotationNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AnnotationNamingConvention.html
@@ -4,7 +4,7 @@ Reports annotation classes whose names are either too short, too long, or do not
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for annotation names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for annotation names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassComplexity.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassComplexity.html
index ff78e208becc..ba9645bfc1ff 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassComplexity.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassComplexity.html
@@ -7,7 +7,7 @@ toward the total complexity. Anonymous classes with more than very low complexit
difficult to understand, and should probably be promoted to become named inner classes.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable complexity a class might have.
+Use the field below to specify the maximum complexity a class is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassMethodCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassMethodCount.html
index 6ba388da5fb1..562dcd0e56de 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassMethodCount.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AnonymousClassMethodCount.html
@@ -1,12 +1,11 @@
<html>
<body>
-Reports anonymous inner class with too many methods.
+Reports anonymous inner <b>class</b> with too many methods.
Anonymous classes with more than a very low number of methods may be
difficult to understand, and should probably be promoted to become named inner classes.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of methods
-an anonymous inner class might have.
+Use the field below to specify the maximum number of methods an anonymous inner <b>class</b> is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html
new file mode 100644
index 000000000000..5a4a842cbcd8
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/AssignmentToSuperclassField.html
@@ -0,0 +1,9 @@
+<html>
+<body>
+Reports any assignments to fields from a superclass from within a constructor. It is usually better to call a constructor of the
+superclass to initialize the fields.
+<!-- tooltip end -->
+<p>
+<small>New in 12.1, Powered by InspectionGadgets</small>
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassComplexity.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassComplexity.html
index 5545631e12d8..e57f1a74bfb3 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassComplexity.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassComplexity.html
@@ -1,12 +1,12 @@
<html>
<body>
-Reports class with too high of a total complexity. The
-total complexity of a class is the sum of the cyclomatic complexities of all the methods
-and initializers the class declares. Inherited methods and initializers are not counted
+Reports classes with too high of a total complexity. The
+total complexity of a <b>class</b> is the sum of the cyclomatic complexities of all the methods
+and initializers the <b>class</b> declares. Inherited methods and initializers are not counted
toward the total complexity.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable complexity a class might have.
+Use the field below to specify the maximum complexity a class is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassCoupling.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassCoupling.html
index 9a4dea6c0f21..0c5c3d5a1026 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassCoupling.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassCoupling.html
@@ -2,11 +2,10 @@
<body>
Reports classes which are highly coupled, i.e. that reference too many other classes.
Classes with too high a coupling can be very fragile, and should probably be broken up. References to system classes
-(those in the <b>java.</b>or <b>javax.</b> packages), are not
-counted for purposes of this inspection.
+(those in the <b>java.</b>or <b>javax.</b> packages), are not counted.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable coupling a class might have.
+Use the field below to specify the maximum coupling a class is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInheritanceDepth.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInheritanceDepth.html
index 01b74552b231..037a60410018 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInheritanceDepth.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInheritanceDepth.html
@@ -2,10 +2,10 @@
<body>
Reports class too deep in the inheritance hierarchy. Classes too deeply inherited
may be confusing, and are a good sign that refactoring may be necessary. This inspection counts all superclasses
-from a library as a single superclass (libraries are considered unmodifyable).
+from a library as a single superclass (libraries are considered unmodifiable).
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable inheritance depth a class might have.
+Use the field below to specify the maximum inheritance depth a class is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNamingConvention.html
index 106143e562bb..fb9919e329bd 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNamingConvention.html
@@ -4,7 +4,7 @@ Reports classes whose names are either too short, too long, or do not follow
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for class names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for class names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNestingDepth.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNestingDepth.html
index 5d19449ca9f3..bd8b314e0587 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNestingDepth.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassNestingDepth.html
@@ -4,7 +4,7 @@ Reports inner classes too deeply nested. Nesting inner classes inside
inner classes is almost certain to be confusing, and is a good sign that refactoring may be necessary.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable nesting depth a class might have.
+Use the field below to specify the maximum nesting depth a class is allowed have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassWithoutNoArgConstructor.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassWithoutNoArgConstructor.html
index a6c1e99852a7..3b1d5e0dbfae 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassWithoutNoArgConstructor.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassWithoutNoArgConstructor.html
@@ -5,7 +5,7 @@ Such constructors are necessary in some contexts if a class is to be created ref
<!-- tooltip end -->
<p>
Use the checkbox below to indicate that this inspection should ignore classes which
-contain no explicit constructors, and thus are provided a default no-argument constructor
+contain no explicit constructors. These classes are provided a default no-argument constructor
by the compiler.
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ConstantNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ConstantNamingConvention.html
index 99c3c6b6201a..9bc0bdb2368a 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ConstantNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ConstantNamingConvention.html
@@ -4,9 +4,10 @@ Reports any constants whose names are either too short, too long, or do not foll
the specified regular expression pattern. Constants are fields declared <b>static final</b>.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for constant names
-(Regular expressions are in standard <b>java.util.regex</b> format). Use the
-checkbox below to specify that only immutable static final fields should be checked by this inspection.
+Use the fields below to specify minimum length, maximum length and regular expression expected for constant names
+(Regular expressions are in standard <b>java.util.regex</b> format).
+<p>
+Use the checkbox below to specify that only immutable static final fields should be checked by this inspection.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ConstructorCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ConstructorCount.html
index f6e8bb81050e..f5175b6ee095 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ConstructorCount.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ConstructorCount.html
@@ -5,7 +5,7 @@ too many constructors are prone to initialization errors, and may often be bette
multiple subclasses.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of constructors a class might have.
+Use the field below to specify the maximum number of constructors a class is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/CyclomaticComplexity.html b/plugins/InspectionGadgets/src/inspectionDescriptions/CyclomaticComplexity.html
index 96acc30811f5..9b486425fa77 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/CyclomaticComplexity.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/CyclomaticComplexity.html
@@ -5,7 +5,7 @@ complexity is basically a measurement of the number of branching points in a met
a cyclomatic complexity may be confusing and difficult to test.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable cyclomatic complexity a method might have.
+Use the field below to specify the maximum cyclomatic complexity a method is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/DuplicateCondition.html b/plugins/InspectionGadgets/src/inspectionDescriptions/DuplicateCondition.html
index 242fdae23897..f6fa1cc1b5a3 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/DuplicateCondition.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/DuplicateCondition.html
@@ -5,6 +5,9 @@ Reports on any duplicate conditions among different branches of an
desired semantics, duplicate conditions usually represent programmer oversight.
<!-- tooltip end -->
<p>
+Use the checkbox below to let this inspection ignore conditions containing method calls. Some method calls may return a different value
+on an identical invocation.
+<p>
<small>Powered by InspectionGadgets</small>
</body>
</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumSwitchStatementWhichMissesCases.html b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumSwitchStatementWhichMissesCases.html
index 827ef4f29c54..feeb593c8a5d 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumSwitchStatementWhichMissesCases.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumSwitchStatementWhichMissesCases.html
@@ -4,8 +4,7 @@ Reports <b>switch</b> statements
over enumerated types which do not include all of the enumerated type's elements as cases.
<!-- tooltip end -->
<p>
-Use the check box below to let this inspection ignore <b>switch</b>
-statements which include a <b>default</b> branch.
+Use the checkbox below to ignore <b>switch</b> statements which have a <b>default</b> branch.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedClassNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedClassNamingConvention.html
index cd55dc8db061..9f2382f5dbe6 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedClassNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedClassNamingConvention.html
@@ -4,7 +4,7 @@ Reports enumerated classes whose names are either too short, too long, or do not
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for enumerated class names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for enumerated class names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedConstantNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedConstantNamingConvention.html
index de47a9ed2ec9..c67aa6c5e14b 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedConstantNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/EnumeratedConstantNamingConvention.html
@@ -4,7 +4,7 @@ Reports enumerated constants whose names are either too short, too long, or do n
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for enumerated constant names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for enumerated constant names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/FieldCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/FieldCount.html
index 1053fda73f13..a6cb3d42f151 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/FieldCount.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/FieldCount.html
@@ -5,9 +5,10 @@ a large number of fields are often trying to 'do too much', and may need to be
refactored into multiple smaller classes.
<!-- tooltip end -->
<p>
-Use the controls below to specify the maximum acceptable number of fields a class might have, and
-to indicate whether constant fields count toward this number. Per default this inspection only counts
-immutable <b>static final</b> objects as constant. Use the checkbox below to
+Use the field below to specify the maximum number of fields a class is allowed to have.
+<p>
+Use the first checkbox below to indicate whether constant fields count toward this number.
+<p>Per default this inspection only counts immutable <b>static final</b> objects as constant. Use the second checkbox below to
count any <b>static final</b> field as constant.
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ForCanBeForeach.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ForCanBeForeach.html
index 2e6283893e0b..111adc7da74b 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ForCanBeForeach.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ForCanBeForeach.html
@@ -1,7 +1,7 @@
<html>
<body>
Reports <b>for</b> loops which iterate
-over collections or arrays, and can be replaced with the "for each" iteration syntax, available
+over collections or arrays, and can be replaced with the <b>foreach</b> iteration syntax, available
in Java 5 and newer.
<!-- tooltip end -->
<p>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/IfStatementWithTooManyBranches.html b/plugins/InspectionGadgets/src/inspectionDescriptions/IfStatementWithTooManyBranches.html
index ba3b4cd5bf61..6ccaf0ffb7fb 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/IfStatementWithTooManyBranches.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/IfStatementWithTooManyBranches.html
@@ -5,7 +5,7 @@ Such statements may be confusing, and are often the sign of inadequate levels of
abstraction.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum number of branches expected.
+Use the field below to specify the maximum number of branches an <b>if</b> statement is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceMethodNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceMethodNamingConvention.html
index 6b5506a05232..2d43e9b5f64d 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceMethodNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceMethodNamingConvention.html
@@ -5,7 +5,7 @@ the specified regular expression pattern. Instance methods that override library
methods are ignored by this inspection.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for instance method names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for instance method names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceVariableNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceVariableNamingConvention.html
index 4f0efb6c957f..4a9c36f0490f 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceVariableNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/InstanceVariableNamingConvention.html
@@ -4,7 +4,7 @@ Reports instance variables whose names are either too short, too long, or do not
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for
+Use the fields below to specify minimum length, maximum length and regular expression expected for
instance variable names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/InterfaceNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/InterfaceNamingConvention.html
index bd8d7e5ba8b5..8183383249e2 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/InterfaceNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/InterfaceNamingConvention.html
@@ -4,7 +4,7 @@ Reports interfaces whose names are either too short, too long, or do not follow
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for interface names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for interface names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitAbstractTestClassNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitAbstractTestClassNamingConvention.html
index 6e9ed206f39e..8492d81e4a92 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitAbstractTestClassNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitAbstractTestClassNamingConvention.html
@@ -6,7 +6,7 @@ standard that abstract JUnit test classes follow a specific pattern, usually req
with "TestCase".
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for class names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for class names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitTestClassNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitTestClassNamingConvention.html
index 797ef090f0a5..431e0acf2563 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitTestClassNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/JUnitTestClassNamingConvention.html
@@ -6,7 +6,7 @@ standard that concrete JUnit test classes follow a specific pattern, usually req
with "Test".
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for class names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for class names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/LocalVariableNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/LocalVariableNamingConvention.html
index 449e387b2645..35fa839696c1 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/LocalVariableNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/LocalVariableNamingConvention.html
@@ -4,7 +4,7 @@ Reports local variables whose names are either too short, too long, or do not fo
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for local variables names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for local variables names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/LogStatementGuardedByLogCondition.html b/plugins/InspectionGadgets/src/inspectionDescriptions/LogStatementGuardedByLogCondition.html
index bc16a72efc06..dd4a0b561feb 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/LogStatementGuardedByLogCondition.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/LogStatementGuardedByLogCondition.html
@@ -1,17 +1,19 @@
<html>
<body>
-Reports log statements with non-constant arguments which are not
-surrounded by a guard condition.
-The evaluation of the arguments of a log statement can be expensive.
-Surrounding a log statement with a guard clause prevents that cost when the logging
-is disabled for the level used by the logging statement. This is especially for the
-least serious level (trace, debug, finest) of logging statements, because those are
+Reports logging calls with non-constant arguments which are not surrounded by a guard condition.
+The evaluation of the arguments of a logging call can be expensive.
+Surrounding a logging call with a guard clause prevents that cost, when the logging
+is disabled for the level used by the logging statement. This is especially useful for the
+least serious level (trace, debug, finest) of logging calls, because those are
most often disabled in a production environment.
<!-- tooltip end -->
<p>
-Use the text field below to specify the logger class name used. Use the table
-to specify the log methods this inspection should warn on, with the corresponding
-logging condition text.
+Use the text field below to specify the logger class name used.
+<p>
+Use the table to specify the logging methods this inspection should warn on, with the corresponding
+log condition text.
+<p>
+Use the checkbox below to let this inspection flag all unguarded log calls, not only those with non-constant arguments.
<p>
<small>New in 8, Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/LoggingConditionDisagreesWithLogStatement.html b/plugins/InspectionGadgets/src/inspectionDescriptions/LoggingConditionDisagreesWithLogStatement.html
index fa394dc4f1a3..ce67c059a7b7 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/LoggingConditionDisagreesWithLogStatement.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/LoggingConditionDisagreesWithLogStatement.html
@@ -1,7 +1,7 @@
<html>
<body>
Reports <em>is log enabled for</em> conditions of if statements which
-do not match the log level of the contained log statement.
+do not match the log level of the contained logging call.
<p>
For example:
<code><pre>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCanBeVariableArityMethod.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCanBeVariableArityMethod.html
index 62d61cd226cd..4445fa8fcb39 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCanBeVariableArityMethod.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCanBeVariableArityMethod.html
@@ -7,6 +7,10 @@ This inspection only reports if the project or module is configured to use a
language level of 5.0 or higher.
<!-- tooltip end -->
<p>
+Use the first checkbox below to not offer to convert byte[] or short[] parameters to vararg.
+<p>
+Use the second checkbox below to ignore methods overriding a method in a super class.
+<p>
<small>New in 10.5, Powered by InspectionGadgets</small>
</body>
</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCount.html
index 471915e3dc85..28724c52181d 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCount.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCount.html
@@ -5,11 +5,9 @@ a large number of methods are often trying to 'do too much', and may need to be
refactored into multiple smaller classes.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of methods
-a class might have.
+Use the field below to specify the maximum number of methods a class is allowed to have.
<p>
-Use the checkbox below to specify if simple getters and setters should be ignored
-in the method count.
+Use the checkbox below to specify that simple getters and setters should be ignored in the method count.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCoupling.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCoupling.html
index 121e7f960f29..4baba21ee9e1 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCoupling.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MethodCoupling.html
@@ -6,7 +6,7 @@ Methods with too high a coupling can be very fragile, and should probably be bro
counted for purposes of this inspection.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable coupling a method might have.
+Use the field below to specify the maximum coupling a method is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MultipleReturnPointsPerMethod.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MultipleReturnPointsPerMethod.html
index ab45f6242ca0..e7396f74045c 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/MultipleReturnPointsPerMethod.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MultipleReturnPointsPerMethod.html
@@ -1,12 +1,15 @@
<html>
<body>
-Reports methods with too many return points. Methods
-with too many return points may be confusing, and hard to refactor.
+Reports methods with too many <b>return</b> points. Methods with too many <b>return</b> points may be confusing,
+and hard to refactor. A <b>return</b> point is either a <b>return</b> statement or the falling through the bottom of a
+<b>void</b> method or constructor.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of return points a method might have.
-Use the check boxes below to specify if guard clause and/or return points inside
-<b>equals()</b> methods should be ignored.
+Use the field below to specify the maximum number of <b>return</b> points a method is allowed to have.
+<p>
+Use the first checkbox below to ignore guard clauses.
+<p>
+Use the second checkbox below to ignore <b>return</b> points inside <b>equals()</b> methods.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MultiplyOrDivideByPowerOfTwo.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MultiplyOrDivideByPowerOfTwo.html
index 89179a4fb58c..c2a8578868d8 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/MultiplyOrDivideByPowerOfTwo.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MultiplyOrDivideByPowerOfTwo.html
@@ -1,10 +1,10 @@
<html>
<body>
Reports multiplication of an integer value by a constant power of 2. These
-expressions may be replaced by right or left shift operations, to some possible performance improvement.
+expressions may be replaced by right or left shift operations, for a possible performance improvement.
<!-- tooltip end -->
<p>
-Use the check box below to enable the inspection for divisions by a power of two also. Note that replacing
+Use the checkbox below to enable the inspection for divisions by a power of two. Note that replacing
a power of two division by a shift does not work for negative numbers.
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedConditional.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedConditional.html
index 30cb00ed1326..ccd1b184ce12 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedConditional.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedConditional.html
@@ -4,8 +4,7 @@ Reports conditional expressions whose conditions are negated.
Flipping the order of the conditional expression branches will usually increase the clarity of such statements.
<!-- tooltip end -->
<p>
-Use the check box below to have comparisons of the form <b>!= null</b>
-ignored by this inspection
+Use the checkbox below to ignore comparisons of the form <b>!= null</b>.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedIfElse.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedIfElse.html
index 5029f07dcc69..63a12c216851 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedIfElse.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NegatedIfElse.html
@@ -6,8 +6,7 @@ Flipping the order of the <b>if</b> and <b>else</b>
branches will usually increase the clarity of such statements.
<!-- tooltip end -->
<p>
-Use the check box below to have comparisons of the form <b>!= null</b>
-ignored by this inspection
+Use the checkbox below to ignore comparisons of the form <b>!= null</b>.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NestingDepth.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NestingDepth.html
index fa5fd1b7e41c..f658efd3a684 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/NestingDepth.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NestingDepth.html
@@ -4,7 +4,7 @@ Reports methods whose bodies are too deeply nested. Methods with too much statem
nesting may be confusing, and are a good sign that refactoring may be necessary.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable nesting depth a method might have.
+Use the field below to specify the maximum nesting depth a method is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NonCommentSourceStatements.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NonCommentSourceStatements.html
index 5599d4592282..f1b6865cccd5 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/NonCommentSourceStatements.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/NonCommentSourceStatements.html
@@ -4,7 +4,7 @@ Reports methods that are too long. Methods that are too long
may be confusing, and are a good sign that refactoring is necessary.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of non-comment source statements a method might have.
+Use the field below to specify the maximum number of non-comment source statements a method is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexArithmeticExpression.html b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexArithmeticExpression.html
index b6d845c2f6a4..26c746a06c07 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexArithmeticExpression.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexArithmeticExpression.html
@@ -4,7 +4,7 @@ Reports arithmetic expressions with too many terms. Such
expressions may be confusing and bug-prone.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum number of terms allowed in an arithmetic expression.
+Use the field below to specify the maximum number of terms allowed in an arithmetic expression.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexBooleanExpression.html b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexBooleanExpression.html
index d92ae7b6e1ee..fc6f4a1314a0 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexBooleanExpression.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyComplexBooleanExpression.html
@@ -1,10 +1,11 @@
<html>
<body>
-Reports boolean expressions with too many terms. Such
-expressions may be confusing and bug-prone.
+Reports boolean expressions with too many terms. Such expressions may be confusing and bug-prone.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum number of terms allowed in a boolean expression.
+Use the field below to specify the maximum number of terms allowed in a boolean expression.
+<p>
+Use the checkbox below to ignore boolean expressions which use only a single boolean operator repeatedly.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PackageNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PackageNamingConvention.html
index 9eddb8328048..55fce2a987a0 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/PackageNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PackageNamingConvention.html
@@ -4,7 +4,7 @@ This global inspection reports packages whose names are either too short, too lo
the specified regular expression pattern. Since this inspection requires global code analysis, it is only available in batch inspection mode.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for method parameter names
+Use the fields below to specify minimum length, maximum length and regular expression expected for method parameter names
(Regular expressions are in standard <b>java.util.regex</b> format).
<p>
<small>New in 11, Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ParameterNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ParameterNamingConvention.html
index ddd783ced5c6..9557e336ad5c 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ParameterNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ParameterNamingConvention.html
@@ -4,7 +4,7 @@ Reports method parameters whose names are either too short, too long, or do not
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for method parameter names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for method parameter names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
index 226c8ea0b002..97c9c4001e52 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerConstructor.html
@@ -4,7 +4,7 @@ Reports constructors with too many parameters. Constructors
with too many parameters can be a good sign that refactoring is necessary.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of parameters a constructor might have.
+Use the field below to specify the maximum number of parameters a constructor is allowed to have.
<p>
Use the combobox below to specify if the inspection should ignore private, package local & private or protected, package local and
private constructors
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerMethod.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerMethod.html
index 67d3f8d3eb7b..6d6075e05e03 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerMethod.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ParametersPerMethod.html
@@ -5,7 +5,7 @@ can be a good sign that refactoring is necessary. Methods whose signatures are i
library classes are ignored by this inspection.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of parameters a method might have.
+Use the field below to specify the maximum number of parameters a method is allowed to have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html
new file mode 100644
index 000000000000..a89605bed897
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PlaceholderCountMatchesArgumentCount.html
@@ -0,0 +1,9 @@
+<html>
+<body>
+Reports SLF4J logging calls where the number of {}-placeholders in the string constant argument
+does not match the number of other arguments to the logging call.
+<!-- tooltip end -->
+<p>
+<small>New in 12.1, Powered by InspectionGadgets</small>
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/PointlessNullCheck.html b/plugins/InspectionGadgets/src/inspectionDescriptions/PointlessNullCheck.html
index e69e0d11d5b7..8d94468a2871 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/PointlessNullCheck.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/PointlessNullCheck.html
@@ -2,7 +2,7 @@
<body>
<p>Reports a <b>null</b> check followed by an <b>instanceof</b> check.
Since the <b>instanceof</b> operator always returns <b>false</b> for <b>null</b>,
-there is no need to also have a <b>null</b> check. </p>
+there is no need to have an additional <b>null</b> check. </p>
<p>Here is an example of a violation: </p>
<pre><code> if (x != null && x instanceof String) { ... }</code></pre>
<p>The quickfix changes this code to:</p>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAssignmentWithOperatorAssignment.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAssignmentWithOperatorAssignment.html
index 1e2f9dea8373..0404e0fb7cfa 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAssignmentWithOperatorAssignment.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAssignmentWithOperatorAssignment.html
@@ -4,7 +4,7 @@ Reports assignment operations which can be replaced by operator-assignment. Code
using operator assignment may be clearer, and theoretically more performant.
<!-- tooltip end -->
<p>
-Use the check box below to ignore the conditional operators <b>&amp;&amp;</b>
+Use the checkbox below to ignore the conditional operators <b>&amp;&amp;</b>
and <b>||</b>. Replacing conditional operators with operator
assignment modifies the semantics of the expression.
<p>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ResultOfObjectAllocationIgnored.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ResultOfObjectAllocationIgnored.html
index 077a8fb17157..a07bfe721c12 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ResultOfObjectAllocationIgnored.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ResultOfObjectAllocationIgnored.html
@@ -1,6 +1,6 @@
<html>
<body>
-Reports object allocation where the object allocated ignored.
+Reports object allocations where the object allocated is ignored, and not assigned to a variable or used in another way.
Such allocation expressions are legal Java, but are usually either inadvertent, or
evidence of a very odd object initialization strategy.
<!-- tooltip end -->
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StaticMethodNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StaticMethodNamingConvention.html
index 605ed476071b..be324e15ce8c 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/StaticMethodNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StaticMethodNamingConvention.html
@@ -1,10 +1,10 @@
<html>
<body>
-Reports static methods whose names are either too short, too long, or do not follow
+Reports <b>static</b> methods whose names are either too short, too long, or do not follow
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for static method names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for static method names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StaticVariableNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StaticVariableNamingConvention.html
index 27ef62898a9b..54040ee77476 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/StaticVariableNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StaticVariableNamingConvention.html
@@ -5,7 +5,7 @@ the specified regular expression pattern. Constants, i.e. variables of immutable
are not checked by this inspection
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for static variable names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for static variable names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenationMissingWhitespace.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenationMissingWhitespace.html
index bdc568a2f3c7..5d8ebdfbab46 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenationMissingWhitespace.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConcatenationMissingWhitespace.html
@@ -1,14 +1,14 @@
<html>
<body>
-Reports string concatenations where the left literal does not
-end with whitespace and the right literal does not start with whitespace. For example:
+Reports string concatenations where the left-hand side does not
+end with whitespace or a symbol and the right-hand side does not start with whitespace or a symbol. For example:
<pre><code>
String sql = "SELECT column" +
"FROM table";
</code></pre>
<!-- tooltip end -->
<p>
-Use the checkbox below to have this inspection only report when both the left and right side of the concatenation are string literals.
+Use the checkbox below to have this inspection only report when both the left and right side of the concatenation are literals.
<p>
<small>New in 12, Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConstructor.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConstructor.html
index 3851033ebf56..a8ea2df6e63c 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/StringConstructor.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StringConstructor.html
@@ -6,7 +6,7 @@ Constructing new <b>String</b> objects in this way
is rarely necessary, and may cause performance problems if done often enough.
<!-- tooltip end -->
<p>
-Use the check box below to ignore <b>String</b>
+Use the checkbox below to ignore <b>String</b>
constructor calls which have a <b>String.substring()</b>
call as parameter. A call to <b>substring()</b>
reuses the character array of the original string, which can cause a large
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/StringReplaceableByStringBuffer.html b/plugins/InspectionGadgets/src/inspectionDescriptions/StringReplaceableByStringBuffer.html
index 45e397e37d13..65299e00bf63 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/StringReplaceableByStringBuffer.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/StringReplaceableByStringBuffer.html
@@ -5,7 +5,7 @@ repeatedly appended to. Such variables may be more efficiently declared as <b>ja
or <b>java.lang.StringBuilder</b>.
<!-- tooltip end -->
<p>
-Use the check box below to specify that this inspection should only warn when the variable is appended
+Use the checkbox below to specify that this inspection should only warn when the variable is appended
to in a loop.
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooFewBranches.html b/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooFewBranches.html
index fcbd8e712f03..0832a5793d77 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooFewBranches.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooFewBranches.html
@@ -4,7 +4,7 @@ Reports <b>switch</b> statements with too few <b>case</b> labels.
Such statements may be more clearly expressed as <b>if</b> statements.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the minimum number of <b>case</b> labels expected.
+Use the field below to specify the minimum number of <b>case</b> labels expected.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooManyBranches.html b/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooManyBranches.html
index 0ceee7b6fd87..d1853c9b399a 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooManyBranches.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/SwitchStatementWithTooManyBranches.html
@@ -3,7 +3,7 @@
Reports <b>switch</b> statements with too many <b>case</b> labels.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum number of <b>case</b> labels expected.
+Use the field below to specify the maximum number of <b>case</b> labels expected.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ThrownExceptionsPerMethod.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ThrownExceptionsPerMethod.html
index 4a1d6db3543e..4c94a5df808a 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ThrownExceptionsPerMethod.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ThrownExceptionsPerMethod.html
@@ -5,7 +5,7 @@ different types of exceptions. Methods with too many exceptions declared
are a good sign that your error handling code is getting overly complex.
<!-- tooltip end -->
<p>
-Use the field provided below to specify the maximum acceptable number of throw clauses a method might have.
+Use the field below to specify the maximum number of <b>throws</b> clauses a method might have.
<p>
<small>Powered by InspectionGadgets</small>
</body>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TryFinallyCanBeTryWithResources.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TryFinallyCanBeTryWithResources.html
index 22533392f259..28b8411a23e5 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/TryFinallyCanBeTryWithResources.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/TryFinallyCanBeTryWithResources.html
@@ -1,7 +1,7 @@
<html>
<body>
Reports <b>try finally</b> statements which can use Java 7
-Automatic Resource Management. A quickfix is provided to convert the <b>try finally</b>
+Automatic Resource Management. A quickfix is available to convert the <b>try finally</b>
statement into a <b>try</b> with resources statement.
<p>
This inspection only reports if the project or module is configured to use a
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TryWithIdenticalCatches.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TryWithIdenticalCatches.html
index 79143fd4e68f..3b10d772375b 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/TryWithIdenticalCatches.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/TryWithIdenticalCatches.html
@@ -1,6 +1,6 @@
<html>
<body>
-Reports identical <b>catch</b> sections in <b>try</b> blocks under JDK 7. A quickfix is provided to collapse the sections into
+Reports identical <b>catch</b> sections in <b>try</b> blocks under JDK 7. A quickfix is available to collapse the sections into
a multi-catch section.
<p>
This inspection only reports if the project or module is configured to use a
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/TypeParameterNamingConvention.html b/plugins/InspectionGadgets/src/inspectionDescriptions/TypeParameterNamingConvention.html
index be4665aa3ba9..c305e8a67f9f 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/TypeParameterNamingConvention.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/TypeParameterNamingConvention.html
@@ -4,7 +4,7 @@ Reports type parameters whose names are either too short, too long, or do not fo
the specified regular expression pattern.
<!-- tooltip end -->
<p>
-Use the fields provided below to specify minimum length, maximum length and regular expression expected for type parameter names.
+Use the fields below to specify minimum length, maximum length and regular expression expected for type parameter names.
(Regular expressions are in standard <b>java.util.regex</b> format.)
<p>
<small>Powered by InspectionGadgets</small>
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/WhileCanBeForeach.html b/plugins/InspectionGadgets/src/inspectionDescriptions/WhileCanBeForeach.html
index 4bc193be7e3f..a5a7f944ff2a 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/WhileCanBeForeach.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/WhileCanBeForeach.html
@@ -1,7 +1,7 @@
<html>
<body>
Reports <b>while</b> loops which iterate
-over collections, and can be replaced with the "for each" iteration syntax,
+over collections, and can be replaced with the <b>foreach</b> iteration syntax,
which is available in Java 5 and newer.
<p>
This inspection only reports if the project or module is configured to use a
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.after.java
new file mode 100644
index 000000000000..ab585746b99e
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.after.java
@@ -0,0 +1,6 @@
+class Test {
+ {
+ // this comment will be deleted.
+ System.out.println();
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.java
new file mode 100644
index 000000000000..21b1a2d973a3
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/constant_if/Comment.java
@@ -0,0 +1,8 @@
+class Test {
+ {
+ i<caret>f (true) {
+ // this comment will be deleted.
+ System.out.println();
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.after.java
new file mode 100644
index 000000000000..d1777e043eab
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.after.java
@@ -0,0 +1,6 @@
+class Negated {
+
+ void check(String contentType) {
+ if (!"image/jpeg".equalsIgnoreCase(contentType)) {}
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.java
new file mode 100644
index 000000000000..d834fb67b7e1
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Negated.java
@@ -0,0 +1,6 @@
+class Negated {
+
+ void check(String contentType) {
+ if (contentType<caret> == null || !contentType.equalsIgnoreCase("image/jpeg")) {}
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.after.java
new file mode 100644
index 000000000000..79a55fd2112b
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.after.java
@@ -0,0 +1,6 @@
+class Normal {
+
+ void check(String contentType) {
+ if ("image/jpeg".equals(contentType)) {}
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.java
new file mode 100644
index 000000000000..8b87e90495ef
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/controlflow/simplifiable_equals_expression/Normal.java
@@ -0,0 +1,6 @@
+class Normal {
+
+ void check(String contentType) {
+ if ((contentType != <caret>null) && contentType.equals("image/jpeg")) {}
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/moveThrows.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/MoveThrows.java
index ea95fddcf155..ea95fddcf155 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/moveThrows.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/errorhandling/throws_runtime_exception/MoveThrows.java
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.after.java
new file mode 100644
index 000000000000..c7159d28aa56
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.after.java
@@ -0,0 +1,11 @@
+import org.slf4j.*;
+
+class UseOfConstant {
+
+ void foo() {
+ Logger logger = LoggerFactory.getLogger(UseOfConstant.class);
+ final String CONST = "const";
+ String var = "var";
+ logger.info("string {}" + CONST, var);
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.java
new file mode 100644
index 000000000000..9861dfd6f0ac
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/logging/string_concatenation_argument_to_log_call/UseOfConstant.java
@@ -0,0 +1,11 @@
+import org.slf4j.*;
+
+class UseOfConstant {
+
+ void foo() {
+ Logger logger = LoggerFactory.getLogger(UseOfConstant.class);
+ final String CONST = "const";
+ String var = "var";
+ logger.in<caret>fo("string " + (var) + CONST);
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.after.java
new file mode 100644
index 000000000000..c6dc251371e5
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.after.java
@@ -0,0 +1,15 @@
+class Comment {
+
+ String foo(int par) {
+ switch (par) {
+ case 11:
+ return "ciao";//case 1 bla bla
+ case 14:
+ return "fourteen";//case 2 bla bla
+ case 15:
+ return "fifteen"; //case 3 chchah
+ default:
+ return "default";
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.java
new file mode 100644
index 000000000000..00a181784e5d
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/migration/if_can_be_switch/Comment.java
@@ -0,0 +1,13 @@
+class Comment {
+
+ String foo(int par) {
+ i<caret>f(par == 11)
+ return "ciao";//case 1 bla bla
+ else if(par == 14)
+ return "fourteen";//case 2 bla bla
+ else if(par == 15)
+ return "fifteen"; //case 3 chchah
+ else
+ return "default";
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
index a5fe62bbe18c..3d9b0a2fd811 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/AutoClosableTest.java
@@ -35,4 +35,10 @@ class AutoClosableTest2
bar.go();
}
}
+
+ void dodo() throws java.io.IOException {
+ try (java.io.Reader reader = new java.io.FileReader("/home/steve/foo.txt")) {
+ System.out.println(reader);
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml
index 807c8ea762c3..599595a7163a 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/weaken_type/expected.xml
@@ -28,4 +28,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type may be weakened</problem_class>
<description>Type of variable &lt;code&gt;bar&lt;/code&gt; may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.AutoClosableTest2.Foo' #loc</description>
</problem>
+
+ <problem>
+ <file>AutoClosableTest.java</file>
+ <line>40</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type may be weakened</problem_class>
+ <description>Type of variable &lt;code&gt;reader&lt;/code&gt; may be weakened to 'java.io.Closeable' #loc</description>
+ </problem>
</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/AssignmentToSuperclassField.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/AssignmentToSuperclassField.java
new file mode 100644
index 000000000000..c3b0fb0380f8
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/AssignmentToSuperclassField.java
@@ -0,0 +1,25 @@
+package com.siyeh.igtest.assignment.assignment_to_superclass_field;
+
+class AssignmentToSuperclassField {
+ int i = 1;
+ int j = 2;
+ int k = 0;
+
+ AssignmentToSuperclassField() {}
+
+ AssignmentToSuperclassField(int i, int j, int k) {
+ this.i = i;
+ this.j = j;
+ this.k = k;
+ }
+}
+class B extends AssignmentToSuperclassField {
+ int z;
+
+ B() {
+ i += 3;
+ this.j = 4;
+ super.k++;
+ z = 100;
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/expected.xml
new file mode 100644
index 000000000000..a7aa39856153
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/assignment/assignment_to_superclass_field/expected.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+
+ <problem>
+ <file>AssignmentToSuperclassField.java</file>
+ <line>20</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constructor assigns value to field defined in superclass</problem_class>
+ <description>Assignment to field 'i' defined in superclass 'AssignmentToSuperclassField'</description>
+ </problem>
+
+ <problem>
+ <file>AssignmentToSuperclassField.java</file>
+ <line>21</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constructor assigns value to field defined in superclass</problem_class>
+ <description>Assignment to field 'j' defined in superclass 'AssignmentToSuperclassField'</description>
+ </problem>
+
+ <problem>
+ <file>AssignmentToSuperclassField.java</file>
+ <line>22</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constructor assigns value to field defined in superclass</problem_class>
+ <description>Assignment to field 'k' defined in superclass 'AssignmentToSuperclassField'</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/IgnoreResultsOfReadInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/IgnoreResultsOfReadInspection.java
deleted file mode 100644
index 010b97103504..000000000000
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/IgnoreResultsOfReadInspection.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.siyeh.igtest.bugs;
-
-import java.io.*;
-
-public class IgnoreResultsOfReadInspection
-{
- private void foo()
- {
- try
- {
- final FileInputStream stream = new FileInputStream("FOO");
- final byte[] buffer = new byte[10];
- stream.read(buffer);
- }
- catch(FileNotFoundException e)
- {
- }
- catch(IOException e)
- {
- }
-
- }
-}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/IgnoreResultOfCall.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/IgnoreResultOfCall.java
new file mode 100644
index 000000000000..6dbce04ce831
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/IgnoreResultOfCall.java
@@ -0,0 +1,10 @@
+package com.siyeh.igtest.bugs.ignore_result_of_call;
+
+class IgnoreResultOfCall {
+
+ void foo(Object o, String s) {
+ o.equals(s);
+ o.equals()
+ }
+
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/expected.xml
new file mode 100644
index 000000000000..7f64be4f9ef0
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ignore_result_of_call/expected.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>IgnoreResultOfCall.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Result of method call ignored</problem_class>
+ <description>Result of &lt;code&gt;Object.equals()&lt;/code&gt; is ignored #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ResultOfObjectAllocationIgnoredInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/ResultOfObjectAllocationIgnored.java
index 4f76d187ba20..1185f4ddb2ca 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/ResultOfObjectAllocationIgnoredInspection.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/ResultOfObjectAllocationIgnored.java
@@ -1,8 +1,8 @@
-package com.siyeh.igtest.bugs;
+package com.siyeh.igtest.bugs.result_of_object_allocation_ignored;
-public class ResultOfObjectAllocationIgnoredInspection {
+public class ResultOfObjectAllocationIgnored {
- private ResultOfObjectAllocationIgnoredInspection() {
+ private ResultOfObjectAllocationIgnored() {
super();
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/expected.xml
new file mode 100644
index 000000000000..319a29ac85b1
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/result_of_object_allocation_ignored/expected.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>ResultOfObjectAllocationIgnored.java</file>
+ <line>14</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Result of object allocation ignored</problem_class>
+ <description>Result of &lt;code&gt;new Comparable&lt;String&gt;()&lt;/code&gt; is ignored #loc</description>
+ </problem>
+
+ <problem>
+ <file>ResultOfObjectAllocationIgnored.java</file>
+ <line>10</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Result of object allocation ignored</problem_class>
+ <description>Result of &lt;code&gt;new Integer()&lt;/code&gt; is ignored #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/string_concatenation_missing_whitespace/Concatenations.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/string_concatenation_missing_whitespace/Concatenations.java
index c3f495333a7f..5d709ccd8b4b 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/string_concatenation_missing_whitespace/Concatenations.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/string_concatenation_missing_whitespace/Concatenations.java
@@ -8,5 +8,7 @@ class Concatenations {
System.out.println("no:" + i);
System.out.println("i" + i);
System.out.println("i" + ((String)"j"));
+ System.out.println('{' + "a" + '\'');
+ String.format("aaaa%n" + "bbbb");
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumnetToVariableArgMethod.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumentToVariableArgMethod.java
index 1c62329ea804..aa8620ac34c1 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumnetToVariableArgMethod.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/PrimitiveArrayArgumentToVariableArgMethod.java
@@ -1,6 +1,6 @@
package com.siyeh.igtest.bugs.var_arg;
-public class PrimitiveArrayArgumnetToVariableArgMethod
+public class PrimitiveArrayArgumentToVariableArgMethod
{
public static void main(String[] arg)
{
@@ -15,4 +15,14 @@ public class PrimitiveArrayArgumnetToVariableArgMethod
private static void methodVarArgByteArray(byte[]... bytes)
{
}
+
+ class X<T> {
+ void method(T... t) {
+ }
+ }
+
+ void foo(byte[] bs) {
+ final X<byte[]> x = new X<byte[]>();
+ x.method(bs);
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/expected.xml
index c308de6db0a5..cee36b29eb4e 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/var_arg/expected.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
- <file>PrimitiveArrayArgumnetToVariableArgMethod.java</file>
+ <file>PrimitiveArrayArgumentToVariableArgMethod.java</file>
<line>7</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Confusing primitive array argument to var-arg method</problem_class>
<description>Confusing primitive array argument to var-arg method #loc</description>
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/non_final_utility_class/NonFinalUtilityClass.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/non_final_utility_class/NonFinalUtilityClass.java
index d77cc0ebe49e..9d49e02351ff 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/non_final_utility_class/NonFinalUtilityClass.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/non_final_utility_class/NonFinalUtilityClass.java
@@ -7,4 +7,7 @@ class NonFinalUtilityClass {
}
final class FinalUtilityClass {
public static void foo() {}
+}
+abstract class NoUtilityClass {
+ public static void foo() {}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/DuplicateBooleanBranch.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/DuplicateBooleanBranch.java
new file mode 100644
index 000000000000..d68b1d43e167
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/DuplicateBooleanBranch.java
@@ -0,0 +1,8 @@
+package com.siyeh.igtest.controlflow.duplicate_boolean_branch;
+
+public class DuplicateBooleanBranch {
+
+ boolean x(boolean b, boolean c){
+ return b && b && c;
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/expected.xml
new file mode 100644
index 000000000000..f59e83b86cf3
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_boolean_branch/expected.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>DuplicateBooleanBranch.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition on '&amp;&amp;' or '||'</problem_class>
+ <description>Duplicate branch &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>DuplicateBooleanBranch.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition on '&amp;&amp;' or '||'</problem_class>
+ <description>Duplicate branch &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/DuplicateCondition.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/DuplicateCondition.java
new file mode 100644
index 000000000000..ef047398e14f
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/DuplicateCondition.java
@@ -0,0 +1,12 @@
+package com.siyeh.igtest.controlflow.duplicate_condition;
+
+public class DuplicateCondition {
+
+ void x(boolean b) {
+ if (b || b || b ) {
+
+ } else if (b) {
+
+ } else if (b) {}
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/expected.xml
new file mode 100644
index 000000000000..47f1e352b5e6
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/duplicate_condition/expected.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>DuplicateCondition.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition in 'if' statement</problem_class>
+ <description>Duplicate condition &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>DuplicateCondition.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition in 'if' statement</problem_class>
+ <description>Duplicate condition &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>DuplicateCondition.java</file>
+ <line>8</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition in 'if' statement</problem_class>
+ <description>Duplicate condition &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>DuplicateCondition.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition in 'if' statement</problem_class>
+ <description>Duplicate condition &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>DuplicateCondition.java</file>
+ <line>10</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Duplicate condition in 'if' statement</problem_class>
+ <description>Duplicate condition &lt;code&gt;b&lt;/code&gt; #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/FallthruInSwitch.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/FallthruInSwitch.java
index ed8501e48045..6ce4e6a7d4f1 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/FallthruInSwitch.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/FallthruInSwitch.java
@@ -20,7 +20,7 @@ public class FallthruInSwitch
case (4):
System.out.println("3");
case (5):
- case (6):
+ case (6): // don't warn here
System.out.println("4");
}
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/expected.xml
index fa39d92753c6..4017e6ccf8c8 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/fallthru_in_switch_statement/expected.xml
@@ -8,11 +8,4 @@
<description>&lt;code&gt;case (5):&lt;/code&gt; fall-through in 'switch' statement #loc</description>
</problem>
- <problem>
- <file>FallthruInSwitch.java</file>
- <line>23</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Fall-through in 'switch' statement</problem_class>
- <description>&lt;code&gt;case (6):&lt;/code&gt; fall-through in 'switch' statement #loc</description>
- </problem>
-
</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/OverlyComplexBooleanExpression.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/OverlyComplexBooleanExpression.java
new file mode 100644
index 000000000000..0bd94cfb6f81
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/OverlyComplexBooleanExpression.java
@@ -0,0 +1,13 @@
+package com.siyeh.igtest.controlflow.overly_complex_boolean_expression;
+
+public class OverlyComplexBooleanExpression {
+
+ boolean x(boolean b) {
+ return b && b || b && b;
+ }
+
+ boolean ignore(boolean b) {
+ return b || b || b || b;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/expected.xml
new file mode 100644
index 000000000000..5af2080fb042
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/overly_complex_boolean_expression/expected.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>OverlyComplexBooleanExpression.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Overly complex boolean expression</problem_class>
+ <description>Overly complex boolean expression (4 terms) #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/PointlessBooleanExpression.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/PointlessBooleanExpression.java
index 15020be28068..0cfd2f6840ba 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/PointlessBooleanExpression.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/PointlessBooleanExpression.java
@@ -28,4 +28,11 @@ class PointlessBooleanExpression {
boolean y = false || c;
boolean z = b != true;
}
+}
+class Presley {
+ void elvis(Object king) {
+ if (true && king != null && king.hashCode() > 1) {
+ // blah
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/expected.xml
index 1d0a66df6e32..32f91701b161 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_boolean_expression/expected.xml
@@ -42,4 +42,11 @@
<description>&lt;code&gt;b != true&lt;/code&gt; can be simplified to '!b' #loc</description>
</problem>
+ <problem>
+ <file>PointlessBooleanExpression.java</file>
+ <line>34</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless boolean expression</problem_class>
+ <description>&lt;code&gt;true &amp;&amp; king != null &amp;&amp; king.hashCode() &gt; 1&lt;/code&gt; can be simplified to 'king != null &amp;&amp; king.hashCode() &gt; 1' #loc</description>
+ </problem>
+
</problems>
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_null_check/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_null_check/expected.xml
index 6805724ab1d6..de2c46db9665 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_null_check/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/controlflow/pointless_null_check/expected.xml
@@ -4,48 +4,48 @@
<file>PointlessNullCheck.java</file>
<line>6</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>10</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>14</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>18</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>22</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>26</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>30</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless null check</problem_class>
- <description>Pointless null check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
<problem>
<file>PointlessNullCheck.java</file>
<line>33</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless 'null' check</problem_class>
- <description>Pointless 'null' check can be removed</description>
+ <description>Unnecessary 'null' check</description>
</problem>
</problems>
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java
index 796470be95c7..883b3e2e5a46 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/AutoBoxing.java
@@ -45,4 +45,12 @@ public class AutoBoxing {
Byte s = 8;
Short j = (byte)7;
}
+
+ void polyadic() {
+ Integer i = 1 + 2 + 3;
+ }
+
+ void doInstanceof(Object o) {
+ Boolean b = o instanceof String;
+ }
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml
index 2f40755387dc..c5867eeadea1 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/jdk/auto_boxing/expected.xml
@@ -79,4 +79,18 @@
<description>Auto-boxing &lt;code&gt;(byte)7&lt;/code&gt; #loc</description>
</problem>
+ <problem>
+ <file>AutoBoxing.java</file>
+ <line>50</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Auto-boxing</problem_class>
+ <description>Auto-boxing &lt;code&gt;1 + 2 + 3&lt;/code&gt; #loc</description>
+ </problem>
+
+ <problem>
+ <file>AutoBoxing.java</file>
+ <line>54</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Auto-boxing</problem_class>
+ <description>Auto-boxing &lt;code&gt;o instanceof String&lt;/code&gt; #loc</description>
+ </problem>
+
</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/LogStatementGuardedByLogCondition.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/LogStatementGuardedByLogCondition.java
index b8f4f8c43443..dfb8c65cc7e0 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/LogStatementGuardedByLogCondition.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/LogStatementGuardedByLogCondition.java
@@ -32,6 +32,10 @@ public class LogStatementGuardedByLogCondition {
}
}
+ void alternativeDebugMethodSignature(int i) {
+ LOG.debug(i, "asdfasdf");
+ }
+
static class Logger {
public Logger(String log) {
@@ -40,6 +44,8 @@ public class LogStatementGuardedByLogCondition {
public void debug(String s) {
}
+ public void debug(int i, String s) {}
+
public void trace(String s) {}
public boolean isDebug() {
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/expected.xml
index e04e666cf360..701ef7837e72 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/logging/log_statement_guarded_by_log_condition/expected.xml
@@ -14,4 +14,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Log statement not guarded by log condition</problem_class>
<description>&lt;code&gt;debug()&lt;/code&gt; log statement not guarded by log condition #loc</description>
</problem>
+
+ <problem>
+ <file>LogStatementGuardedByLogCondition.java</file>
+ <line>36</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Log statement not guarded by log condition</problem_class>
+ <description>&lt;code&gt;debug()&lt;/code&gt; log statement not guarded by log condition #loc</description>
+ </problem>
</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java
index 8260653742c9..4b65e91cb8f2 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/IfCanBeSwitch.java
@@ -1,4 +1,6 @@
-class C {
+import org.jetbrains.annotations.Nullable;
+
+class IfCanBeSwitch {
void m1(int i) { // ok
if (i == 0) System.out.println("zero"); else if (i == 1) System.out.println("one"); else System.out.println("many");
}
@@ -11,11 +13,36 @@ class C {
if (i == (byte)0) System.out.println("zero"); else if (i == (byte)1) System.out.println("one"); else System.out.println("many");
}
- void m1(int i) { // bad, long literals
+ void m2(int i) { // bad, long literals
if (i == 0L) System.out.println("zero"); else if (i == 1L) System.out.println("one"); else System.out.println("many");
}
void m2(long l) { // bad, long expression
if (l == 0) System.out.println("zero"); else if (l == 1) System.out.println("one"); else System.out.println("many");
}
+
+ void polyadic() {
+ String s = null;
+ if ("asdf".equals(s) || "addd".equals(s) || "lkjh".equals(s)) {
+ System.out.println("asdf");
+
+ } else if ("null".equals(s)) {
+ System.out.println("null");
+
+ } else {
+ System.out.println("default");
+ }
+ }
+
+ void nullable(@Nullable String s) {
+ if ("a".equals(s)) {
+ System.out.println(1);
+ } else if ("b".equals(s)) {
+ System.out.println(2);
+ } else if ("c".equals(s)) {
+ System.out.println(3);
+ } else {
+ System.out.println(4);
+ }
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml
index 197819a78333..af78b4213567 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/if_switch/expected.xml
@@ -2,21 +2,28 @@
<problems>
<problem>
<file>IfCanBeSwitch.java</file>
- <line>3</line>
+ <line>5</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement replaceable with 'switch' statement #loc</description>
</problem>
<problem>
<file>IfCanBeSwitch.java</file>
- <line>7</line>
+ <line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement replaceable with 'switch' statement #loc</description>
</problem>
<problem>
<file>IfCanBeSwitch.java</file>
- <line>11</line>
+ <line>13</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class>
+ <description>&lt;code&gt;if&lt;/code&gt; statement replaceable with 'switch' statement #loc</description>
+ </problem>
+
+ <problem>
+ <file>IfCanBeSwitch.java</file>
+ <line>26</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'if' replaceable with 'switch'</problem_class>
<description>&lt;code&gt;if&lt;/code&gt; statement replaceable with 'switch' statement #loc</description>
</problem>
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/method_can_be_variable_arity_method/MethodCanBeVariableArity.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/method_can_be_variable_arity_method/MethodCanBeVariableArity.java
index 4fd8268a94fe..db74d0cfc230 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/method_can_be_variable_arity_method/MethodCanBeVariableArity.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/migration/method_can_be_variable_arity_method/MethodCanBeVariableArity.java
@@ -17,4 +17,11 @@ abstract class MyInputStream extends Reader {
public int read(char[] cbuf) throws IOException {
return super.read(cbuf);
}
+}
+class Sub extends MethodCanBeVariableArity {
+
+ @Override
+ public void convertMe(String[] ss) {
+ super.convertMe(ss);
+ }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/DivideByZero.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/DivideByZero.java
new file mode 100644
index 000000000000..9f24ebf109ee
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/DivideByZero.java
@@ -0,0 +1,13 @@
+package com.siyeh.igtest.numeric.divide_by_zero;
+
+public class DivideByZero {
+
+ int divide(int num) {
+ return num / 3 / 0;
+ }
+
+ int rest(int num) {
+ return num % 0 % 1;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/expected.xml
new file mode 100644
index 000000000000..3a07cc5477ef
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/divide_by_zero/expected.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>DivideByZero.java</file>
+ <line>6</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Division by zero</problem_class>
+ <description>Division by zero #loc</description>
+ </problem>
+
+ <problem>
+ <file>DivideByZero.java</file>
+ <line>10</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Division by zero</problem_class>
+ <description>Division by zero #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/ImplicitNumericConversion.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/ImplicitNumericConversion.java
index 9aa5a5a2dde8..09ee0ed4b595 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/ImplicitNumericConversion.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/ImplicitNumericConversion.java
@@ -79,4 +79,8 @@ public class ImplicitNumericConversion
int a[] = new int[b];
a[b] = (byte)1;
}
+
+ private void polyadic() {
+ long l = 1 + 2 + 3;
+ }
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/expected.xml
index 3b9e14d34212..833457e3f0cb 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/implicit_numeric_conversion/expected.xml
@@ -168,4 +168,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Implicit numeric conversion</problem_class>
<description>Implicit numeric conversion of &lt;code&gt;(byte)1&lt;/code&gt; from 'byte' to 'int' #loc</description>
</problem>
+
+ <problem>
+ <file>ImplicitNumericConversion.java</file>
+ <line>84</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Implicit numeric conversion</problem_class>
+ <description>Implicit numeric conversion of &lt;code&gt;1 + 2 + 3&lt;/code&gt; from 'int' to 'long' #loc</description>
+ </problem>
</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java
index 60d67f02003f..9468de1baf32 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/unnecessary_explicit_numeric_cast/UnnecessaryExplicitNumericCast.java
@@ -48,4 +48,9 @@ public class UnnecessaryExplicitNumericCast {
void target(int c) {}
void target(char c) {}
void target2(int d) {}
+
+ void foo() {
+ float x = 2;
+ target((int) x); // this line complains: 'x' unnecessarily cast to 'int'
+ }
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java
index ce6022abc44f..70695c4e1fff 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/style/unnecessary_parentheses/UnnecessaryParenthesesInspection.java
@@ -107,4 +107,9 @@ public class UnnecessaryParenthesesInspection
final Object[] objects = {(args.length - 1), 1};
return args.length > 0 && place.equals(args[(args.length - 1)]);// here are unnecessary parentheses inside args[...]
}
+
+ void uu() {
+ Object info = new Object[]{"abc"};
+ String s = (String)((Object[])info)[0];
+ }
}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/SynchronizationOnLocalVariableOrMethodParameter.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/SynchronizationOnLocalVariableOrMethodParameter.java
new file mode 100644
index 000000000000..6eaff9ad5acd
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/SynchronizationOnLocalVariableOrMethodParameter.java
@@ -0,0 +1,34 @@
+package com.siyeh.igtest.threading.synchronization_on_local_variable_or_method_parameter;
+
+class SynchronizationOnLocalVariableOrMethodParameter {
+
+ static {
+ final Object lock = new Object();
+ new Object(){{
+ synchronized (lock) {} // no warning
+ }};
+ }
+
+ interface IntegerMath {
+ int operation(int a, int b);
+ }
+ public int operateBinary(int a, int b, IntegerMath op) {
+ return op.operation(a, b);
+ }
+ public static void foo() {
+ final Object lock = new Object();
+ final SynchronizationOnLocalVariableOrMethodParameter x = new SynchronizationOnLocalVariableOrMethodParameter();
+ IntegerMath addition = (a, b) -> {
+ synchronized(lock) {return a + b;} // no warning
+ };
+ System.out.println("40 + 2 = " +
+ x.operateBinary(40, 2, addition));
+ }
+
+ void bar() {
+ final Object lock = new Object();
+ synchronized (lock) {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/expected.xml
new file mode 100644
index 000000000000..efee019926d2
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter/expected.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<problems>
+ <problem>
+ <file>SynchronizationOnLocalVariableOrMethodParameter.java</file>
+ <line>30</line>
+ <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Synchronization on local variable or method parameter</problem_class>
+ <description>Synchronization on local variable &lt;code&gt;lock&lt;/code&gt; #loc</description>
+ </problem>
+</problems> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java
new file mode 100644
index 000000000000..3760b2f16d8f
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/LightInspectionTestCase.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2000-2013 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;
+
+import com.intellij.codeInspection.LocalInspectionTool;
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+import org.intellij.lang.annotations.Language;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public abstract class LightInspectionTestCase extends LightCodeInsightFixtureTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ for (String environmentClass : getEnvironmentClasses()) {
+ myFixture.addClass(environmentClass);
+ }
+ myFixture.enableInspections(getInspection());
+ }
+
+ protected abstract LocalInspectionTool getInspection();
+
+ @NonNls
+ protected String[] getEnvironmentClasses() {
+ return new String[]{};
+ }
+
+ protected final void doTest(@Language("JAVA") @NotNull @NonNls String classText) {
+ @NonNls final StringBuilder newText = new StringBuilder();
+ int start = 0;
+ int end = classText.indexOf("/*");
+ while (end >= 0) {
+ newText.append(classText, start, end);
+ start = end + 2;
+ end = classText.indexOf("*/", end);
+ if (end < 0) {
+ throw new IllegalArgumentException("invalid class text");
+ }
+ final String warning = classText.substring(start, end);
+ if (warning.isEmpty()) {
+ newText.append("</warning>");
+ } else {
+ newText.append("<warning descr=\"").append(warning).append("\">");
+ }
+ start = end + 2;
+ end = classText.indexOf("/*", end + 1);
+ }
+ newText.append(classText, start, classText.length());
+ myFixture.configureByText("X.java", newText.toString());
+ myFixture.testHighlighting(true, false, false);
+ }
+}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspectionTest.java
new file mode 100644
index 000000000000..c872e143c188
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/assignment/AssignmentToSuperclassFieldInspectionTest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2013 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.assignment;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class AssignmentToSuperclassFieldInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/assignment/assignment_to_superclass_field", new AssignmentToSuperclassFieldInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/IgnoreResultOfCallInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/IgnoreResultOfCallInspectionTest.java
new file mode 100644
index 000000000000..9e575efebbac
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/IgnoreResultOfCallInspectionTest.java
@@ -0,0 +1,10 @@
+package com.siyeh.ig.bugs;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class IgnoreResultOfCallInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/bugs/ignore_result_of_call", new IgnoreResultOfCallInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspectionTest.java
new file mode 100644
index 000000000000..505385d32ca2
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumentToVariableArgMethodInspectionTest.java
@@ -0,0 +1,10 @@
+package com.siyeh.ig.bugs;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class PrimitiveArrayArgumentToVariableArgMethodInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/bugs/var_arg", new PrimitiveArrayArgumentToVariableArgMethodInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumnetToVariableArgMethodInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumnetToVariableArgMethodInspectionTest.java
deleted file mode 100644
index f2b0ef1277a0..000000000000
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/PrimitiveArrayArgumnetToVariableArgMethodInspectionTest.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.siyeh.ig.bugs;
-
-import com.siyeh.ig.IGInspectionTestCase;
-
-public class PrimitiveArrayArgumnetToVariableArgMethodInspectionTest extends IGInspectionTestCase {
-
- public void test() throws Exception {
- doTest("com/siyeh/igtest/bugs/var_arg",
- new PrimitiveArrayArgumentToVariableArgMethodInspection());
- }
-} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspectionTest.java
new file mode 100644
index 000000000000..51e31a55987f
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/ResultOfObjectAllocationIgnoredInspectionTest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2000-2013 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.bugs;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class ResultOfObjectAllocationIgnoredInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/bugs/result_of_object_allocation_ignored", new ResultOfObjectAllocationIgnoredInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspectionTest.java
new file mode 100644
index 000000000000..2eae159f3403
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateBooleanBranchInspectionTest.java
@@ -0,0 +1,10 @@
+package com.siyeh.ig.controlflow;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class DuplicateBooleanBranchInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/controlflow/duplicate_boolean_branch", new DuplicateBooleanBranchInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateConditionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateConditionInspectionTest.java
new file mode 100644
index 000000000000..aaa379cf6ad1
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/DuplicateConditionInspectionTest.java
@@ -0,0 +1,10 @@
+package com.siyeh.ig.controlflow;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class DuplicateConditionInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/controlflow/duplicate_condition", new DuplicateConditionInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspectionTest.java
new file mode 100644
index 000000000000..bca8529d1ed7
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/OverlyComplexBooleanExpressionInspectionTest.java
@@ -0,0 +1,13 @@
+package com.siyeh.ig.controlflow;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class OverlyComplexBooleanExpressionInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ final OverlyComplexBooleanExpressionInspection tool = new OverlyComplexBooleanExpressionInspection();
+ tool.m_limit = 3;
+ tool.m_ignorePureConjunctionsDisjunctions = true;
+ doTest("com/siyeh/igtest/controlflow/overly_complex_boolean_expression", tool);
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspectionTest.java
index 5c213bf5c00e..fb1751dc2d55 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspectionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -25,6 +25,6 @@ public class PointlessBooleanExpressionInspectionTest extends IGInspectionTestCa
public void test() throws Exception {
final PointlessBooleanExpressionInspection inspection = new PointlessBooleanExpressionInspection();
inspection.m_ignoreExpressionsContainingConstants = true;
- doTest("com/siyeh/igtest/controlflow/pointless_boolean_expression_ignore_cont_const", inspection);
+ doTest("com/siyeh/igtest/controlflow/pointless_boolean_expression", inspection);
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
index f3ace921a257..30a81c245adb 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessBooleanExpressionFixTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -26,9 +26,10 @@ public class PointlessBooleanExpressionFixTest extends IGQuickFixesTestCase {
super.setUp();
myFixture.enableInspections(new PointlessBooleanExpressionInspection());
myRelativePath = "pointlessboolean";
- myDefaultHint = InspectionGadgetsBundle.message("pointless.nullcheck.simplify.quickfix");
+ myDefaultHint = InspectionGadgetsBundle.message("pointless.bitwise.expression.simplify.quickfix");
}
+
public void testNegation() {
doTest();
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessNullCheckFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessNullCheckFixTest.java
index bafeb45518b2..e101a9a3e1de 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessNullCheckFixTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/PointlessNullCheckFixTest.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2000-2011 JetBrains s.r.o.
- *pointless.nullcheck.quickfix
+ * Copyright 2000-2013 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
@@ -26,10 +26,9 @@ public class PointlessNullCheckFixTest extends IGQuickFixesTestCase {
super.setUp();
myFixture.enableInspections(new PointlessNullCheckInspection());
myRelativePath = "pointlessnullcheck";
- myDefaultHint = InspectionGadgetsBundle.message("pointless.nullcheck.simplify.quickfix");
}
public void testScenario1() {
- doTest();
+ doTest(InspectionGadgetsBundle.message("pointless.nullcheck.simplify.quickfix", "arg != null"));
}
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/ConstantIfFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/ConstantIfFixTest.java
new file mode 100644
index 000000000000..7613d1818b14
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/ConstantIfFixTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2000-2013 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.fixes.controlflow;
+
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.IGQuickFixesTestCase;
+import com.siyeh.ig.controlflow.ConstantIfStatementInspection;
+
+public class ConstantIfFixTest extends IGQuickFixesTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myFixture.enableInspections(new ConstantIfStatementInspection());
+ myRelativePath = "controlflow/constant_if";
+ myDefaultHint = InspectionGadgetsBundle.message("constant.conditional.expression.simplify.quickfix");
+ }
+
+ public void testComment() { doTest(); }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/SimplifiableEqualsExpressionFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/SimplifiableEqualsExpressionFixTest.java
new file mode 100644
index 000000000000..1ec9847167d1
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/controlflow/SimplifiableEqualsExpressionFixTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2013 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.fixes.controlflow;
+
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.IGQuickFixesTestCase;
+import com.siyeh.ig.controlflow.ConstantIfStatementInspection;
+import com.siyeh.ig.controlflow.SimplifiableEqualsExpressionInspection;
+
+public class SimplifiableEqualsExpressionFixTest extends IGQuickFixesTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myFixture.enableInspections(new SimplifiableEqualsExpressionInspection());
+ myRelativePath = "controlflow/simplifiable_equals_expression";
+ }
+
+ public void testNormal() { doTest(InspectionGadgetsBundle.message("simplifiable.equals.expression.quickfix", "equals")); }
+ public void testNegated() { doTest(InspectionGadgetsBundle.message("simplifiable.equals.expression.quickfix", "equalsIgnoreCase")); }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/errorhandling/ThrowsRuntimeExceptionInspectionFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/errorhandling/ThrowsRuntimeExceptionInspectionFixTest.java
index 500d8244adad..0b29ddfd081a 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/errorhandling/ThrowsRuntimeExceptionInspectionFixTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/errorhandling/ThrowsRuntimeExceptionInspectionFixTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2013 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.
@@ -17,8 +17,6 @@ package com.siyeh.ig.fixes.errorhandling;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.IGQuickFixesTestCase;
-import com.siyeh.ig.errorhandling.CaughtExceptionImmediatelyRethrownInspection;
-import com.siyeh.ig.errorhandling.EmptyFinallyBlockInspection;
import com.siyeh.ig.errorhandling.ThrowsRuntimeExceptionInspection;
public class ThrowsRuntimeExceptionInspectionFixTest extends IGQuickFixesTestCase {
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/logging/StringConcatenationArgumentToLogCallFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/logging/StringConcatenationArgumentToLogCallFixTest.java
new file mode 100644
index 000000000000..9257d3e29062
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/logging/StringConcatenationArgumentToLogCallFixTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2000-2013 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.fixes.logging;
+
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.IGQuickFixesTestCase;
+import com.siyeh.ig.logging.StringConcatenationArgumentToLogCallInspection;
+
+public class StringConcatenationArgumentToLogCallFixTest extends IGQuickFixesTestCase {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ myDefaultHint = InspectionGadgetsBundle.message("string.concatenation.in.format.call.quickfix");
+ myFixture.addClass("package org.slf4j; public interface Logger { void info(String format); }");
+ myFixture.addClass("package org.slf4j; public class LoggerFactory { public static Logger getLogger(Class clazz) { return null; }}");
+ myFixture.enableInspections(new StringConcatenationArgumentToLogCallInspection());
+ }
+
+ public void testUseOfConstant() {
+ doTest();
+ }
+
+ @Override
+ protected String getRelativePath() {
+ return "logging/string_concatenation_argument_to_log_call";
+ }
+}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/migration/IfCanBeSwitchFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/migration/IfCanBeSwitchFixTest.java
new file mode 100644
index 000000000000..bc14f28ee9c5
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/migration/IfCanBeSwitchFixTest.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2000-2013 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.fixes.migration;
+
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.IGQuickFixesTestCase;
+import com.siyeh.ig.migration.IfCanBeSwitchInspection;
+
+public class IfCanBeSwitchFixTest extends IGQuickFixesTestCase {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ final IfCanBeSwitchInspection inspection = new IfCanBeSwitchInspection();
+ inspection.suggestIntSwitches = true;
+ myFixture.enableInspections(inspection);
+ myRelativePath = "migration/if_can_be_switch";
+ myDefaultHint = InspectionGadgetsBundle.message("if.can.be.switch.quickfix");
+ }
+
+ public void testComment() {
+ doTest();
+ }
+}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java
new file mode 100644
index 000000000000..a5a246170b43
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/PlaceholderCountMatchesArgumentCountInspectionTest.java
@@ -0,0 +1,62 @@
+package com.siyeh.ig.logging;
+
+import com.intellij.codeInspection.LocalInspectionTool;
+import com.siyeh.ig.LightInspectionTestCase;
+
+public class PlaceholderCountMatchesArgumentCountInspectionTest extends LightInspectionTestCase {
+ @Override
+ protected LocalInspectionTool getInspection() {
+ return new PlaceholderCountMatchesArgumentCountInspection();
+ }
+
+ @Override
+ protected String[] getEnvironmentClasses() {
+ return new String[]{
+ "package org.slf4j; public interface Logger { void info(String format, Object... arguments); }",
+ "package org.slf4j; public class LoggerFactory { public static Logger getLogger(Class clazz) { return null; }}"};
+ }
+
+ public void testNoWarn() {
+ doTest("import org.slf4j.*;\n" +
+ "class X {\n" +
+ " void foo() {\n" +
+ " Logger logger = LoggerFactory.getLogger(X.class);\n" +
+ " logger.info(\"string {}\", 1);\n" +
+ " }\n" +
+ "}"
+ );
+ }
+
+ public void testMorePlaceholders() {
+ doTest("import org.slf4j.*;\n" +
+ "class X {\n" +
+ " void foo() {\n" +
+ " Logger logger = LoggerFactory.getLogger(X.class);\n" +
+ " logger./*'info()' call has fewer arguments (1) than placeholders (2)*/info/**/(\"string {}{}\", 1);\n" +
+ " }\n" +
+ "}"
+ );
+ }
+
+ public void testFewerPlaceholders() {
+ doTest("import org.slf4j.*;\n" +
+ "class X {\n" +
+ " void foo() {\n" +
+ " Logger logger = LoggerFactory.getLogger(X.class);\n" +
+ " logger./*'info()' call has more arguments (1) than placeholders (0)*/info/**/(\"string\", 1);\n" +
+ " }\n" +
+ "}"
+ );
+ }
+
+ public void testThrowable() {
+ doTest("import org.slf4j.*;\n" +
+ "class X {\n" +
+ " void foo() {\n" +
+ " Logger logger = LoggerFactory.getLogger(X.class);\n" +
+ " logger.info(\"string {}\", 1, new RuntimeException());\n" +
+ " }\n" +
+ "}"
+ );
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspectionTest.java
new file mode 100644
index 000000000000..442a2fc8d2b9
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/logging/StringConcatenationArgumentToLogCallInspectionTest.java
@@ -0,0 +1,31 @@
+package com.siyeh.ig.logging;
+
+import com.intellij.codeInspection.LocalInspectionTool;
+import com.siyeh.ig.LightInspectionTestCase;
+
+public class StringConcatenationArgumentToLogCallInspectionTest extends LightInspectionTestCase {
+ @Override
+ protected LocalInspectionTool getInspection() {
+ return new StringConcatenationArgumentToLogCallInspection();
+ }
+
+ @Override
+ protected String[] getEnvironmentClasses() {
+ return new String[]{
+ "package org.slf4j; public interface Logger { void debug(String format); }",
+ "package org.slf4j; public class LoggerFactory { public static Logger getLogger(Class clazz) { return null; }}"};
+ }
+
+ public void testBasic() {
+ doTest("import org.slf4j.*;\n" +
+ "class X {\n" +
+ " void foo() {\n" +
+ " Logger logger = LoggerFactory.getLogger(X.class);\n" +
+ " final String CONST = \"const\";\n" +
+ " String var = \"var\";\n" +
+ " logger./*Non-constant string concatenation as argument to 'debug()' logging call*/debug/**/(\"string \" + var + CONST);\n" +
+ " }\n" +
+ "}"
+ );
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java
index 07adab51d884..bf9dced7682a 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/IfCanBeSwitchInspectionTest.java
@@ -16,12 +16,23 @@
package com.siyeh.ig.migration;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.LanguageLevelProjectExtension;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.testFramework.IdeaTestUtil;
import com.siyeh.ig.IGInspectionTestCase;
public class IfCanBeSwitchInspectionTest extends IGInspectionTestCase {
+
+ @Override
+ protected Sdk getTestProjectSdk() {
+ LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
+ return IdeaTestUtil.getMockJdk17();
+ }
+
public void test() throws Exception {
final IfCanBeSwitchInspection inspection = new IfCanBeSwitchInspection();
inspection.suggestIntSwitches = true;
- doTest("com/siyeh/igtest/migration/if_switch", new LocalInspectionToolWrapper(inspection));
+ doTest("com/siyeh/igtest/migration/if_switch", new LocalInspectionToolWrapper(inspection));
}
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspectionTest.java
index b07f6920fb2e..a54bd64d3b47 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/migration/MethodCanBeVariableArityMethodInspectionTest.java
@@ -5,10 +5,9 @@ import com.siyeh.ig.IGInspectionTestCase;
public class MethodCanBeVariableArityMethodInspectionTest extends IGInspectionTestCase {
public void test() throws Exception {
- final MethodCanBeVariableArityMethodInspection tool =
- new MethodCanBeVariableArityMethodInspection();
+ final MethodCanBeVariableArityMethodInspection tool = new MethodCanBeVariableArityMethodInspection();
tool.ignoreByteAndShortArrayParameters = true;
- doTest("com/siyeh/igtest/migration/method_can_be_variable_arity_method",
- tool);
+ tool.ignoreOverridingMethods = true;
+ doTest("com/siyeh/igtest/migration/method_can_be_variable_arity_method", tool);
}
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/DivideByZeroInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/DivideByZeroInspectionTest.java
new file mode 100644
index 000000000000..7fb38a3f579d
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/numeric/DivideByZeroInspectionTest.java
@@ -0,0 +1,10 @@
+package com.siyeh.ig.numeric;
+
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class DivideByZeroInspectionTest extends IGInspectionTestCase {
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/numeric/divide_by_zero", new DivideByZeroInspection());
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspectionTest.java
new file mode 100644
index 000000000000..da714c2abbad
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/SynchronizationOnLocalVariableOrMethodParameterInspectionTest.java
@@ -0,0 +1,21 @@
+package com.siyeh.ig.threading;
+
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.LanguageLevelProjectExtension;
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.testFramework.IdeaTestUtil;
+import com.siyeh.ig.IGInspectionTestCase;
+
+public class SynchronizationOnLocalVariableOrMethodParameterInspectionTest extends IGInspectionTestCase {
+
+ @Override
+ protected Sdk getTestProjectSdk() {
+ LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
+ return IdeaTestUtil.getMockJdk17();
+ }
+
+ public void test() throws Exception {
+ doTest("com/siyeh/igtest/threading/synchronization_on_local_variable_or_method_parameter",
+ new SynchronizationOnLocalVariableOrMethodParameterInspection());
+ }
+}