diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
index 2f213319dd35..1cbbc76cd3ae 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
@@ -2157,6 +2157,7 @@ synchronization.on.get.class.display.name=Synchronization on 'getClass()'
synchronization.on.get.class.problem.descriptor=Synchronization on #ref() #loc
object.instantiation.inside.equals.or.hashcode.display.name=Object instantiation inside 'equals()' or 'hashCode()'
object.instantiation.inside.equals.or.hashcode.problem.descriptor=Object instantiation inside ''{0}()'' #loc
+object.instantiation.inside.equals.or.hashcode.problem.descriptor2=Object instantiation inside ''{0}()'' ({1})#loc
lambda.body.can.be.code.block.name=Lambda body can be code block
lambda.body.can.be.code.block.quickfix=Expand lambda body to {...}
lambda.parameter.type.can.be.specified.name=Lambda parameter type can be specified
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ObjectInstantiationInEqualsHashCodeInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ObjectInstantiationInEqualsHashCodeInspection.java
index 449b8e0afcca..a8e018ff84c2 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ObjectInstantiationInEqualsHashCodeInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/ObjectInstantiationInEqualsHashCodeInspection.java
@@ -42,6 +42,9 @@ public class ObjectInstantiationInEqualsHashCodeInspection extends BaseInspectio
protected String buildErrorString(Object... infos) {
final PsiMethod method = PsiTreeUtil.getParentOfType((PsiElement)infos[0], PsiMethod.class);
assert method != null;
+ if (infos.length > 1) {
+ return InspectionGadgetsBundle.message("object.instantiation.inside.equals.or.hashcode.problem.descriptor2", method.getName(), infos[1]);
+ }
return InspectionGadgetsBundle.message("object.instantiation.inside.equals.or.hashcode.problem.descriptor", method.getName());
}
@@ -50,9 +53,68 @@ public class ObjectInstantiationInEqualsHashCodeInspection extends BaseInspectio
return new ObjectInstantiationInEqualsHashCodeVisitor();
}
- // todo check boxing too
private static class ObjectInstantiationInEqualsHashCodeVisitor extends BaseInspectionVisitor {
+ @Override
+ public void visitExpression(PsiExpression expression) {
+ if (!ExpressionUtils.isAutoBoxed(expression)) {
+ return;
+ }
+ registerError(expression, expression, "autoboxing");
+ }
+
+ @Override
+ public void visitForeachStatement(PsiForeachStatement statement) {
+ final PsiExpression iteratedValue = statement.getIteratedValue();
+ if (iteratedValue == null || iteratedValue.getType() instanceof PsiArrayType) {
+ return;
+ }
+ registerError(iteratedValue, iteratedValue, "iterator");
+ }
+
+ @Override
+ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
+ final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+ final PsiMethod method = expression.resolveMethod();
+ if (method == null) {
+ return;
+ }
+ if (method.isVarArgs()) {
+ registerError(expression, expression, "varargs call");
+ }
+ else {
+ final String name = methodExpression.getReferenceName();
+ if (!"valueOf".equals(name)) {
+ return;
+ }
+ final PsiExpressionList argumentList = expression.getArgumentList();
+ final PsiExpression[] expressions = argumentList.getExpressions();
+ if (expressions.length != 1) {
+ return;
+ }
+ final PsiClass aClass = method.getContainingClass();
+ if (aClass == null) {
+ return;
+ }
+ final String qualifiedName = aClass.getQualifiedName();
+ if (!CommonClassNames.JAVA_LANG_SHORT.equals(qualifiedName) && !CommonClassNames.JAVA_LANG_INTEGER.equals(qualifiedName) &&
+ !CommonClassNames.JAVA_LANG_LONG.equals(qualifiedName) && !CommonClassNames.JAVA_LANG_DOUBLE.equals(qualifiedName) &&
+ !CommonClassNames.JAVA_LANG_FLOAT.equals(qualifiedName) && !CommonClassNames.JAVA_LANG_CHARACTER.equals(qualifiedName)) {
+ return;
+ }
+ registerError(expression, expression);
+ }
+ }
+
+ @Override
+ public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression) {
+ if (!(expression.getParent() instanceof PsiVariable)) {
+ // new expressions are already reported.
+ return;
+ }
+ registerError(expression, expression);
+ }
+
@Override
public void visitPolyadicExpression(PsiPolyadicExpression expression) {
super.visitPolyadicExpression(expression);
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ObjectInstantiationInEqualsHashCode.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ObjectInstantiationInEqualsHashCode.html
index 8361d39e41ce..75b171119f68 100644
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ObjectInstantiationInEqualsHashCode.html
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ObjectInstantiationInEqualsHashCode.html
@@ -2,7 +2,8 @@