summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets')
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml4
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java53
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java81
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java2
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java97
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java86
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java27
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java4
-rw-r--r--plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html8
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticImport.after.java (renamed from plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticIport.after.java)0
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java12
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java12
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java1
-rw-r--r--plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml84
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java26
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java3
-rw-r--r--plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java30
17 files changed, 202 insertions, 328 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
index a9bfaa130c66..2b47e3a3c33d 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
@@ -394,10 +394,6 @@
<localInspection language="JAVA" shortName="AnonymousInnerClass" bundle="com.siyeh.InspectionGadgetsBundle" key="anonymous.inner.class.display.name"
groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure" enabledByDefault="false"
level="WARNING" implementationClass="com.siyeh.ig.classlayout.AnonymousInnerClassInspection"/>
- <localInspection language="JAVA" suppressId="ClassWithoutPackageStatement" shortName="ClassInTopLevelPackage" bundle="com.siyeh.InspectionGadgetsBundle"
- key="class.in.top.level.package.display.name" groupBundle="messages.InspectionsBundle"
- groupKey="group.names.class.structure" enabledByDefault="false" level="WARNING"
- implementationClass="com.siyeh.ig.classlayout.ClassInTopLevelPackageInspection"/>
<localInspection language="JAVA" suppressId="NonStaticInitializer" shortName="ClassInitializer" bundle="com.siyeh.InspectionGadgetsBundle"
key="class.initializer.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.class.structure"
enabledByDefault="false" level="WARNING" implementationClass="com.siyeh.ig.classlayout.ClassInitializerInspection"/>
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java
index fc0a72508c81..090280531a78 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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.
@@ -60,20 +60,51 @@ public class EqualsBetweenInconvertibleTypesInspection
extends BaseInspectionVisitor {
@Override
- public void visitMethodCallExpression(
- @NotNull PsiMethodCallExpression expression) {
+ public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
- if (!MethodCallUtils.isEqualsCall(expression)) {
- return;
- }
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+ final boolean staticEqualsCall;
+ if (MethodCallUtils.isEqualsCall(expression)) {
+ staticEqualsCall = false;
+ }
+ else {
+ final String name = methodExpression.getReferenceName();
+ if (!"equals".equals(name) && !"equal".equals(name)) {
+ return;
+ }
+ final PsiMethod method = expression.resolveMethod();
+ if (method == null) {
+ return;
+ }
+ final PsiClass aClass = method.getContainingClass();
+ if (aClass == null) {
+ return;
+ }
+ final String qualifiedName = aClass.getQualifiedName();
+ if (!"java.util.Objects".equals(qualifiedName) && !"com.google.common.base.Objects".equals(qualifiedName)) {
+ return;
+ }
+ staticEqualsCall = true;
+ }
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
- if (arguments.length != 1) {
- return;
+ final PsiExpression expression1;
+ final PsiExpression expression2;
+ if (staticEqualsCall) {
+ if (arguments.length != 2) {
+ return;
+ }
+ expression1 = arguments[0];
+ expression2 = arguments[1];
}
- final PsiExpression expression1 = arguments[0];
- final PsiExpression expression2 = methodExpression.getQualifierExpression();
+ else {
+ if (arguments.length != 1) {
+ return;
+ }
+ expression1 = arguments[0];
+ expression2 = methodExpression.getQualifierExpression();
+ }
+
final PsiType comparisonType;
if (expression2 == null) {
final PsiClass aClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
@@ -94,7 +125,7 @@ public class EqualsBetweenInconvertibleTypesInspection
final PsiType comparedTypeErasure = TypeConversionUtil.erasure(comparedType);
final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(comparisonType);
if (comparedTypeErasure == null || comparisonTypeErasure == null ||
- TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) {
+ TypeConversionUtil.areTypesConvertible(comparedType, comparisonType)) {
return;
}
registerMethodCallError(expression, comparedType, comparisonType);
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java
deleted file mode 100644
index dec9e2e662d2..000000000000
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspectionBase.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.classlayout;
-
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiJavaFile;
-import com.intellij.psi.util.FileTypeUtils;
-import com.siyeh.InspectionGadgetsBundle;
-import com.siyeh.ig.BaseInspection;
-import com.siyeh.ig.BaseInspectionVisitor;
-import com.siyeh.ig.psiutils.ClassUtils;
-import org.jetbrains.annotations.NotNull;
-
-public class ClassInTopLevelPackageInspectionBase extends BaseInspection {
- @Override
- @NotNull
- public String getID() {
- return "ClassWithoutPackageStatement";
- }
-
- @Override
- @NotNull
- public String getDisplayName() {
- return InspectionGadgetsBundle.message(
- "class.in.top.level.package.display.name");
- }
-
- @Override
- @NotNull
- protected String buildErrorString(Object... infos) {
- return InspectionGadgetsBundle.message(
- "class.in.top.level.package.problem.descriptor");
- }
-
- @Override
- protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
- return true;
- }
-
- @Override
- public BaseInspectionVisitor buildVisitor() {
- return new ClassInTopLevelPackageVisitor();
- }
-
- private static class ClassInTopLevelPackageVisitor
- extends BaseInspectionVisitor {
-
- @Override
- public void visitClass(@NotNull PsiClass aClass) {
- // no call to super, so that it doesn't drill down to inner classes
- if (FileTypeUtils.isInServerPageFile(aClass)) {
- return;
- }
- if (ClassUtils.isInnerClass(aClass)) {
- return;
- }
- final PsiFile file = aClass.getContainingFile();
- if (!(file instanceof PsiJavaFile)) {
- return;
- }
- if (((PsiJavaFile)file).getPackageStatement() != null) {
- return;
- }
- registerClassError(aClass);
- }
- }
-}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java
index e4f77e0fbea9..b9f43f708b77 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/classlayout/InterfaceMayBeAnnotatedFunctionalInspection.java
@@ -75,7 +75,7 @@ public class InterfaceMayBeAnnotatedFunctionalInspection extends BaseInspection
if (LambdaHighlightingUtil.checkInterfaceFunctional(aClass) != null) {
return;
}
- final List<MethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass);
+ final List<HierarchicalMethodSignature> candidates = LambdaUtil.findFunctionCandidates(aClass);
if (candidates == null || candidates.size() != 1) {
return;
}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java
index 6b2f34b1aa47..bebf5a559d15 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/PointlessArithmeticExpressionInspection.java
@@ -20,8 +20,8 @@ import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.ConstantExpressionUtil;
import com.intellij.psi.util.PsiUtil;
+import com.intellij.psi.util.PsiUtilCore;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -116,20 +116,19 @@ public class PointlessArithmeticExpressionInspection
}
else if (tokenType.equals(JavaTokenType.ASTERISK) && isZero(operand) ||
tokenType.equals(JavaTokenType.PERC) && (isOne(operand) || EquivalenceChecker.expressionsAreEquivalent(previousOperand, operand))) {
- return PsiType.LONG.equals(polyadicExpression.getType()) ? "0L" : "0";
- }
- else if (tokenType.equals(JavaTokenType.LE) || tokenType.equals(JavaTokenType.GE) ||
- tokenType.equals(JavaTokenType.LT) || tokenType.equals(JavaTokenType.GT)) {
- return (tokenType.equals(JavaTokenType.LT) || tokenType.equals(JavaTokenType.GT)) ? "false" : "true";
+ fromTarget = operands[0];
+ untilTarget = operands[length - 1];
+ replacement = PsiType.LONG.equals(polyadicExpression.getType()) ? "0L" : "0";
+ break;
}
previousOperand = operand;
}
- return buildReplacementExpression(polyadicExpression, fromTarget, untilTarget, replacement).trim();
+ return getText(polyadicExpression, fromTarget, untilTarget, replacement).trim();
}
- public static String buildReplacementExpression(PsiPolyadicExpression expression, PsiElement fromTarget, PsiElement untilTarget,
- String replacement) {
+ public static String getText(PsiPolyadicExpression expression, PsiElement fromTarget, PsiElement untilTarget,
+ @NotNull @NonNls String replacement) {
final StringBuilder result = new StringBuilder();
boolean stop = false;
for (PsiElement child : expression.getChildren()) {
@@ -198,13 +197,10 @@ public class PointlessArithmeticExpressionInspection
if (!arithmeticTokens.contains(expression.getOperationTokenType())) {
return;
}
- if (ExpressionUtils.hasStringType(expression)) {
+ if (ExpressionUtils.hasStringType(expression) || PsiUtilCore.hasErrorElementChild(expression)) {
return;
}
final PsiExpression[] operands = expression.getOperands();
- if (operands.length < 2) {
- return;
- }
final IElementType tokenType = expression.getOperationTokenType();
final boolean isPointless;
if (tokenType.equals(JavaTokenType.PLUS)) {
@@ -222,14 +218,6 @@ public class PointlessArithmeticExpressionInspection
else if (tokenType.equals(JavaTokenType.PERC)) {
isPointless = modExpressionIsPointless(operands);
}
- else if (tokenType.equals(JavaTokenType.LE) ||
- tokenType.equals(JavaTokenType.GE) ||
- tokenType.equals(JavaTokenType.GT) ||
- tokenType.equals(JavaTokenType.LT)) {
- final PsiExpression lhs = operands[0];
- final PsiExpression rhs = operands[1];
- isPointless = comparisonExpressionIsPointless(lhs, rhs, tokenType);
- }
else {
isPointless = false;
}
@@ -292,45 +280,6 @@ public class PointlessArithmeticExpressionInspection
}
return false;
}
-
- private boolean comparisonExpressionIsPointless(
- PsiExpression lhs, PsiExpression rhs, IElementType comparison) {
- if (PsiType.INT.equals(lhs.getType()) &&
- PsiType.INT.equals(rhs.getType())) {
- return intComparisonIsPointless(lhs, rhs, comparison);
- }
- else if (PsiType.LONG.equals(lhs.getType()) &&
- PsiType.LONG.equals(rhs.getType())) {
- return longComparisonIsPointless(lhs, rhs, comparison);
- }
- return false;
- }
-
- private boolean intComparisonIsPointless(
- PsiExpression lhs, PsiExpression rhs, IElementType comparison) {
- if (isMaxInt(lhs) || isMinInt(rhs)) {
- return JavaTokenType.GE.equals(comparison) ||
- JavaTokenType.LT.equals(comparison);
- }
- if (isMinInt(lhs) || isMaxInt(rhs)) {
- return JavaTokenType.LE.equals(comparison) ||
- JavaTokenType.GT.equals(comparison);
- }
- return false;
- }
-
- private boolean longComparisonIsPointless(
- PsiExpression lhs, PsiExpression rhs, IElementType comparison) {
- if (isMaxLong(lhs) || isMinLong(rhs)) {
- return JavaTokenType.GE.equals(comparison) ||
- JavaTokenType.LT.equals(comparison);
- }
- if (isMinLong(lhs) || isMaxLong(rhs)) {
- return JavaTokenType.LE.equals(comparison) ||
- JavaTokenType.GT.equals(comparison);
- }
- return false;
- }
}
boolean isZero(PsiExpression expression) {
@@ -346,32 +295,4 @@ public class PointlessArithmeticExpressionInspection
}
return ExpressionUtils.isOne(expression);
}
-
- private static boolean isMinInt(PsiExpression expression) {
- final Integer value = (Integer)
- ConstantExpressionUtil.computeCastTo(
- expression, PsiType.INT);
- return value != null && value.intValue() == Integer.MIN_VALUE;
- }
-
- private static boolean isMaxInt(PsiExpression expression) {
- final Integer value = (Integer)
- ConstantExpressionUtil.computeCastTo(
- expression, PsiType.INT);
- return value != null && value.intValue() == Integer.MAX_VALUE;
- }
-
- private static boolean isMinLong(PsiExpression expression) {
- final Long value = (Long)
- ConstantExpressionUtil.computeCastTo(
- expression, PsiType.LONG);
- return value != null && value.longValue() == Long.MIN_VALUE;
- }
-
- private static boolean isMaxLong(PsiExpression expression) {
- final Long value = (Long)
- ConstantExpressionUtil.computeCastTo(
- expression, PsiType.LONG);
- return value != null && value.longValue() == Long.MAX_VALUE;
- }
} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java
index ebd8449909e6..69c2bad8242b 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringEqualsEmptyStringInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
+ * Copyright 2003-2014 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,8 @@ package com.siyeh.ig.performance;
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.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.HardcodedMethodConstants;
@@ -27,6 +29,7 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.PsiReplacementUtil;
import com.siyeh.ig.psiutils.BoolUtils;
+import com.siyeh.ig.psiutils.EquivalenceChecker;
import com.siyeh.ig.psiutils.ExpressionUtils;
import com.siyeh.ig.psiutils.TypeUtils;
import org.jetbrains.annotations.NonNls;
@@ -97,19 +100,19 @@ public class StringEqualsEmptyStringInspection extends BaseInspection {
}
final PsiExpression qualifier = expression.getQualifierExpression();
final PsiExpression argument = arguments[0];
- final String variableText;
+ final PsiExpression checkedExpression;
final boolean addNullCheck;
if (ExpressionUtils.isEmptyStringLiteral(argument)) {
- variableText = getRemainingText(qualifier);
+ checkedExpression = getCheckedExpression(qualifier);
addNullCheck = false;
}
else {
- variableText = getRemainingText(argument);
- addNullCheck = true;
+ checkedExpression = getCheckedExpression(argument);
+ addNullCheck = !isCheckedForNull(checkedExpression);
}
- StringBuilder newExpression;
+ final StringBuilder newExpression;
if (addNullCheck) {
- newExpression = new StringBuilder(variableText);
+ newExpression = new StringBuilder(checkedExpression.getText());
newExpression.append("!=null&&");
} else {
newExpression = new StringBuilder("");
@@ -121,38 +124,81 @@ public class StringEqualsEmptyStringInspection extends BaseInspection {
if (BoolUtils.isNegation(parentExpression)) {
expressionToReplace = parentExpression;
if (useIsEmpty) {
- newExpression.append('!').append(variableText).append(".isEmpty()");
+ newExpression.append('!').append(checkedExpression.getText()).append(".isEmpty()");
}
else {
- newExpression.append(variableText).append(".length()!=0");
+ newExpression.append(checkedExpression.getText()).append(".length()!=0");
}
}
else {
expressionToReplace = call;
if (useIsEmpty) {
- newExpression.append(variableText).append(".isEmpty()");
+ newExpression.append(checkedExpression.getText()).append(".isEmpty()");
}
else {
- newExpression.append(variableText).append(".length()==0");
+ newExpression.append(checkedExpression.getText()).append(".length()==0");
}
}
}
else {
expressionToReplace = call;
if (useIsEmpty) {
- newExpression.append(variableText).append(".isEmpty()");
+ newExpression.append(checkedExpression.getText()).append(".isEmpty()");
}
else {
- newExpression.append(variableText).append(".length()==0");
+ newExpression.append(checkedExpression.getText()).append(".length()==0");
}
}
PsiReplacementUtil.replaceExpression(expressionToReplace, newExpression.toString());
}
- private String getRemainingText(PsiExpression expression) {
- if (useIsEmpty ||
- !(expression instanceof PsiMethodCallExpression)) {
- return expression.getText();
+ private static boolean isCheckedForNull(PsiExpression expression) {
+ final PsiPolyadicExpression polyadicExpression =
+ PsiTreeUtil.getParentOfType(expression, PsiPolyadicExpression.class, true, PsiStatement.class, PsiVariable.class);
+ if (polyadicExpression == null) {
+ return false;
+ }
+ final IElementType tokenType = polyadicExpression.getOperationTokenType();
+ for (PsiExpression operand : polyadicExpression.getOperands()) {
+ if (PsiTreeUtil.isAncestor(operand, expression, true)) {
+ return false;
+ }
+ if (!(operand instanceof PsiBinaryExpression)) {
+ continue;
+ }
+ final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)operand;
+ final IElementType operationTokenType = binaryExpression.getOperationTokenType();
+ if (JavaTokenType.ANDAND.equals(tokenType)) {
+ if (!JavaTokenType.NE.equals(operationTokenType)) {
+ continue;
+ }
+ }
+ else if (JavaTokenType.OROR.equals(tokenType)) {
+ if (!JavaTokenType.EQEQ.equals(operationTokenType)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
+ final PsiExpression lhs = binaryExpression.getLOperand();
+ final PsiExpression rhs = binaryExpression.getROperand();
+ if (rhs == null) {
+ continue;
+ }
+ if (PsiType.NULL.equals(lhs.getType()) && EquivalenceChecker.expressionsAreEquivalent(expression, rhs)) {
+ return true;
+ }
+ else if (PsiType.NULL.equals(rhs.getType()) && EquivalenceChecker.expressionsAreEquivalent(expression, lhs)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private PsiExpression getCheckedExpression(PsiExpression expression) {
+ if (useIsEmpty || !(expression instanceof PsiMethodCallExpression)) {
+ return expression;
}
// to replace stringBuffer.toString().equals("") with
// stringBuffer.length() == 0
@@ -161,15 +207,15 @@ public class StringEqualsEmptyStringInspection extends BaseInspection {
final String referenceName = methodExpression.getReferenceName();
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
if (qualifierExpression == null) {
- return expression.getText();
+ return expression;
}
final PsiType type = qualifierExpression.getType();
if (HardcodedMethodConstants.TO_STRING.equals(referenceName) && type != null && (type.equalsToText(
CommonClassNames.JAVA_LANG_STRING_BUFFER) || type.equalsToText(CommonClassNames.JAVA_LANG_STRING_BUILDER))) {
- return qualifierExpression.getText();
+ return qualifierExpression;
}
else {
- return expression.getText();
+ return expression;
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java
deleted file mode 100644
index 828b4c68d43f..000000000000
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/ClassInTopLevelPackageInspection.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2003-2011 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.
- * 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.classlayout;
-
-import com.siyeh.ig.InspectionGadgetsFix;
-import com.siyeh.ig.fixes.MoveClassFix;
-
-public class ClassInTopLevelPackageInspection extends ClassInTopLevelPackageInspectionBase {
-
- @Override
- protected InspectionGadgetsFix buildFix(Object... infos) {
- return new MoveClassFix();
- }
-} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java
index 8f823f019770..bbd0f1491925 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/ProblematicWhitespaceInspection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -141,7 +141,7 @@ public class ProblematicWhitespaceInspection extends BaseInspection {
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE);
return;
}
- else {
+ else if (!spaceSeen) {
final int currentIndent = Math.max(0, j);
if (currentIndent != previousLineIndent) {
registerError(file, file.getName(), Boolean.valueOf(isOnTheFly()), Boolean.TRUE);
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html
deleted file mode 100644
index c6263f25c4d5..000000000000
--- a/plugins/InspectionGadgets/src/inspectionDescriptions/ClassInTopLevelPackage.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<html>
-<body>
-Reports any classes which do not contain package declarations.
-<!-- tooltip end -->
-<p>
-
-</body>
-</html> \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticIport.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticImport.after.java
index f026afe3785e..f026afe3785e 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticIport.after.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/junit/useOfObsoleteAssert/singleStaticImport.after.java
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java
new file mode 100644
index 000000000000..7277bd021670
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.after.java
@@ -0,0 +1,12 @@
+package com.siyeh.igfixes.performance.replace_with_isempty;
+
+public class NullCheckAlreadyPresent {
+
+ String[] splitProperties = {"1","2"};
+
+ public void someAction() {
+ if (splitProperties[1] != null && splitProperties[1].isEmpty()) {
+ System.out.println("");
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java
new file mode 100644
index 000000000000..e91b650758e2
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/replace_with_isempty/NullCheckAlreadyPresent.java
@@ -0,0 +1,12 @@
+package com.siyeh.igfixes.performance.replace_with_isempty;
+
+public class NullCheckAlreadyPresent {
+
+ String[] splitProperties = {"1","2"};
+
+ public void someAction() {
+ if (splitProperties[1] != null && "".<caret>equals(splitProperties[1])) {
+ System.out.println("");
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
index d7577b1c9c79..019805adcf17 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/PointlessArithmeticExpression.java
@@ -123,4 +123,5 @@ class Expanded {{
System.out.println(u * 1);
long g = 8L / 8L;
long h = 9L * 0L;
+ int a = 8 * 0 * 8 * ; // don't warn
}} \ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml
index 58e0898bdcdd..f6af12237ea0 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/pointless_arithmetic_expression/expected.xml
@@ -38,90 +38,6 @@
<problem>
<file>PointlessArithmeticExpression.java</file>
- <line>30</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;k&lt;=Integer.MAX_VALUE&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>34</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;k&gt;=Integer.MIN_VALUE&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>38</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;k&gt;Integer.MAX_VALUE&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>42</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;k&lt;Integer.MIN_VALUE&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>46</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;Integer.MAX_VALUE &gt;= k&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>50</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;Integer.MIN_VALUE &lt;= k&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>54</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;Integer.MAX_VALUE &lt; k&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>58</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;Integer.MIN_VALUE &gt; k&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>70</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i &gt; Integer.MAX_VALUE&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>76</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i &lt;= Integer.MAX_VALUE&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>80</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i &gt;= Integer.MIN_VALUE&lt;/code&gt; can be replaced with 'true' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
- <line>83</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
- <description>&lt;code&gt;i &lt; Integer.MIN_VALUE&lt;/code&gt; can be replaced with 'false' #loc</description>
- </problem>
-
- <problem>
- <file>PointlessArithmeticExpression.java</file>
<line>93</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Pointless arithmetic expression</problem_class>
<description>&lt;code&gt;i / i&lt;/code&gt; can be replaced with '1' #loc</description>
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java
index 3168d9ec5b0b..92e72bb81a55 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/EqualsBetweenInconvertibleTypesInspectionTest.java
@@ -39,6 +39,32 @@ public class EqualsBetweenInconvertibleTypesInspectionTest extends LightInspecti
"}");
}
+ public void testJavaUtilObjectsEquals() {
+ doStatementTest("java.util.Objects./*'equals()' between objects of inconvertible types 'Integer' and 'String'*/equals/**/(Integer.valueOf(1), \"string\");");
+ }
+
+ public void testComGoogleCommonBaseObjects() {
+ doStatementTest("com.google.common.base.Objects./*'equal()' between objects of inconvertible types 'Integer' and 'String'*/equal/**/(Integer.valueOf(1), \"string\");");
+ }
+
+ @Override
+ protected String[] getEnvironmentClasses() {
+ return new String[] {
+ "package java.util;" +
+ "public final class Objects {" +
+ " public static boolean equals(Object a, Object b) {" +
+ " return (a == b) || (a != null && a.equals(b));" +
+ " }" +
+ "}",
+ "package com.google.common.base;" +
+ "public final class Objects {" +
+ " public static boolean equal(Object a, Object b) {" +
+ " return true;" +
+ " }" +
+ "}"
+ };
+ }
+
@Override
protected InspectionProfileEntry getInspection() {
return new EqualsBetweenInconvertibleTypesInspection();
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java
index a42fccbda5a6..6bd1cefe6320 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/performance/StringEqualsEmptyStringFixTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Bas Leijdekkers
+ * Copyright 2012-2014 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,4 +31,5 @@ public class StringEqualsEmptyStringFixTest extends IGQuickFixesTestCase {
public void testSimple() { doTest(); }
public void testNullCheck() { doTest(); }
+ public void testNullCheckAlreadyPresent() { doTest(); }
}
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java
index c0e062c6d79b..3cfc26b152a2 100644
--- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/style/ProblematicWhitespaceInspectionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@@ -69,6 +69,34 @@ public class ProblematicWhitespaceInspectionTest extends LightInspectionTestCase
"}\n/**/");
}
+ public void testSmartTabsInFile2() {
+ final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
+ final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(JavaFileType.INSTANCE);
+ options.USE_TAB_CHARACTER = true;
+ options.SMART_TABS = true;
+ doTest("class X {\n" +
+ "\tvoid aaa(boolean a, boolean b, boolean c) {\n" +
+ "\t\taaa(true,\n" +
+ "\t\t true,\n" +
+ "\t\t true);\n" +
+ "\t}\n" +
+ "}\n");
+ }
+
+ public void testSmartTabsInFile3() {
+ final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
+ final CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptions(JavaFileType.INSTANCE);
+ options.USE_TAB_CHARACTER = true;
+ options.SMART_TABS = true;
+ doTest("/*File 'X.java' uses spaces for indentation*/class X {\n" +
+ "\tvoid aaa(boolean a, boolean b, boolean c) {\n" +
+ "\t\taaa(true,\n" +
+ "\t \t true,\n" +
+ "\t\t true);\n" +
+ "\t}\n" +
+ "}\n/**/");
+ }
+
@Override
protected InspectionProfileEntry getInspection() {
return new ProblematicWhitespaceInspection();