diff --git a/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr b/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr
index 3e59c5d6d627..66a01920d532 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr
+++ b/plugins/InspectionGadgets/InspectionGadgetsSVN.ipr
@@ -192,7 +192,7 @@
-
+
diff --git a/plugins/InspectionGadgets/Leftovers.txt b/plugins/InspectionGadgets/Leftovers.txt
index 29d58e8f277b..3957291d9625 100644
--- a/plugins/InspectionGadgets/Leftovers.txt
+++ b/plugins/InspectionGadgets/Leftovers.txt
@@ -25,12 +25,13 @@
Fix for non-static initializer
Check IDs for all inspections
Better handling of unnecessary block
+ Encapsulatable use of field
+ While loop replaceable by for-each
+ Acceptable name for type (Exceptions always e, Iterators always i)
Expand "Trivial If" inspection to cover same cases as the intention
Flag inspections with default on-off and default warning level
- More detectors and quickfixes for "Simplifiable JUnit Assertion"
Inheritance as type def (change the EmptyClass inspection)
Fix the "variable accessed in synchronized and unsynchronized contexts" to deal
with unsynchronized private methods called only from synchronized contexts
SerialVersionUID calculation
- Fix list table alignment
-
+ Fix list table alignment
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ConcreteClassUtil.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ConcreteClassUtil.java
index 8849a2af9358..eaabe417c0f3 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ConcreteClassUtil.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ConcreteClassUtil.java
@@ -1,9 +1,7 @@
package com.siyeh.ig.abstraction;
-import com.intellij.psi.PsiType;
-import com.intellij.psi.PsiClassType;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiTypeElement;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
import com.siyeh.ig.psiutils.LibraryUtil;
public class ConcreteClassUtil {
@@ -33,6 +31,10 @@ public class ConcreteClassUtil {
if (aClass.isInterface() || aClass.isEnum()|| aClass.isAnnotationType()) {
return false;
}
+ if(PsiTreeUtil.getParentOfType(aClass, PsiTypeParameterList.class)!=null)
+ {
+ return false;
+ }
if (LibraryUtil.classIsInLibrary(aClass)) {
return false;
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ParameterOfConcreteClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ParameterOfConcreteClassInspection.java
index 4d6031c9779b..88934febe7ec 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ParameterOfConcreteClassInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/abstraction/ParameterOfConcreteClassInspection.java
@@ -24,11 +24,11 @@ public class ParameterOfConcreteClassInspection extends MethodInspection {
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
- return new LocalVariableOfConcreteClassVisitor(this, inspectionManager, onTheFly);
+ return new ParameterOfConcreteClassVisitor(this, inspectionManager, onTheFly);
}
- private static class LocalVariableOfConcreteClassVisitor extends BaseInspectionVisitor {
- private LocalVariableOfConcreteClassVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
+ private static class ParameterOfConcreteClassVisitor extends BaseInspectionVisitor {
+ private ParameterOfConcreteClassVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
super(inspection, inspectionManager, isOnTheFly);
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java
index b6a9e1c056c3..ae8506af3360 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionQueryCalledVisitor.java
@@ -23,6 +23,12 @@ public class CollectionQueryCalledVisitor extends PsiRecursiveElementVisitor {
queryNames.add("entrySet");
queryNames.add("keySet");
queryNames.add("values");
+ queryNames.add("keys");
+ queryNames.add("elements");
+ queryNames.add("subList");
+ queryNames.add("copyInto");
+ queryNames.add("lastElement");
+ queryNames.add("firstElement");
}
private boolean queried = false;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionUpdateCalledVisitor.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionUpdateCalledVisitor.java
index 674caa1351a1..4c1d2cbed95e 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionUpdateCalledVisitor.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/CollectionUpdateCalledVisitor.java
@@ -18,6 +18,14 @@ public class CollectionUpdateCalledVisitor extends PsiRecursiveElementVisitor {
updateNames.add("retainAll");
updateNames.add("putAll");
updateNames.add("clear");
+ updateNames.add("addElement");
+ updateNames.add("removeAllElements");
+ updateNames.add("trimToSize");
+ updateNames.add("removeElementAt");
+ updateNames.add("removeRange");
+ updateNames.add("insertElementAt");
+ updateNames.add("setElementAt");
+ updateNames.add("removeRange");
}
private boolean updated = false;
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java
index ca08ceb4d6c3..b34245e82637 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java
@@ -2,11 +2,14 @@ package com.siyeh.ig.bugs;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.ProblemDescriptor;
-import com.intellij.psi.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
+
import com.siyeh.ig.*;
+import com.siyeh.ig.psiutils.ClassUtils;
public class StaticCallOnSubclassInspection extends ExpressionInspection {
private final StaticCallOnSubclassFix fix = new StaticCallOnSubclassFix();
@@ -46,9 +49,7 @@ public class StaticCallOnSubclassInspection extends ExpressionInspection {
final String methodName = expression.getReferenceName();
final PsiClass containingClass = method.getContainingClass();
final PsiExpressionList argumentList = call.getArgumentList();
- final PsiExpression[] args = argumentList.getExpressions();
- final String argText = args[0].getText();
- replaceExpression(project, call, containingClass.getName() + '.' + methodName + "(" + argText + ")");
+ replaceExpression(project, call, containingClass.getName() + '.' + methodName + argumentList.getText() );
}
}
@@ -85,8 +86,13 @@ public class StaticCallOnSubclassInspection extends ExpressionInspection {
if (declaringClass.equals(referencedClass)) {
return;
}
- registerMethodCallError(call);
+ final PsiClass containingClass = (PsiClass) PsiTreeUtil.getParentOfType(call, PsiClass.class);
+ if(!ClassUtils.isClassVisibleFromClass(containingClass, declaringClass))
+ {
+ return;
+ }
+ registerMethodCallError(call);
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java
index 3742774fa2e8..3e10f0e01ff3 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/EmptyCatchBlockInspection.java
@@ -102,7 +102,8 @@ public class EmptyCatchBlockInspection extends StatementInspection {
}
return true;
} else {
- return block.getStatements().length == 0;
+ final PsiStatement[] statements = block.getStatements();
+ return statements == null || statements.length == 0;
}
}
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
index 1f238a6f16e1..5186c5a89116 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/junit/SimplifiableJUnitAssertionInspection.java
@@ -10,36 +10,49 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.siyeh.ig.*;
import com.siyeh.ig.psiutils.ClassUtils;
-public class SimplifiableJUnitAssertionInspection extends ExpressionInspection {
+public class SimplifiableJUnitAssertionInspection extends ExpressionInspection{
private SimplifyJUnitAssertFix fix = new SimplifyJUnitAssertFix();
-
- public String getDisplayName() {
+ public String getDisplayName(){
return "Simplifiable JUnit assertion";
}
- public String getGroupDisplayName() {
+ public String getGroupDisplayName(){
return GroupNames.JUNIT_GROUP_NAME;
}
- public String buildErrorString(PsiElement location) {
- return "#ref() can be simplified to assertEquals() #loc";
+ public String buildErrorString(PsiElement location){
+ return "#ref() can be simplified #loc";
}
- public InspectionGadgetsFix buildFix(PsiElement location) {
+ public InspectionGadgetsFix buildFix(PsiElement location){
return fix;
}
- private static class SimplifyJUnitAssertFix extends InspectionGadgetsFix {
- public String getName() {
+ private static class SimplifyJUnitAssertFix extends InspectionGadgetsFix{
+ public String getName(){
return "Simplify assertion";
}
public void applyFix(Project project, ProblemDescriptor descriptor) {
if (ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(new VirtualFile[]{descriptor.getPsiElement().getContainingFile().getVirtualFile()}).hasReadonlyFiles()) return;
+
final PsiElement methodNameIdentifier = descriptor.getPsiElement();
- final PsiMethodCallExpression callExpression = (PsiMethodCallExpression) methodNameIdentifier.getParent().getParent();
- final PsiReferenceExpression methodExpression = callExpression.getMethodExpression();
+ final PsiMethodCallExpression callExpression =
+ (PsiMethodCallExpression) methodNameIdentifier.getParent()
+ .getParent();
+ if(isAssertTrueThatCouldBeAssertEquality(callExpression)){
+ replaceAssertTrueWithAssertEquals(callExpression, project);
+ }
+ if(isAssertEqualsThatCouldBeAssertLiteral(callExpression)){
+ replaceAssertEqualsWithAssertLiteral(callExpression, project);
+ }
+ }
+
+ private void replaceAssertTrueWithAssertEquals(PsiMethodCallExpression callExpression,
+ Project project){
+ final PsiReferenceExpression methodExpression =
+ callExpression.getMethodExpression();
final PsiMethod method = (PsiMethod) methodExpression.resolve();
final PsiParameterList paramList = method.getParameterList();
@@ -48,17 +61,19 @@ public class SimplifiableJUnitAssertionInspection extends ExpressionInspection {
final PsiManager psiManager = callExpression.getManager();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
- final PsiType stringType = PsiType.getJavaLangString(psiManager, scope);
+ final PsiType stringType =
+ PsiType.getJavaLangString(psiManager, scope);
final PsiType paramType1 = parameters[0].getType();
- final PsiExpressionList argumentList = callExpression.getArgumentList();
+ final PsiExpressionList argumentList =
+ callExpression.getArgumentList();
final PsiExpression[] args = argumentList.getExpressions();
final int testPosition;
final PsiExpression message;
- if (paramType1.equals(stringType) && parameters.length >= 2) {
+ if(paramType1.equals(stringType) && parameters.length >= 2){
testPosition = 1;
message = args[0];
- } else {
+ } else{
testPosition = 0;
message = null;
}
@@ -66,183 +81,329 @@ public class SimplifiableJUnitAssertionInspection extends ExpressionInspection {
PsiExpression lhs = null;
PsiExpression rhs = null;
- if (testArg instanceof PsiBinaryExpression) {
+ if(testArg instanceof PsiBinaryExpression){
lhs = ((PsiBinaryExpression) testArg).getLOperand();
rhs = ((PsiBinaryExpression) testArg).getROperand();
- } else if (testArg instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression call = (PsiMethodCallExpression) testArg;
- final PsiReferenceExpression equalityMethodExpression = call.getMethodExpression();
- final PsiExpressionList equalityArgumentList = call.getArgumentList();
- final PsiExpression[] equalityArgs = equalityArgumentList.getExpressions();
+ } else if(testArg instanceof PsiMethodCallExpression){
+ final PsiMethodCallExpression call =
+ (PsiMethodCallExpression) testArg;
+ final PsiReferenceExpression equalityMethodExpression =
+ call.getMethodExpression();
+ final PsiExpressionList equalityArgumentList =
+ call.getArgumentList();
+ final PsiExpression[] equalityArgs =
+ equalityArgumentList.getExpressions();
rhs = equalityArgs[0];
lhs = equalityMethodExpression.getQualifierExpression();
}
if(!(lhs instanceof PsiLiteralExpression) &&
- rhs instanceof PsiLiteralExpression)
- {
+ rhs instanceof PsiLiteralExpression){
final PsiExpression temp = lhs;
lhs = rhs;
rhs = temp;
}
- final StringBuffer newExpression = new StringBuffer("assertEquals(");
- if(message!=null)
- {
+ final StringBuffer newExpression =
+ new StringBuffer("assertEquals(");
+ if(message != null){
newExpression.append(message.getText());
newExpression.append(',');
}
newExpression.append(lhs.getText());
newExpression.append(',');
newExpression.append(rhs.getText());
- if(isFloatingPoint(lhs) || isFloatingPoint(rhs))
- {
+ if(isFloatingPoint(lhs) || isFloatingPoint(rhs)){
newExpression.append(",0.0");
}
newExpression.append(')');
- replaceExpression(project, callExpression, newExpression.toString());
+ replaceExpression(project, callExpression,
+ newExpression.toString());
}
- private boolean isFloatingPoint(PsiExpression expression) {
- final PsiType type = expression.getType();
- return PsiType.FLOAT.equals(type)|| PsiType.DOUBLE.equals(type);
- }
-
- }
-
- public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
- return new MisorderedAssertEqualsParametersVisitor(this, inspectionManager, onTheFly);
- }
-
- private static class MisorderedAssertEqualsParametersVisitor extends BaseInspectionVisitor {
-
- private MisorderedAssertEqualsParametersVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
- super(inspection, inspectionManager, isOnTheFly);
- }
-
- public void visitMethodCallExpression(PsiMethodCallExpression expression) {
- super.visitMethodCallExpression(expression);
- if (!isAssertTrue(expression)) {
- return;
- }
- final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+ private void replaceAssertEqualsWithAssertLiteral(PsiMethodCallExpression callExpression,
+ Project project){
+ final PsiReferenceExpression methodExpression =
+ callExpression.getMethodExpression();
final PsiMethod method = (PsiMethod) methodExpression.resolve();
final PsiParameterList paramList = method.getParameterList();
- if (paramList == null) {
- return;
- }
final PsiParameter[] parameters = paramList.getParameters();
- final PsiManager psiManager = expression.getManager();
+ final PsiManager psiManager = callExpression.getManager();
- final Project project = psiManager.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
- final PsiType stringType = PsiType.getJavaLangString(psiManager, scope);
+ final PsiType stringType =
+ PsiType.getJavaLangString(psiManager, scope);
final PsiType paramType1 = parameters[0].getType();
- final int testPosition;
- if (paramType1.equals(stringType) && parameters.length > 1) {
- testPosition = 1;
- } else {
- testPosition = 0;
- }
- final PsiExpressionList argumentList = expression.getArgumentList();
- if (argumentList == null) {
- return;
- }
+ final PsiExpressionList argumentList =
+ callExpression.getArgumentList();
+
final PsiExpression[] args = argumentList.getExpressions();
- final PsiExpression testArg = args[testPosition];
- if (testArg == null) {
- return;
+ final int firstTestPosition;
+ final int secondTestPosition;
+ final PsiExpression message;
+ if(paramType1.equals(stringType) && parameters.length >= 3){
+ firstTestPosition = 1;
+ secondTestPosition = 2;
+ message = args[0];
+ } else{
+ firstTestPosition = 0;
+ secondTestPosition = 1;
+ message = null;
+
}
- if (!isEqualityComparison(testArg)) {
- return;
+ final PsiExpression firstTestArg = args[firstTestPosition];
+ final PsiExpression secondTestArg = args[secondTestPosition];
+ final String literalValue;
+ final String compareValue;
+ if(isSimpleLiteral(firstTestArg)){
+ literalValue = firstTestArg.getText();
+ compareValue = secondTestArg.getText();
+ } else{
+ literalValue = secondTestArg.getText();
+ compareValue = firstTestArg.getText();
}
- registerMethodCallError(expression);
+ final String uppercaseLiteralValue=
+ Character.toUpperCase( literalValue.charAt(0)) +literalValue.substring(1);
+ final StringBuffer newExpression =
+ new StringBuffer("assert"+ uppercaseLiteralValue + '(');
+ if(message != null){
+ newExpression.append(message.getText());
+ newExpression.append(',');
+ }
+ newExpression.append(compareValue);
+ newExpression.append(')');
+ replaceExpression(project, callExpression,
+ newExpression.toString());
}
- private boolean isEqualityComparison(PsiExpression testArg) {
- if (testArg instanceof PsiBinaryExpression) {
- final PsiJavaToken sign = ((PsiBinaryExpression) testArg).getOperationSign();
- if(sign == null)
- {
- return false;
- }
- if(!sign.getTokenType().equals(JavaTokenType.EQEQ))
- {
- return false;
- }
- final PsiExpression lhs = ((PsiBinaryExpression) testArg).getLOperand();
- if(lhs == null)
- {
- return false;
- }
- final PsiExpression rhs = ((PsiBinaryExpression) testArg).getROperand();
- if(rhs == null)
- {
- return false;
- }
- final PsiType type = lhs.getType();
- if(type == null)
- {
- return false;
- }
- if(!ClassUtils.isPrimitive(type))
- {
- return false;
- }
- return true;
- } else if (testArg instanceof PsiMethodCallExpression) {
- final PsiMethodCallExpression call = (PsiMethodCallExpression) testArg;
- final PsiReferenceExpression methodExpression = call.getMethodExpression();
- final String methodName = methodExpression.getReferenceName();
- if(!"equals".equals(methodName))
- {
- return false;
- }
- final PsiExpressionList argumentList = call.getArgumentList();
- if(argumentList == null)
- {
- return false;
- }
- final PsiExpression[] args = argumentList.getExpressions();
- if(args == null)
- {
- return false;
- }
- if(args.length!=1)
- {
- return false;
- }
- if(args[0] == null)
- {
- return false;
- }
- if(methodExpression.getQualifierExpression() == null)
- {
- return false;
- }
- return true;
+ private boolean isFloatingPoint(PsiExpression expression){
+ final PsiType type = expression.getType();
+ return PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type);
+ }
+ }
+
+ public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
+ boolean onTheFly){
+ return new SimplifiableJUnitAssertionVisitor(this,
+ inspectionManager,
+ onTheFly);
+ }
+
+ private static class SimplifiableJUnitAssertionVisitor
+ extends BaseInspectionVisitor{
+ private SimplifiableJUnitAssertionVisitor(BaseInspection inspection,
+ InspectionManager inspectionManager,
+ boolean isOnTheFly){
+ super(inspection, inspectionManager, isOnTheFly);
+ }
+
+ public void visitMethodCallExpression(PsiMethodCallExpression expression){
+ super.visitMethodCallExpression(expression);
+ if(isAssertTrueThatCouldBeAssertEquality(expression)){
+ registerMethodCallError(expression);
+ return;
}
+ if(isAssertEqualsThatCouldBeAssertLiteral(expression)){
+ registerMethodCallError(expression);
+ return;
+ }
+ }
+ }
+
+ private static boolean isAssertTrueThatCouldBeAssertEquality(PsiMethodCallExpression expression){
+ if(!isAssertTrue(expression)){
return false;
}
+ final PsiReferenceExpression methodExpression =
+ expression.getMethodExpression();
- private static boolean isAssertTrue(PsiMethodCallExpression expression) {
- final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+ final PsiMethod method = (PsiMethod) methodExpression.resolve();
+ final PsiParameterList paramList = method.getParameterList();
+ if(paramList == null){
+ return false;
+ }
+ final PsiParameter[] parameters = paramList.getParameters();
+
+ final PsiManager psiManager = expression.getManager();
+
+ final Project project = psiManager.getProject();
+ final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
+ final PsiType stringType =
+ PsiType.getJavaLangString(psiManager, scope);
+ final PsiType paramType1 = parameters[0].getType();
+ final int testPosition;
+ if(paramType1.equals(stringType) && parameters.length > 1){
+ testPosition = 1;
+ } else{
+ testPosition = 0;
+ }
+ final PsiExpressionList argumentList = expression.getArgumentList();
+ if(argumentList == null){
+ return false;
+ }
+ final PsiExpression[] args = argumentList.getExpressions();
+ final PsiExpression testArg = args[testPosition];
+ if(testArg == null){
+ return false;
+ }
+ if(!isEqualityComparison(testArg)){
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean isAssertEqualsThatCouldBeAssertLiteral(PsiMethodCallExpression expression){
+ if(!isAssertEquals(expression)){
+ return false;
+ }
+ final PsiReferenceExpression methodExpression =
+ expression.getMethodExpression();
+
+ final PsiMethod method = (PsiMethod) methodExpression.resolve();
+ final PsiParameterList paramList = method.getParameterList();
+ if(paramList == null){
+ return false;
+ }
+ final PsiParameter[] parameters = paramList.getParameters();
+
+ final PsiManager psiManager = expression.getManager();
+
+ final Project project = psiManager.getProject();
+ final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
+ final PsiType stringType =
+ PsiType.getJavaLangString(psiManager, scope);
+ final PsiType paramType1 = parameters[0].getType();
+ final int firstTestPosition;
+ final int secondTestPosition;
+ if(paramType1.equals(stringType) && parameters.length > 2){
+ firstTestPosition = 1;
+ secondTestPosition = 2;
+ } else{
+ firstTestPosition = 0;
+ secondTestPosition = 1;
+ }
+ final PsiExpressionList argumentList = expression.getArgumentList();
+ if(argumentList == null){
+ return false;
+ }
+ final PsiExpression[] args = argumentList.getExpressions();
+ final PsiExpression firstTestArg = args[firstTestPosition];
+ final PsiExpression secondTestArg = args[secondTestPosition];
+ if(firstTestArg == null){
+ return false;
+ }
+ if(secondTestArg == null){
+ return false;
+ }
+ if(isSimpleLiteral(firstTestArg) || isSimpleLiteral(secondTestArg)){
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean isSimpleLiteral(PsiExpression arg){
+ if(!(arg instanceof PsiLiteralExpression)){
+ return false;
+ }
+ final String text = arg.getText();
+ return "null".equals(text) || "true".equals(text) ||
+ "false".equals(text);
+ }
+
+ private static boolean isEqualityComparison(PsiExpression testArg){
+ if(testArg instanceof PsiBinaryExpression){
+ final PsiJavaToken sign =
+ ((PsiBinaryExpression) testArg).getOperationSign();
+ if(sign == null){
+ return false;
+ }
+ if(!sign.getTokenType().equals(JavaTokenType.EQEQ)){
+ return false;
+ }
+ final PsiExpression lhs =
+ ((PsiBinaryExpression) testArg).getLOperand();
+ if(lhs == null){
+ return false;
+ }
+ final PsiExpression rhs =
+ ((PsiBinaryExpression) testArg).getROperand();
+ if(rhs == null){
+ return false;
+ }
+ final PsiType type = lhs.getType();
+ if(type == null){
+ return false;
+ }
+ if(!ClassUtils.isPrimitive(type)){
+ return false;
+ }
+ return true;
+ } else if(testArg instanceof PsiMethodCallExpression){
+ final PsiMethodCallExpression call =
+ (PsiMethodCallExpression) testArg;
+ final PsiReferenceExpression methodExpression =
+ call.getMethodExpression();
final String methodName = methodExpression.getReferenceName();
- if (!"assertTrue".equals(methodName)) {
+ if(!"equals".equals(methodName)){
return false;
}
- final PsiMethod method = (PsiMethod) methodExpression.resolve();
- if (method == null) {
+ final PsiExpressionList argumentList = call.getArgumentList();
+ if(argumentList == null){
return false;
}
-
- final PsiClass targetClass = method.getContainingClass();
- if (!ClassUtils.isSubclass(targetClass, "junit.framework.Assert")) {
+ final PsiExpression[] args = argumentList.getExpressions();
+ if(args == null){
+ return false;
+ }
+ if(args.length != 1){
+ return false;
+ }
+ if(args[0] == null){
+ return false;
+ }
+ if(methodExpression.getQualifierExpression() == null){
return false;
}
return true;
}
-
+ return false;
}
+ private static boolean isAssertTrue(PsiMethodCallExpression expression){
+ final PsiReferenceExpression methodExpression =
+ expression.getMethodExpression();
+ final String methodName = methodExpression.getReferenceName();
+ if(!"assertTrue".equals(methodName)){
+ return false;
+ }
+ final PsiMethod method = (PsiMethod) methodExpression.resolve();
+ if(method == null){
+ return false;
+ }
+
+ final PsiClass targetClass = method.getContainingClass();
+ if(!ClassUtils.isSubclass(targetClass, "junit.framework.Assert")){
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean isAssertEquals(PsiMethodCallExpression expression){
+ final PsiReferenceExpression methodExpression =
+ expression.getMethodExpression();
+ final String methodName = methodExpression.getReferenceName();
+ if(!"assertEquals".equals(methodName)){
+ return false;
+ }
+ final PsiMethod method = (PsiMethod) methodExpression.resolve();
+ if(method == null){
+ return false;
+ }
+
+ final PsiClass targetClass = method.getContainingClass();
+ if(!ClassUtils.isSubclass(targetClass, "junit.framework.Assert")){
+ return false;
+ }
+ return true;
+ }
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ClassUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ClassUtils.java
index ff6c2c5745a6..f3b152d18f82 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ClassUtils.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ClassUtils.java
@@ -178,4 +178,24 @@ public class ClassUtils {
public static PsiMethod getContainingMethod(PsiElement element){
return (PsiMethod) PsiTreeUtil.getParentOfType(element, PsiMethod.class);
}
+
+ public static boolean isClassVisibleFromClass(PsiClass baseClass,
+ PsiClass referencedClass){
+ if(referencedClass.hasModifierProperty(PsiModifier.PUBLIC))
+ {
+ return true;
+ }
+ else if(referencedClass.hasModifierProperty(PsiModifier.PROTECTED))
+ {
+ return inSamePackage(baseClass, referencedClass);
+ }
+ else if(referencedClass.hasModifierProperty(PsiModifier.PRIVATE))
+ {
+ return PsiTreeUtil.findCommonParent(baseClass, referencedClass)!=null;
+ }
+ else
+ {
+ return inSamePackage(baseClass, referencedClass);
+ }
+ }
}
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/MissortedModifiersInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/MissortedModifiersInspection.java
index e89fde13e8d3..4b33ace1a9f2 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/MissortedModifiersInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/MissortedModifiersInspection.java
@@ -78,37 +78,10 @@ public class MissortedModifiersInspection extends ClassInspection {
}
- private static Map NAME_TO_KEYWORD_TYPE_MAP =
- new HashMap();
-
- static{
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PUBLIC, JavaTokenType.PUBLIC_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PROTECTED,
- JavaTokenType.PROTECTED_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.PRIVATE,
- JavaTokenType.PRIVATE_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.STATIC,
- JavaTokenType.STATIC_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.ABSTRACT,
- JavaTokenType. ABSTRACT_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.FINAL,
- JavaTokenType.FINAL_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.NATIVE,
- JavaTokenType.NATIVE_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.SYNCHRONIZED,
- JavaTokenType.SYNCHRONIZED_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.STRICTFP,
- JavaTokenType.STRICTFP_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.TRANSIENT,
- JavaTokenType.TRANSIENT_KEYWORD);
- NAME_TO_KEYWORD_TYPE_MAP.put(PsiModifier.VOLATILE,
- JavaTokenType.VOLATILE_KEYWORD);
- }
private static void addModifiersInOrder(List modifiers,
PsiModifierList modifierList) {
for (Iterator iterator = modifiers.iterator(); iterator.hasNext();) {
final String modifier = (String) iterator.next();
- final JavaTokenType keyword = (JavaTokenType) NAME_TO_KEYWORD_TYPE_MAP.get(modifier);
try {
modifierList.setModifierProperty(modifier, true);
} catch (IncorrectOperationException e) {
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java
index e8f53ccd995d..722b80beea80 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/verbose/UnnecessaryFullyQualifiedNameInspection.java
@@ -112,6 +112,7 @@ public class UnnecessaryFullyQualifiedNameInspection extends ClassInspection{
}
m_inClass = wasInClass;
}
+
public void visitReferenceElement(PsiJavaCodeReferenceElement element){
if(m_ignoreJavadoc)
{
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassChild.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassChild.java
new file mode 100644
index 000000000000..2f725606be3f
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassChild.java
@@ -0,0 +1,4 @@
+package com.siyeh.igtest.abstraction;
+
+public class StaticCallOnSubclassChild extends StaticCallOnSubclassParent {
+}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassParent.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassParent.java
new file mode 100644
index 000000000000..f7516a8ed1da
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/abstraction/StaticCallOnSubclassParent.java
@@ -0,0 +1,5 @@
+package com.siyeh.igtest.abstraction;
+
+ \class StaticCallOnSubclassParent {
+ public static void foo(){};
+}
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/StaticCallOnSubclass.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/StaticCallOnSubclass.java
index edee3629f52f..ce84c858fe00 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/StaticCallOnSubclass.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/StaticCallOnSubclass.java
@@ -1,10 +1,13 @@
package com.siyeh.igtest.bugs;
+import com.siyeh.igtest.abstraction.StaticCallOnSubclassChild;
+
public class StaticCallOnSubclass {
public void foo() throws InterruptedException {
Thread.sleep(1000L);
- InnerThread.sleep(1000L);
+ InnerThread.sleep(1000L, 1000);
+ StaticCallOnSubclassChild.foo();
}
class InnerThread extends Thread
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/SimplifiableJUnitAssertionInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/SimplifiableJUnitAssertionInspection.java
new file mode 100644
index 000000000000..dcb5183cf4c7
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/junit/SimplifiableJUnitAssertionInspection.java
@@ -0,0 +1,11 @@
+package com.siyeh.igtest.junit;
+
+import junit.framework.TestCase;
+
+public class SimplifiableJUnitAssertionInspection extends TestCase{
+ public void test()
+ {
+ assertTrue(3 == 4);
+ assertEquals(false, new Object() != null);
+ }
+}