(no message)

This commit is contained in:
Dave Griffith
2005-03-21 18:25:50 +03:00
parent ae0d074454
commit 7e5fcd63bf
239 changed files with 3081 additions and 674 deletions
@@ -196,7 +196,7 @@
<module fileurl="file://$PROJECT_DIR$/InspectionGadgetsSVN.iml" filepath="$PROJECT_DIR$/InspectionGadgetsSVN.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" project-jdk-name="IDEA 3245" />
<component name="ProjectRootManager" version="2" assert-keyword="true" jdk-15="false" project-jdk-name="IDEA 3260" />
<component name="RmicSettings">
<option name="IS_EANABLED" value="false" />
<option name="DEBUGGING_INFO" value="true" />
+4 -11
View File
@@ -6,8 +6,7 @@
setter or getter with non-standard name
Avoid repeated casting
arithmetic operations on volatile types
Field has setter but no getter
Class name with forbidden component
Class name with forbidden name component
Paired open/close for Sockets
Paired open/close for Channels
Paired acquire/release for Locks
@@ -15,20 +14,14 @@
Empty zip file entry
Empty jar file entry
getClass().getResource()
Using nextDouble rather than nextInt() to create random integer
Inefficient use of keySet iterator rather than entrySet iterator
Equals methods that do not check parameter type
Call to simple getter or setter from within class
Encapsulatable use of field
Static inheritance fix
Static import fix
Vararg fix
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)
Flag inspections with default on-off and default warning level
Inheritance as type def (change the EmptyClass inspection)
Fix damn "Instanceof Incompatible Interface" inspection
Fix the "variable accessed in synchronized and unsynchronized contexts" to deal
with unsynchronized private methods called only from synchronized contexts
@@ -24,12 +24,6 @@ import com.siyeh.ig.imports.*;
import com.siyeh.ig.initialization.*;
import com.siyeh.ig.internationalization.*;
import com.siyeh.ig.jdk.*;
import com.siyeh.ig.jdk.AnnotationInspection;
import com.siyeh.ig.jdk.AssertAsNameInspection;
import com.siyeh.ig.jdk.AssertStatementInspection;
import com.siyeh.ig.jdk.EnumAsNameInspection;
import com.siyeh.ig.jdk.EnumClassInspection;
import com.siyeh.ig.jdk.VarargParameterInspection;
import com.siyeh.ig.junit.*;
import com.siyeh.ig.logging.ClassWithMultipleLoggersInspection;
import com.siyeh.ig.logging.ClassWithoutLoggerInspection;
@@ -52,14 +46,14 @@ import com.siyeh.ig.verbose.*;
import com.siyeh.ig.visibility.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
public class InspectionGadgetsPlugin implements ApplicationComponent,
InspectionToolProvider{
private static final int NUM_INSPECTIONS = 360;
private final List m_inspectionClasses = new ArrayList(NUM_INSPECTIONS);
private static final String DESCRIPTION_DIRECTORY_NAME =
"C:/My Open Source Projects/InspectionGadgetsSVN/src/inspectionDescriptions/";
public static void main(String[] args){
final InspectionGadgetsPlugin plugin = new InspectionGadgetsPlugin();
@@ -114,20 +108,58 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
}
}
out.println();
out.println("Inspections enabled by default:");
for(int i = 0; i < classes.length; i++){
final Class aClass = classes[i];
final String className = aClass.getName();
try{
final LocalInspectionTool inspection =
(LocalInspectionTool) aClass.newInstance();
if(inspection.isEnabledByDefault())
{
out.println("\t"+inspection.getDisplayName());
}
} catch(InstantiationException e){
out.print("Couldn't instantiate ");
out.println(className);
} catch(IllegalAccessException e){
out.print("Couldn't access ");
out.println(className);
} catch(ClassCastException e){
out.print("Couldn't cast ");
out.println(className);
}
}
final File descriptionDirectory = new File(DESCRIPTION_DIRECTORY_NAME);
final File[] descriptionFiles = descriptionDirectory.listFiles();
final Set descriptionFilesSet = new HashSet(descriptionFiles.length);
for(int i = 0; i < descriptionFiles.length; i++){
if(!descriptionFiles[i].getName().startsWith(".")){
descriptionFilesSet.add(descriptionFiles[i]);
}
}
for(int i = 0; i < classes.length; i++){
final Class aClass = classes[i];
final String className = aClass.getName();
final String simpleClassName =
className.substring(className.lastIndexOf('.') + 1,
className.length() -
"Inspection".length());
"Inspection".length());
final String fileName =
"C:/InspectionGadgetsSVN/src/inspectionDescriptions/" +
simpleClassName + ".html";
if(!new File(fileName).exists()){
out.println("Couldn't find documentation file " + fileName);
DESCRIPTION_DIRECTORY_NAME + simpleClassName + ".html";
final File descriptionFile = new File(fileName);
if(descriptionFile.exists()){
descriptionFilesSet.remove(descriptionFile);
} else{
out.println("Couldn't find documentation file: " + fileName);
}
}
for(Iterator unusedDescriptionFiles = descriptionFilesSet.iterator();
unusedDescriptionFiles.hasNext();){
final File file = (File) unusedDescriptionFiles.next();
out.println("Unused documentation file: " + file.getAbsolutePath());
}
}
private static void printInspectionDescription(LocalInspectionTool inspection,
@@ -224,7 +256,6 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(JDBCResourceInspection.class);
}
private void registerLoggingInspections(){
final List inspectionClasses = m_inspectionClasses;
inspectionClasses.add(ClassWithoutLoggerInspection.class);
@@ -272,7 +303,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(MethodNameSameAsParentNameInspection.class);
inspectionClasses.add(StandardVariableNamesInspection.class);
inspectionClasses.add(BooleanMethodNameMustStartWithQuestionInspection.class);
inspectionClasses.add(NonBooleanMethodNameMayNotStartWithQuestionInspection .class);
inspectionClasses.add(NonBooleanMethodNameMayNotStartWithQuestionInspection.class);
inspectionClasses.add(QuestionableNameInspection.class);
inspectionClasses.add(ConfusingMainMethodInspection.class);
inspectionClasses.add(UpperCaseFieldNameNotConstantInspection.class);
@@ -325,6 +356,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(EqualsUsesNonFinalVariableInspection.class);
inspectionClasses.add(HashCodeUsesNonFinalVariableInspection.class);
inspectionClasses.add(CompareToUsesNonFinalVariableInspection.class);
inspectionClasses.add(EqualsWhichDoesntCheckParameterClassInspection.class);
}
private void registerAbstractionInspections(){
@@ -384,6 +416,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(MultipleTopLevelClassesInFileInspection.class);
inspectionClasses.add(ClassNameDiffersFromFileNameInspection.class);
inspectionClasses.add(MarkerInterfaceInspection.class);
inspectionClasses.add(FieldHasSetterButNoGetterInspection.class);
}
private void registerCloneInspections(){
@@ -504,6 +537,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(UnnecessaryFinalOnParameterInspection.class);
inspectionClasses.add(UnnecessaryFinalOnLocalVariableInspection.class);
inspectionClasses.add(ForCanBeForeachInspection.class);
inspectionClasses.add(WhileCanBeForeachInspection.class);
}
private void registerStyleInspections(){
@@ -690,11 +724,14 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
inspectionClasses.add(SystemGCInspection.class);
inspectionClasses.add(SingleCharacterStartsWithInspection.class);
inspectionClasses.add(StringEqualsEmptyStringInspection.class);
inspectionClasses.add(RandomDoubleForRandomIntegerInspection.class);
inspectionClasses.add(FieldRepeatedlyAccessedInspection.class);
inspectionClasses.add(ManualArrayCopyInspection.class);
inspectionClasses.add(JavaLangReflectInspection.class);
inspectionClasses.add(StaticCollectionInspection.class);
inspectionClasses.add(ZeroLengthArrayInitializationInspection.class);
inspectionClasses.add(CallToSimpleGetterInClassInspection.class);
inspectionClasses.add(CallToSimpleSetterInClassInspection.class);
}
private void registerMaturityInspections(){
@@ -10,6 +10,10 @@ import com.siyeh.ig.psiutils.CollectionUtils;
public class DeclareCollectionAsInterfaceInspection extends VariableInspection {
public String getID(){
return "CollectionDeclaredAsConcreteClass";
}
public String getDisplayName() {
return "Collection declared by class, not interface";
}
@@ -30,11 +30,11 @@ public class FeatureEnvyInspection extends MethodInspection {
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new InstanceVariableRepeatedlyAccessedVisitor(this, inspectionManager, onTheFly);
return new FeatureEnvyVisitor(this, inspectionManager, onTheFly);
}
private static class InstanceVariableRepeatedlyAccessedVisitor extends BaseInspectionVisitor {
private InstanceVariableRepeatedlyAccessedVisitor(BaseInspection inspection,
private static class FeatureEnvyVisitor extends BaseInspectionVisitor {
private FeatureEnvyVisitor(BaseInspection inspection,
InspectionManager inspectionManager, boolean isOnTheFly) {
super(inspection, inspectionManager, isOnTheFly);
}
@@ -12,7 +12,7 @@ import com.siyeh.ig.GroupNames;
public class InstanceVariableOfConcreteClassInspection extends FieldInspection {
public String getDisplayName() {
return "Concrete class for instance variable";
return "Instance variable of concrete class";
}
public String getGroupDisplayName() {
@@ -9,6 +9,10 @@ import com.siyeh.ig.StatementInspection;
public class InstanceofChainInspection extends StatementInspection {
public String getID(){
return "ChainOfInstanceofChecks";
}
public String getDisplayName() {
return "Chain of 'instanceof' checks";
}
@@ -11,7 +11,7 @@ import com.siyeh.ig.GroupNames;
public class LocalVariableOfConcreteClassInspection extends ExpressionInspection {
public String getDisplayName() {
return "Concrete class for local variable";
return "Local variable of concrete class";
}
public String getGroupDisplayName() {
@@ -12,7 +12,7 @@ import com.siyeh.ig.MethodInspection;
public class MethodReturnOfConcreteClassInspection extends MethodInspection {
public String getDisplayName() {
return "Concrete class for method return";
return "Method return of concrete class";
}
public String getGroupDisplayName() {
@@ -10,9 +10,11 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.MethodInspection;
public class ParameterOfConcreteClassInspection extends MethodInspection {
public String getID(){
return "MethodParameterOfConcreteClass";
}
public String getDisplayName() {
return "Concrete class for method parameter";
return "Method parameter of concrete class";
}
public String getGroupDisplayName() {
@@ -12,7 +12,7 @@ import com.siyeh.ig.GroupNames;
public class StaticVariableOfConcreteClassInspection extends FieldInspection {
public String getDisplayName() {
return "Concrete class for static variable";
return "Static variable of concrete class";
}
public String getGroupDisplayName() {
@@ -11,7 +11,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.StatementInspection;
public class EmptyInitializerInspection extends StatementInspection {
public String getID(){
return "EmptyClassInitializer";
}
public String getDisplayName() {
return "Empty class initializer";
}
@@ -13,6 +13,10 @@ import javax.swing.*;
public class EmptyStatementBodyInspection extends StatementInspection {
public boolean m_reportEmptyBlocks = false;
public String getID(){
return "StatementWithEmptyBody";
}
public String getDisplayName() {
return "Statement with empty body";
}
@@ -7,82 +7,88 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class EqualsUsesNonFinalVariableInspection extends ExpressionInspection {
public class EqualsUsesNonFinalVariableInspection extends ExpressionInspection{
public String getID(){
return "NonFinalFieldReferenceInEquals";
}
public String getDisplayName() {
public String getDisplayName(){
return "Non-final field referenced in 'equals()'";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.BUGS_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
public String buildErrorString(PsiElement location){
return "Non-final field #ref accessed in equals() #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new EqualsUsesNonFinalVariableVisitor(this, inspectionManager, onTheFly);
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new EqualsUsesNonFinalVariableVisitor(this, inspectionManager,
onTheFly);
}
private static class EqualsUsesNonFinalVariableVisitor extends BaseInspectionVisitor {
private static class EqualsUsesNonFinalVariableVisitor
extends BaseInspectionVisitor{
private boolean m_inEquals = false;
private EqualsUsesNonFinalVariableVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
private EqualsUsesNonFinalVariableVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitReferenceExpression(PsiReferenceExpression expression) {
public void visitReferenceExpression(PsiReferenceExpression expression){
super.visitReferenceExpression(expression);
if (!m_inEquals) {
if(!m_inEquals){
return;
}
final PsiElement element = expression.resolve();
if (!(element instanceof PsiField)) {
if(!(element instanceof PsiField)){
return;
}
final PsiField field = (PsiField) element;
if (field.hasModifierProperty(PsiModifier.FINAL)) {
if(field.hasModifierProperty(PsiModifier.FINAL)){
return;
}
registerError(expression);
}
public void visitMethod(PsiMethod method) {
public void visitMethod(PsiMethod method){
final boolean isEquals = isEqualsMethod(method);
if (isEquals) {
if(isEquals){
m_inEquals = true;
}
super.visitMethod(method);
if (isEquals) {
if(isEquals){
m_inEquals = false;
}
}
private static boolean isEqualsMethod(PsiMethod method) {
private static boolean isEqualsMethod(PsiMethod method){
final String methodName = method.getName();
if (!"equals".equals(methodName)) {
if(!"equals".equals(methodName)){
return false;
}
final PsiParameterList parameterList = method.getParameterList();
if (parameterList == null) {
if(parameterList == null){
return false;
}
final PsiParameter[] parameters = parameterList.getParameters();
if (parameters == null || parameters.length != 1) {
if(parameters == null || parameters.length != 1){
return false;
}
final PsiType returnType = method.getReturnType();
if (returnType == null) {
if(returnType == null){
return false;
}
if (!returnType.equals(PsiType.BOOLEAN)) {
if(!returnType.equals(PsiType.BOOLEAN)){
return false;
}
return true;
}
}
}
@@ -0,0 +1,83 @@
package com.siyeh.ig.bugs;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.psi.*;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.GroupNames;
import com.siyeh.ig.MethodInspection;
import com.siyeh.ig.psiutils.TypeUtils;
public class EqualsWhichDoesntCheckParameterClassInspection
extends MethodInspection{
public String getDisplayName(){
return "'equals()' method which doesn't check class of parameter";
}
public String getGroupDisplayName(){
return GroupNames.BUGS_GROUP_NAME;
}
public String buildErrorString(PsiElement location){
return "#ref should check the class of it's parameter #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new EqualsWhichDoesntCheckParameterClassVisitor(this,
inspectionManager,
onTheFly);
}
private class EqualsWhichDoesntCheckParameterClassVisitor
extends BaseInspectionVisitor{
private static final String EQUALS_METHOD_NAME = "equals";
private EqualsWhichDoesntCheckParameterClassVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitMethod(PsiMethod method){
// note: no call to super
final String name = method.getName();
if(!EQUALS_METHOD_NAME.equals(name)){
return;
}
if(!method.hasModifierProperty(PsiModifier.PUBLIC)){
return;
}
final PsiParameterList paramList = method.getParameterList();
if(paramList == null){
return;
}
final PsiParameter[] parameters = paramList.getParameters();
if(parameters.length != 1){
return;
}
final PsiParameter parameter = parameters[0];
final PsiType argType = parameter.getType();
if(!TypeUtils.isJavaLangObject(argType)){
return;
}
final PsiCodeBlock body = method.getBody();
if(body == null){
return;
}
if(isParameterChecked(body, parameter)){
return;
}
registerMethodError(method);
}
private boolean isParameterChecked(PsiCodeBlock body,
PsiParameter parameter){
final ParameterClassCheckVisitor visitor =
new ParameterClassCheckVisitor(parameter);
body.accept(visitor);
return visitor.isChecked();
}
}
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.ControlFlowUtils;
public class FallthruInSwitchStatementInspection extends StatementInspection {
public String getID(){
return "FallthroughInSwitchStatement";
}
public String getDisplayName() {
return "Fallthrough in 'switch' statement";
}
@@ -8,7 +8,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class HashCodeUsesNonFinalVariableInspection extends ExpressionInspection {
public String getID(){
return "NonFinalFieldReferencedInHashCode";
}
public String getDisplayName() {
return "Non-final field referenced in 'hashCode()'";
}
@@ -85,6 +85,9 @@ public class IgnoreResultOfCallInspection extends ExpressionInspection{
callCheckString = buffer.toString();
}
public String getID(){
return "ResultOfMethodCallIgnored";
}
public String getDisplayName(){
return "Result of method call ignored";
}
@@ -12,39 +12,48 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.ComparisonUtils;
import com.siyeh.ig.psiutils.WellFormednessUtils;
public class IncompatibleMaskInspection extends ExpressionInspection {
public class IncompatibleMaskInspection extends ExpressionInspection{
public String getID(){
return "IncompatibleBitwiseMaskOperation";
}
public String getDisplayName() {
public String getDisplayName(){
return "Incompatible bitwise mask operation";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.BUGS_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) location;
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location){
final PsiBinaryExpression binaryExpression =
(PsiBinaryExpression) location;
final PsiJavaToken operationSign = binaryExpression.getOperationSign();
final IElementType tokenType = operationSign.getTokenType();
if (tokenType.equals(JavaTokenType.EQEQ)) {
if(tokenType.equals(JavaTokenType.EQEQ)){
return "#ref is always false #loc";
} else {
} else{
return "#ref is always true #loc";
}
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new IncompatibleMaskVisitor(this, inspectionManager, onTheFly);
}
private static class IncompatibleMaskVisitor extends BaseInspectionVisitor {
private IncompatibleMaskVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
private static class IncompatibleMaskVisitor extends BaseInspectionVisitor{
private IncompatibleMaskVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitBinaryExpression(PsiBinaryExpression expression) {
public void visitBinaryExpression(PsiBinaryExpression expression){
super.visitBinaryExpression(expression);
if(!WellFormednessUtils.isWellFormed(expression)){
return;
@@ -53,37 +62,40 @@ public class IncompatibleMaskInspection extends ExpressionInspection {
return;
}
final PsiType expressionType = expression.getType();
if (expressionType == null) {
if(expressionType == null){
return;
}
final PsiExpression rhs = expression.getROperand();
final PsiExpression strippedRhs = stripExpression(rhs);
if (strippedRhs == null) {
if(strippedRhs == null){
return;
}
final PsiExpression lhs = expression.getLOperand();
final PsiExpression strippedLhs = stripExpression(lhs);
if (strippedLhs == null) {
if(strippedLhs == null){
return;
}
if (isConstantMask(strippedLhs) && PsiUtil.isConstantExpression(strippedRhs)) {
if (isIncompatibleMask((PsiBinaryExpression) strippedLhs, strippedRhs)) {
if(isConstantMask(strippedLhs) &&
PsiUtil.isConstantExpression(strippedRhs)){
if(isIncompatibleMask((PsiBinaryExpression) strippedLhs,
strippedRhs)){
registerError(expression);
}
} else if (isConstantMask(strippedRhs) && PsiUtil.isConstantExpression(strippedLhs)) {
if (isIncompatibleMask((PsiBinaryExpression) strippedRhs, strippedLhs)) {
registerError(expression);
}
}
} else if(isConstantMask(strippedRhs) &&
PsiUtil.isConstantExpression(strippedLhs)){
if(isIncompatibleMask((PsiBinaryExpression) strippedRhs,
strippedLhs)){
registerError(expression);
}
}
}
}
private static PsiExpression stripExpression(PsiExpression exp) {
if (exp == null) {
private static PsiExpression stripExpression(PsiExpression exp){
if(exp == null){
return null;
}
if (exp instanceof PsiParenthesizedExpression) {
if(exp instanceof PsiParenthesizedExpression){
final PsiExpression body =
((PsiParenthesizedExpression) exp).getExpression();
return stripExpression(body);
@@ -91,12 +103,14 @@ public class IncompatibleMaskInspection extends ExpressionInspection {
return exp;
}
private static boolean isIncompatibleMask(PsiBinaryExpression maskExpression, PsiExpression constantExpression) {
private static boolean isIncompatibleMask(PsiBinaryExpression maskExpression,
PsiExpression constantExpression){
final PsiJavaToken sign = maskExpression.getOperationSign();
final IElementType tokenType = sign.getTokenType();
final Object constantValue =
ConstantExpressionUtil.computeCastTo(constantExpression, PsiType.LONG);
if (constantValue == null) {
ConstantExpressionUtil.computeCastTo(constantExpression,
PsiType.LONG);
if(constantValue == null){
return false;
}
final long constantLongValue = ((Long) constantValue).longValue();
@@ -104,55 +118,56 @@ public class IncompatibleMaskInspection extends ExpressionInspection {
final long constantMaskValue;
final PsiExpression maskRhs = maskExpression.getROperand();
final PsiExpression maskLhs = maskExpression.getLOperand();
if (PsiUtil.isConstantExpression(maskRhs)) {
if(PsiUtil.isConstantExpression(maskRhs)){
final Object rhsValue =
ConstantExpressionUtil.computeCastTo(maskRhs, PsiType.LONG);
constantMaskValue = ((Long) rhsValue).longValue();
} else {
} else{
final Object lhsValue =
ConstantExpressionUtil.computeCastTo(maskLhs, PsiType.LONG);
constantMaskValue = ((Long) lhsValue).longValue();
}
if (tokenType.equals(JavaTokenType.OR)) {
if ((constantMaskValue | constantLongValue) != constantLongValue) {
if(tokenType.equals(JavaTokenType.OR)){
if((constantMaskValue | constantLongValue) != constantLongValue){
return true;
}
}
if (tokenType.equals(JavaTokenType.AND)) {
if ((constantMaskValue | constantLongValue) != constantMaskValue) {
if(tokenType.equals(JavaTokenType.AND)){
if((constantMaskValue | constantLongValue) != constantMaskValue){
return true;
}
}
return false;
}
private static boolean isConstantMask(PsiExpression expression) {
if (expression == null) {
private static boolean isConstantMask(PsiExpression expression){
if(expression == null){
return false;
}
if (!(expression instanceof PsiBinaryExpression)) {
if(!(expression instanceof PsiBinaryExpression)){
return false;
}
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) expression;
final PsiBinaryExpression binaryExpression =
(PsiBinaryExpression) expression;
final PsiJavaToken sign = binaryExpression.getOperationSign();
if (sign == null) {
if(sign == null){
return false;
}
final IElementType tokenType = sign.getTokenType();
if (!tokenType.equals(JavaTokenType.OR) && !tokenType.equals(JavaTokenType.AND)) {
if(!tokenType.equals(JavaTokenType.OR) &&
!tokenType.equals(JavaTokenType.AND)){
return false;
}
final PsiExpression rhs = binaryExpression.getROperand();
if (PsiUtil.isConstantExpression(rhs)) {
if(PsiUtil.isConstantExpression(rhs)){
return true;
}
final PsiExpression lhs = binaryExpression.getLOperand();
if (PsiUtil.isConstantExpression(lhs)) {
if(PsiUtil.isConstantExpression(lhs)){
return true;
}
return false;
}
}
@@ -21,6 +21,10 @@ public class InfiniteLoopStatementInspection extends StatementInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "#ref statement cannot complete without throwing an exception #loc";
}
@@ -20,6 +20,9 @@ public class InfiniteRecursionInspection extends MethodInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "Method #ref recurses infinitely, and can only end by throw an exception #loc";
}
@@ -12,6 +12,7 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class InstanceofIncompatibleInterfaceInspection extends ExpressionInspection{
public String getDisplayName(){
return "'instanceof' with incompatible interface";
}
@@ -15,6 +15,9 @@ import java.util.Set;
public class IteratorNextDoesNotThrowNoSuchElementExceptionInspection
extends MethodInspection{
public String getID(){
return "IteratorNextCanNotThrowNoSuchElementException";
}
public String getDisplayName(){
return "Iterator.next() which can't throw NoSuchElementException";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.ControlFlowUtils;
public class LoopStatementsThatDontLoopInspection extends StatementInspection {
public String getID(){
return "LoopStatementThatDoesntLoop";
}
public String getDisplayName() {
return "Loop statement that doesn't loop";
}
@@ -18,6 +20,10 @@ public class LoopStatementsThatDontLoopInspection extends StatementInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "#ref statement doesn't loop #loc";
}
@@ -10,7 +10,9 @@ import com.siyeh.ig.VariableInspection;
import com.siyeh.ig.psiutils.VariableAccessUtils;
public class MismatchedArrayReadWriteInspection extends VariableInspection {
public String getID(){
return "MismatchedReadAndWriteOfArray";
}
public String getDisplayName() {
return "Mismatched read and write of array";
}
@@ -19,6 +21,9 @@ public class MismatchedArrayReadWriteInspection extends VariableInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
final PsiVariable variable = (PsiVariable) location.getParent();
final PsiElement context;
@@ -13,7 +13,9 @@ import com.siyeh.ig.psiutils.VariablePassedAsArgumentVisitor;
import com.siyeh.ig.psiutils.VariableReturnedVisitor;
public class MismatchedCollectionQueryUpdateInspection extends VariableInspection {
public String getID(){
return "MismatchedQueryAndUpdateOfCollection";
}
public String getDisplayName() {
return "Mismatched query and update of collection";
}
@@ -22,6 +24,10 @@ public class MismatchedCollectionQueryUpdateInspection extends VariableInspectio
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
final PsiVariable variable = (PsiVariable) location.getParent();
final PsiElement context;
@@ -9,6 +9,9 @@ import com.siyeh.ig.*;
import com.siyeh.ig.psiutils.WellFormednessUtils;
public class NonShortCircuitBooleanInspection extends ExpressionInspection {
public String getID(){
return "NonShortCircuitBooleanExpression";
}
private final InspectionGadgetsFix fix = new NonShortCircuitBooleanFix();
public String getDisplayName() {
@@ -17,6 +17,10 @@ public class ObjectEqualsNullInspection extends ExpressionInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return ".equals(#ref) is probably not what was intended #loc";
}
@@ -8,7 +8,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class OctalAndDecimalIntegersMixedInspection extends ExpressionInspection {
public String getID(){
return "OctalAndDecimalIntegersInSameArray";
}
public String getDisplayName() {
return "Octal and decimal integers in same array";
}
@@ -0,0 +1,73 @@
package com.siyeh.ig.bugs;
import com.intellij.psi.*;
public class ParameterClassCheckVisitor
extends PsiRecursiveElementVisitor{
private final PsiParameter parameter;
public boolean isChecked(){
return checked;
}
private boolean checked = false;
public ParameterClassCheckVisitor(PsiParameter parameter){
super();
this.parameter = parameter;
}
public void visitMethodCallExpression(PsiMethodCallExpression expression){
super.visitMethodCallExpression(expression);
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
if(methodExpression == null)
{
return;
}
final String methodName = methodExpression.getReferenceName();
if(!"getClass".equals(methodName))
{
return;
}
final PsiExpressionList argList = expression.getArgumentList();
if(argList == null)
{
return;
}
final PsiExpression[] args = argList.getExpressions();
if(args == null || args.length!=0)
{
return;
}
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if(!isParameterReference(qualifier)){
return;
}
checked = true;
}
public void visitInstanceOfExpression(PsiInstanceOfExpression expression){
super.visitInstanceOfExpression(expression);
final PsiExpression operand = expression.getOperand();
if(!isParameterReference(operand))
{
return;
}
checked = true;
}
private boolean isParameterReference(PsiExpression operand){
if(operand == null){
return false;
}
if(!(operand instanceof PsiReferenceExpression)){
return false;
}
final PsiElement referent = ((PsiReference) operand).resolve();
if(referent == null){
return false;
}
return referent.equals(parameter);
}
}
@@ -11,9 +11,11 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.TypeUtils;
public class ResultSetIndexZeroInspection extends ExpressionInspection {
public String getID(){
return "UseOfIndexZeroInJDBCResultSet";
}
public String getDisplayName() {
return "Use on index 0 with JDBC ResultSet";
return "Use of index 0 in JDBC ResultSet";
}
public String getGroupDisplayName() {
@@ -14,6 +14,9 @@ import javax.swing.event.ChangeListener;
import java.awt.*;
public class ReturnNullInspection extends StatementInspection {
public String getID(){
return "ReturnOfNull";
}
public boolean m_reportObjectMethods = true;
public boolean m_reportArrayMethods = true;
@@ -9,6 +9,9 @@ import com.siyeh.ig.*;
import com.siyeh.ig.psiutils.ClassUtils;
public class StaticCallOnSubclassInspection extends ExpressionInspection {
public String getID(){
return "StaticMethodReferencedViaSubclass";
}
private final StaticCallOnSubclassFix fix = new StaticCallOnSubclassFix();
@@ -20,6 +23,10 @@ public class StaticCallOnSubclassInspection extends ExpressionInspection {
return GroupNames.BUGS_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) location.getParent().getParent();
final PsiMethod method = methodCall.resolveMethod();
@@ -11,6 +11,9 @@ import com.siyeh.ig.ui.SingleCheckboxOptionsPanel;
import javax.swing.*;
public class SwitchStatementsWithoutDefaultInspection extends StatementInspection {
public String getID(){
return "SwitchStatementWithoutDefaultBranch";
}
private boolean m_ignoreFullyCoveredEnums = true;
public String getDisplayName() {
@@ -12,6 +12,9 @@ import com.siyeh.ig.psiutils.ClassUtils;
public class ClassInTopLevelPackageInspection extends ClassInspection {
private final MoveClassFix fix = new MoveClassFix();
public String getID(){
return "ClassWithoutPackageStatement";
}
public String getDisplayName() {
return "Class without package statement";
}
@@ -9,6 +9,10 @@ import com.siyeh.ig.GroupNames;
public class ClassInitializerInspection extends ClassInspection {
public String getID(){
return "NonStaticInitializer";
}
public String getDisplayName() {
return "Non-static initializer";
}
@@ -0,0 +1,60 @@
package com.siyeh.ig.classlayout;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.psi.*;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.openapi.project.Project;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.FieldInspection;
import com.siyeh.ig.GroupNames;
public class FieldHasSetterButNoGetterInspection extends FieldInspection {
public String getDisplayName() {
return "Field has setter but no getter";
}
public String getGroupDisplayName() {
return GroupNames.CLASSLAYOUT_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
return "Field '#ref' has setter but no getter #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new StaticNonFinalFieldVisitor(this, inspectionManager, onTheFly);
}
private static class StaticNonFinalFieldVisitor extends BaseInspectionVisitor {
private StaticNonFinalFieldVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
super(inspection, inspectionManager, isOnTheFly);
}
public void visitField(PsiField field) {
final PsiManager psiManager = field.getManager();
final Project project = psiManager.getProject();
final String propertyName =
PropertyUtil.suggestPropertyName(project, field);
final boolean isStatic =
field.hasModifierProperty(PsiModifier.STATIC);
final PsiClass containingClass = field.getContainingClass();
final PsiMethod setter = PropertyUtil.findPropertySetter(containingClass,
propertyName, isStatic,
false);
if(setter==null){
return;
}
final PsiMethod getter =
PropertyUtil.findPropertyGetter(containingClass,
propertyName,
isStatic,
false);
if(getter != null){
return;
}
registerFieldError(field);
}
}
}
@@ -1,7 +1,6 @@
package com.siyeh.ig.classlayout;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiModifier;
@@ -9,8 +8,6 @@ import com.siyeh.ig.*;
import com.siyeh.ig.fixes.RemoveModifierFix;
public class FinalClassInspection extends MethodInspection {
private static final Logger s_logger =
Logger.getInstance("FinalClassInspection");
public String getDisplayName() {
return "'final' class";
@@ -1,7 +1,6 @@
package com.siyeh.ig.classlayout;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
@@ -9,8 +8,6 @@ import com.siyeh.ig.*;
import com.siyeh.ig.fixes.RemoveModifierFix;
public class FinalMethodInspection extends MethodInspection {
private static final Logger s_logger =
Logger.getInstance("FinalMethodnspection");
public String getDisplayName() {
return "'final' method";
@@ -16,6 +16,9 @@ public class FinalPrivateMethodInspection extends MethodInspection {
return GroupNames.CLASSLAYOUT_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "'private' method declared '#ref' #loc";
}
@@ -16,6 +16,10 @@ public class FinalStaticMethodInspection extends MethodInspection {
return GroupNames.CLASSLAYOUT_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "'static' method declared '#ref' #loc";
}
@@ -10,6 +10,9 @@ import com.siyeh.ig.psiutils.ClassUtils;
public class InnerClassOnInterfaceInspection extends ClassInspection {
private final MoveClassFix fix = new MoveClassFix();
public String getID(){
return "InnerClassOfInterface";
}
public String getDisplayName() {
return "Inner class of interface";
}
@@ -11,7 +11,7 @@ public class LimitedScopeInnerClassInspection extends ClassInspection {
private final MoveClassFix fix = new MoveClassFix();
public String getDisplayName() {
return "Limited-scope class";
return "Limited-scope inner class";
}
public String getGroupDisplayName() {
@@ -12,6 +12,9 @@ import com.siyeh.ig.ui.SingleCheckboxOptionsPanel;
import javax.swing.*;
public class NonProtectedConstructorInAbstractClassInspection extends MethodInspection {
public String getID(){
return "ConstructorNotProtectedInAbstractClass";
}
public boolean m_ignoreNonPublicClasses = false;
private final MakeProtectedFix fix = new MakeProtectedFix();
@@ -10,6 +10,9 @@ import com.siyeh.ig.fixes.MoveAnonymousToInnerClassFix;
public class AnonymousClassComplexityInspection
extends ClassMetricInspection {
public String getID(){
return "OverlyComplexAnonymousInnerClass";
}
private static final int DEFAULT_COMPLEXITY_LIMIT = 3;
private final MoveAnonymousToInnerClassFix fix = new MoveAnonymousToInnerClassFix();
@@ -10,6 +10,9 @@ import com.siyeh.ig.fixes.MoveAnonymousToInnerClassFix;
public class AnonymousClassMethodCountInspection
extends ClassMetricInspection {
public String getID(){
return "AnonymousInnerClassWithTooManyMethods";
}
private static final int DEFAULT_METHOD_COUNT_LIMIT = 1;
private final MoveAnonymousToInnerClassFix fix = new MoveAnonymousToInnerClassFix();
@@ -11,6 +11,9 @@ import com.siyeh.ig.GroupNames;
public class ClassComplexityInspection
extends ClassMetricInspection {
public String getID(){
return "OverlyComplexClass";
}
private static final int DEFAULT_COMPLEXITY_LIMIT = 80;
public String getDisplayName() {
@@ -18,9 +18,12 @@ import java.text.NumberFormat;
public class ClassCouplingInspection
extends ClassMetricInspection {
public String getID(){
return "OverlyCoupledClass";
}
private static final int DEFAULT_COUPLING_LIMIT = 15;
public boolean m_includeJavaClasses = false;
public boolean m_includeLibraryClasses = true;
public boolean m_includeLibraryClasses = false;
public String getDisplayName() {
return "Overly coupled class";
@@ -12,6 +12,9 @@ import java.util.Set;
public class ClassInheritanceDepthInspection
extends ClassMetricInspection {
public String getID(){
return "ClassTooDeepInInheritanceTree";
}
private static final int CLASS_INHERITANCE_LIMIT = 2;
public String getDisplayName() {
@@ -11,6 +11,9 @@ public class ClassNestingDepthInspection
extends ClassMetricInspection {
private static final int CLASS_NESTING_LIMIT = 1;
public String getID(){
return "InnerClassTooDeeplyNested";
}
public String getDisplayName() {
return "Inner class too deeply nested";
}
@@ -12,6 +12,9 @@ public class ConstructorCountInspection
extends ClassMetricInspection {
private static final int CONSTRUCTOR_COUNT_LIMIT = 5;
public String getID(){
return "ClassWithTooManyConstructors";
}
public String getDisplayName() {
return "Class with too many constructors";
}
@@ -21,6 +21,9 @@ public class FieldCountInspection
private static final int FIELD_COUNT_LIMIT = 10;
public boolean m_countConstantFields = false;
public String getID(){
return "ClassWithTooManyFields";
}
public String getDisplayName() {
return "Class with too many fields";
}
@@ -12,6 +12,9 @@ public class MethodCountInspection
extends ClassMetricInspection {
private static final int DEFAULT_METHOD_COUNT_LIMIT = 20;
public String getID(){
return "ClassWithTooManyMethods";
}
public String getDisplayName() {
return "Class with too many methods";
}
@@ -8,7 +8,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.MethodInspection;
public class CloneCallsSuperCloneInspection extends MethodInspection {
public String getID(){
return "CloneDoesntCallSuperClone";
}
public String getDisplayName() {
return "clone() doesn't call super.clone()";
}
@@ -12,6 +12,9 @@ import com.siyeh.ig.*;
public class CloneDeclaresCloneNotSupportedInspection extends MethodInspection {
private final CloneDeclaresCloneNotSupportedInspectionFix fix = new CloneDeclaresCloneNotSupportedInspectionFix();
public String getID(){
return "CloneDoesntDeclareCloneNotSupportedException";
}
public String getDisplayName() {
return "clone() doesn't declare CloneNotSupportedException";
}
@@ -14,6 +14,9 @@ import com.siyeh.ig.ui.SingleCheckboxOptionsPanel;
import javax.swing.*;
public class CloneableImplementsCloneInspection extends ClassInspection {
public String getID(){
return "CloneableClassWithoutClone";
}
public boolean m_ignoreCloneableDueToInheritance = false;
public String getDisplayName() {
@@ -14,6 +14,7 @@ import com.siyeh.ig.psiutils.WellFormednessUtils;
public class AssignmentToCatchBlockParameterInspection
extends ExpressionInspection{
private AssignmentToCatchBlockParameterFix fix =
new AssignmentToCatchBlockParameterFix();
@@ -25,6 +25,9 @@ public class CastThatLosesPrecisionInspection extends StatementInspection {
s_typePrecisions.put("double", new Integer(6));
}
public String getID(){
return "NumericCastThatLosesPrecision";
}
public String getDisplayName() {
return "Numeric cast that loses precision";
}
@@ -10,7 +10,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.WellFormednessUtils;
public class ChainedEqualityInspection extends ExpressionInspection {
public String getID(){
return "ChainedEqualityComparisons";
}
public String getDisplayName() {
return "Chained equality comparisons";
}
@@ -12,7 +12,9 @@ import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.ControlFlowUtils;
public class ConfusingElseInspection extends StatementInspection {
public String getID(){
return "ConfusingElseBranch";
}
public String getDisplayName() {
return "Confusing else branch";
}
@@ -10,7 +10,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.TypeUtils;
public class ConfusingOctalEscapeInspection extends ExpressionInspection {
public String getID(){
return "ConfusingOctalEscapeSequence";
}
public String getDisplayName() {
return "Confusing octal escape sequence";
}
@@ -31,7 +31,7 @@ public class ImplicitNumericConversionInspection extends ExpressionInspection {
public boolean m_ignoreWideningConversions = false;
public String getDisplayName() {
return "Implicit numeric conversions";
return "Implicit numeric conversion";
}
public String getGroupDisplayName() {
@@ -9,7 +9,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class IncrementDecrementUsedAsExpressionInspection extends ExpressionInspection {
public String getID(){
return "ValueOfIncrementOrDecrementUsed";
}
public String getDisplayName() {
return "Value of ++ or -- used";
}
@@ -12,6 +12,10 @@ import com.siyeh.ig.*;
public class LongLiteralsEndingWithLowercaseLInspection extends ExpressionInspection {
private final LongLiteralFix fix = new LongLiteralFix();
public String getID(){
return "LongLiteralEndingWithLowercaseL";
}
public String getDisplayName() {
return "Long literal ending with 'l' instead of 'L'";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.*;
import com.siyeh.ig.fixes.RenameFix;
public class MethodNamesDifferOnlyByCaseInspection extends MethodInspection {
public String getID(){
return "MethodNamesDifferingOnlyByCase";
}
private final RenameFix fix = new RenameFix();
public String getDisplayName() {
@@ -15,6 +15,10 @@ public class NegatedConditionalInspection extends ExpressionInspection{
public boolean m_ignoreNegatedNullComparison = true;
private final NegatedConditionalFix fix = new NegatedConditionalFix();
public String getID(){
return "ConditionalExpressionWithNegatedCondition";
}
public String getDisplayName(){
return "Conditional expression with negated condition";
}
@@ -15,6 +15,10 @@ public class NegatedIfElseInspection extends StatementInspection {
public boolean m_ignoreNegatedNullComparison = true;
private final NegatedIfElseFix fix = new NegatedIfElseFix();
public String getID(){
return "IfStatementWithNegatedCondition";
}
public String getDisplayName() {
return "If statement with negated condition";
}
@@ -17,7 +17,7 @@ public class NestedMethodCallInspection extends ExpressionInspection {
private final NestedMethodCallFix fix = new NestedMethodCallFix();
public String getDisplayName() {
return "Nested method calls";
return "Nested method call";
}
public String getGroupDisplayName() {
@@ -10,7 +10,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class OctalLiteralInspection extends ExpressionInspection {
public String getID(){
return "OctalInteger";
}
public String getDisplayName() {
return "Octal integer";
}
@@ -11,66 +11,81 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class SwitchStatementWithConfusingDeclarationInspection extends StatementInspection {
public String getDisplayName() {
public class SwitchStatementWithConfusingDeclarationInspection
extends StatementInspection{
public String getID(){
return "LocalVariableUsedAndDeclaredInDifferentSwitchBranches";
}
public String getDisplayName(){
return "Local variable used and declared in different 'switch' branches";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.CONFUSING_GROUP_NAME;
}
protected String buildErrorString(PsiElement location) {
protected String buildErrorString(PsiElement location){
return "Local variable #ref declared in one switch branch and used in another #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new SwitchStatementWithConfusingDeclarationVisitor(this, inspectionManager, onTheFly);
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new SwitchStatementWithConfusingDeclarationVisitor(this,
inspectionManager,
onTheFly);
}
private static class SwitchStatementWithConfusingDeclarationVisitor extends BaseInspectionVisitor {
private SwitchStatementWithConfusingDeclarationVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
private static class SwitchStatementWithConfusingDeclarationVisitor
extends BaseInspectionVisitor{
private SwitchStatementWithConfusingDeclarationVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitSwitchStatement(PsiSwitchStatement statement) {
public void visitSwitchStatement(PsiSwitchStatement statement){
final Set variablesInCurrentBranch = new HashSet(10);
final Set variablesInPreviousBranches = new HashSet(10);
final PsiCodeBlock body = statement.getBody();
if (body == null) {
if(body == null){
return;
}
final PsiStatement[] statements = body.getStatements();
for (int i = 0; i < statements.length; i++) {
for(int i = 0; i < statements.length; i++){
final PsiStatement child = statements[i];
if (child instanceof PsiDeclarationStatement) {
final PsiDeclarationStatement declaration = (PsiDeclarationStatement) child;
final PsiElement[] declaredElements = declaration.getDeclaredElements();
for (int j = 0; j < declaredElements.length; j++) {
if(child instanceof PsiDeclarationStatement){
final PsiDeclarationStatement declaration =
(PsiDeclarationStatement) child;
final PsiElement[] declaredElements =
declaration.getDeclaredElements();
for(int j = 0; j < declaredElements.length; j++){
final PsiElement declaredElement = declaredElements[j];
if (declaredElement instanceof PsiLocalVariable) {
final PsiLocalVariable localVar = (PsiLocalVariable) declaredElement;
if(declaredElement instanceof PsiLocalVariable){
final PsiLocalVariable localVar =
(PsiLocalVariable) declaredElement;
variablesInCurrentBranch.add(localVar);
}
}
}
if (child instanceof PsiBreakStatement) {
if(child instanceof PsiBreakStatement){
variablesInPreviousBranches.addAll(variablesInCurrentBranch);
variablesInCurrentBranch.clear();
}
final LocalVariableAccessVisitor visitor = new LocalVariableAccessVisitor();
final LocalVariableAccessVisitor visitor =
new LocalVariableAccessVisitor();
child.accept(visitor);
final Set accessedVariables = visitor.getAccessedVariables();
for (Iterator iterator = accessedVariables.iterator(); iterator.hasNext();) {
final PsiLocalVariable localVar = (PsiLocalVariable) iterator.next();
if (variablesInPreviousBranches.contains(localVar)) {
for(Iterator iterator = accessedVariables.iterator();
iterator.hasNext();){
final PsiLocalVariable localVar =
(PsiLocalVariable) iterator.next();
if(variablesInPreviousBranches.contains(localVar)){
variablesInPreviousBranches.remove(localVar);
registerVariableError(localVar);
}
}
}
}
}
}
@@ -12,6 +12,9 @@ import com.siyeh.ig.psiutils.WellFormednessUtils;
public class AssignmentToCollectionFieldFromParameterInspection
extends ExpressionInspection{
public String getID(){
return "AssignmentToCollectionOrArrayFieldFromParameter";
}
public String getDisplayName(){
return "Assignment to Collection or array field from parameter";
@@ -9,6 +9,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.CollectionUtils;
public class ReturnOfCollectionFieldInspection extends ExpressionInspection{
public String getID(){
return "ReturnOfCollectionOrArrayField";
}
public String getDisplayName(){
return "Return of Collection or array field";
@@ -28,7 +31,6 @@ public class ReturnOfCollectionFieldInspection extends ExpressionInspection{
}
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new ReturnOfCollectionFieldVisitor(this, inspectionManager,
@@ -8,7 +8,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class UseOfAnotherObjectsPrivateFieldInspection extends ExpressionInspection {
public String getID(){
return "AccessingNonPublicFieldOfAnotherObject";
}
public String getDisplayName() {
return "Accessing a non-public field of another object";
}
@@ -65,6 +65,9 @@ public class BadExceptionCaughtInspection extends ExpressionInspection {
exceptionCheckString = buffer.toString();
}
public String getID(){
return "ProhibittedExceptionCaught";
}
public String getDisplayName() {
return "Prohibitted exception caught";
}
@@ -68,6 +68,9 @@ public class BadExceptionDeclaredInspection extends MethodInspection {
exceptionCheckString = buffer.toString();
}
public String getID(){
return "ProhibittedExceptionDeclared";
}
public String getDisplayName() {
return "Prohibitted exception declared";
}
@@ -71,6 +71,10 @@ public class BadExceptionThrownInspection extends ExpressionInspection {
exceptionCheckString = buffer.toString();
}
public String getID(){
return "ProhibittedExceptionThrown";
}
public String getDisplayName() {
return "Prohibitted exception thrown";
}
@@ -21,6 +21,9 @@ public class ContinueOrBreakFromFinallyBlockInspection extends StatementInspecti
return GroupNames.ERRORHANDLING_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "'#ref' inside 'finally' block #loc";
}
@@ -11,7 +11,9 @@ import com.siyeh.ig.psiutils.ClassUtils;
import com.siyeh.ig.psiutils.TypeUtils;
public class ErrorRethrownInspection extends StatementInspection {
public String getID(){
return "ErrorNotRethrown";
}
public String getDisplayName() {
return "Error not rethrown";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.ControlFlowUtils;
public class ExceptionFromCatchWhichDoesntWrapInspection extends StatementInspection {
public String getID(){
return "ThrowInsideCatchBlockWhichIgnoresCaughtException";
}
public String getDisplayName() {
return "'throw' inside 'catch' block which ignores the caught exception";
}
@@ -9,37 +9,47 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.ControlFlowUtils;
public class ReturnFromFinallyBlockInspection extends StatementInspection {
public class ReturnFromFinallyBlockInspection extends StatementInspection{
public String getID(){
return "ReturnInsideFinallyBlock";
}
public String getDisplayName() {
public String getDisplayName(){
return "'return' inside 'finally' block";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.ERRORHANDLING_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location){
return "'#ref' inside 'finally' block #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new ReturnFromFinallyBlockVisitor(this, inspectionManager, onTheFly);
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new ReturnFromFinallyBlockVisitor(this, inspectionManager,
onTheFly);
}
private static class ReturnFromFinallyBlockVisitor extends BaseInspectionVisitor {
private ReturnFromFinallyBlockVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
private static class ReturnFromFinallyBlockVisitor
extends BaseInspectionVisitor{
private ReturnFromFinallyBlockVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitReturnStatement(PsiReturnStatement statement) {
public void visitReturnStatement(PsiReturnStatement statement){
super.visitReturnStatement(statement);
if (!ControlFlowUtils.isInFinallyBlock(statement)) {
if(!ControlFlowUtils.isInFinallyBlock(statement)){
return;
}
registerStatementError(statement);
}
}
}
@@ -8,71 +8,84 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.StatementInspection;
import com.siyeh.ig.psiutils.TypeUtils;
public class ThreadDeathRethrownInspection extends StatementInspection {
public class ThreadDeathRethrownInspection extends StatementInspection{
public String getID(){
return "ThreadDeathNotRethrown";
}
public String getDisplayName() {
public String getDisplayName(){
return "ThreadDeath not rethrown";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.ERRORHANDLING_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
public String buildErrorString(PsiElement location){
return "#ref not rethrown #loc";
}
protected BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
return new ThreadDeathRethrownVisitor(this, inspectionManager, onTheFly);
protected BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new ThreadDeathRethrownVisitor(this, inspectionManager,
onTheFly);
}
private static class ThreadDeathRethrownVisitor extends BaseInspectionVisitor {
private ThreadDeathRethrownVisitor(BaseInspection inspection, InspectionManager inspectionManager, boolean isOnTheFly) {
private static class ThreadDeathRethrownVisitor
extends BaseInspectionVisitor{
private ThreadDeathRethrownVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitTryStatement(PsiTryStatement statement) {
public void visitTryStatement(PsiTryStatement statement){
super.visitTryStatement(statement);
PsiCatchSection[] catchSections = statement.getCatchSections();
for (int i = 0; i < catchSections.length; i++) {
for(int i = 0; i < catchSections.length; i++){
final PsiParameter parameter = catchSections[i].getParameter();
final PsiCodeBlock catchBlock = catchSections[i].getCatchBlock();
if (parameter == null || catchBlock == null) continue;
final PsiCodeBlock catchBlock =
catchSections[i].getCatchBlock();
if(parameter == null || catchBlock == null){
continue;
}
checkCatchBlock(parameter, catchBlock);
}
}
private void checkCatchBlock(PsiParameter parameter, PsiCodeBlock catchBlock) {
private void checkCatchBlock(PsiParameter parameter,
PsiCodeBlock catchBlock){
final PsiType type = parameter.getType();
if (!TypeUtils.typeEquals("java.lang.ThreadDeath", type)) {
if(!TypeUtils.typeEquals("java.lang.ThreadDeath", type)){
return;
}
final PsiTypeElement typeElement = parameter.getTypeElement();
if (typeElement == null) {
if(typeElement == null){
return;
}
final PsiStatement[] statements = catchBlock.getStatements();
if (statements.length == 0) {
if(statements.length == 0){
registerError(typeElement);
return;
}
final PsiStatement lastStatement = statements[statements.length - 1];
if (!(lastStatement instanceof PsiThrowStatement)) {
final PsiStatement lastStatement =
statements[statements.length - 1];
if(!(lastStatement instanceof PsiThrowStatement)){
registerError(typeElement);
return;
}
final PsiThrowStatement throwStatement = (PsiThrowStatement) lastStatement;
final PsiThrowStatement throwStatement =
(PsiThrowStatement) lastStatement;
final PsiExpression exception = throwStatement.getException();
if (!(exception instanceof PsiReferenceExpression)) {
if(!(exception instanceof PsiReferenceExpression)){
registerError(typeElement);
return;
}
final PsiElement element = ((PsiReference) exception).resolve();
if (!element.equals(parameter)) {
if(!element.equals(parameter)){
registerError(typeElement);
return;
}
}
}
}
@@ -19,6 +19,9 @@ public class ThrowFromFinallyBlockInspection extends StatementInspection {
return GroupNames.ERRORHANDLING_GROUP_NAME;
}
public boolean isEnabledByDefault(){
return true;
}
public String buildErrorString(PsiElement location) {
return "'#ref' inside 'finally' block #loc";
}
@@ -13,7 +13,9 @@ import java.util.Iterator;
import java.util.Set;
public class TooBroadCatchInspection extends StatementInspection {
public String getID(){
return "OverlyBroadCatchBlock";
}
public String getDisplayName() {
return "Overly broad 'catch' block";
}
@@ -10,7 +10,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.MethodInspection;
public class FinalizeCallsSuperFinalizeInspection extends MethodInspection {
public String getID(){
return "FinalizeDoesntCallSuperFinalize";
}
public String getDisplayName() {
return "finalize() doesn't call super.finalize()";
}
@@ -10,9 +10,12 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.MethodInspection;
public class FinalizeInspection extends MethodInspection {
public String getID(){
return "FinalizeDeclaration";
}
public String getDisplayName() {
return "Use of finalize()";
return "'finalize()' declaration";
}
public String getGroupDisplayName() {
@@ -9,9 +9,11 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class NoExplicitFinalizeCallsInspection extends ExpressionInspection {
public String getID(){
return "Finalize called explicitly";
}
public String getDisplayName() {
return "finalize() called explicitly";
return "'finalize()' called explicitly";
}
public String getGroupDisplayName() {
@@ -0,0 +1,30 @@
package com.siyeh.ig.fixes;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.psi.PsiMethodCallExpression;
import com.intellij.refactoring.RefactoringActionHandler;
import com.intellij.refactoring.RefactoringActionHandlerFactory;
import com.siyeh.ig.InspectionGadgetsFix;
public class InlineCallFix extends InspectionGadgetsFix {
public String getName() {
return "Inline call";
}
public void applyFix(Project project, ProblemDescriptor descriptor) {
if(isQuickFixOnReadOnlyFile(project, descriptor)) return;
final PsiElement nameElement = descriptor.getPsiElement();
final PsiReferenceExpression methodExpression =
(PsiReferenceExpression) nameElement.getParent();
final PsiMethodCallExpression methodCallExpression =
(PsiMethodCallExpression) methodExpression.getParent();
final RefactoringActionHandlerFactory factory =
RefactoringActionHandlerFactory.getInstance();
final RefactoringActionHandler inlineHandler = factory.createInlineHandler();
inlineHandler.invoke(project, new PsiElement[]{methodCallExpression}, null);
}
}
@@ -112,12 +112,12 @@ public class MemberSignature implements Comparable
public int compareTo(Object object)
{
final MemberSignature other = (MemberSignature)object;
int result = getName().compareTo(other.getName());
if (result == 0)
final int result = name.compareTo(other.name);
if (result != 0)
{
result = getSignature().compareTo(other.getSignature());
return result;
}
return result;
return signature.compareTo(other.signature);
}
public static String createMethodSignature(PsiMethod method)
@@ -305,6 +305,6 @@ public class MemberSignature implements Comparable
public String toString()
{
return getName() + getSignature();
return name + signature;
}
}
@@ -16,6 +16,9 @@ import javax.swing.*;
public class InstanceVariableInitializationInspection extends FieldInspection {
public boolean m_ignorePrimitives = false;
public String getID(){
return "InstanceVariableMayNotBeInitialized";
}
public String getDisplayName() {
return "Instance variable may not be initialized";
}
@@ -18,6 +18,9 @@ public class InstanceVariableUninitializedUseInspection
extends FieldInspection {
public boolean m_ignorePrimitives = false;
public String getID(){
return "InstanceVariableUsedBeforeInitialized";
}
public String getDisplayName() {
return "Instance variable used before initialized";
}
@@ -15,6 +15,9 @@ import javax.swing.*;
public class StaticVariableInitializationInspection extends FieldInspection {
public boolean m_ignorePrimitives = false;
public String getID(){
return "StaticVariableMayNotBeInitialized";
}
public String getDisplayName() {
return "Static variable may not be initialized";
}
@@ -16,6 +16,9 @@ import java.util.List;
public class StaticVariableUninitializedUseInspection extends FieldInspection {
public boolean m_ignorePrimitives = false;
public String getID(){
return "StaticVariableUsedBeforeInitialization";
}
public String getDisplayName() {
return "Static variable used before initialization";
}
@@ -10,38 +10,43 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.ClassUtils;
import com.siyeh.ig.psiutils.WellFormednessUtils;
public class ThisEscapedInConstructorInspection extends ClassInspection {
public class ThisEscapedInConstructorInspection extends ClassInspection{
public String getID(){
return "ThisEscapedInObjectConstruction";
}
public String getDisplayName() {
public String getDisplayName(){
return "'this' reference escaped in object construction";
}
public String getGroupDisplayName() {
public String getGroupDisplayName(){
return GroupNames.INITIALIZATION_GROUP_NAME;
}
public String buildErrorString(PsiElement location) {
public String buildErrorString(PsiElement location){
return "Escape of '#ref' during object construction #loc";
}
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
boolean onTheFly){
return new ThisExposedInConstructorInspectionVisitor(this,
inspectionManager,
onTheFly);
inspectionManager,
onTheFly);
}
private static class ThisExposedInConstructorInspectionVisitor
extends BaseInspectionVisitor {
extends BaseInspectionVisitor{
private boolean m_inClass = false;
private ThisExposedInConstructorInspectionVisitor(BaseInspection inspection, InspectionManager inspectionManager,
boolean isOnTheFly) {
private ThisExposedInConstructorInspectionVisitor(BaseInspection inspection,
InspectionManager inspectionManager,
boolean isOnTheFly){
super(inspection, inspectionManager, isOnTheFly);
}
public void visitClass(PsiClass aClass) {
public void visitClass(PsiClass aClass){
final boolean wasInClass = m_inClass;
if (!m_inClass) {
if(!m_inClass){
m_inClass = true;
super.visitClass(aClass);
@@ -49,31 +54,36 @@ public class ThisEscapedInConstructorInspection extends ClassInspection {
m_inClass = wasInClass;
}
public void visitNewExpression(PsiNewExpression psiNewExpression) {
public void visitNewExpression(PsiNewExpression psiNewExpression){
super.visitNewExpression(psiNewExpression);
final boolean isInInitialization = checkForInitialization(psiNewExpression);
if (!isInInitialization) {
final boolean isInInitialization =
checkForInitialization(psiNewExpression);
if(!isInInitialization){
return;
}
if (psiNewExpression.getClassReference() == null) {
if(psiNewExpression.getClassReference() == null){
return;
}
final PsiThisExpression thisExposed = checkArgumentsForThis(psiNewExpression);
if (thisExposed == null) {
final PsiThisExpression thisExposed =
checkArgumentsForThis(psiNewExpression);
if(thisExposed == null){
return;
}
final PsiJavaCodeReferenceElement refElement = psiNewExpression.getClassReference();
if (refElement != null) {
final PsiClass constructorClass = (PsiClass) refElement.resolve();
final PsiJavaCodeReferenceElement refElement =
psiNewExpression.getClassReference();
if(refElement != null){
final PsiClass constructorClass =
(PsiClass) refElement.resolve();
if (constructorClass != null) {
if(constructorClass != null){
// Skips inner classes and containing classes (as well as top level package class with file-named class)
if (constructorClass.getContainingFile().equals(psiNewExpression.getContainingFile())) {
if(constructorClass.getContainingFile()
.equals(psiNewExpression.getContainingFile())){
return;
}
}
@@ -82,97 +92,107 @@ public class ThisEscapedInConstructorInspection extends ClassInspection {
registerError(thisExposed);
}
public void visitAssignmentExpression(PsiAssignmentExpression assignment) {
public void visitAssignmentExpression(PsiAssignmentExpression assignment){
super.visitAssignmentExpression(assignment);
if(!WellFormednessUtils.isWellFormed(assignment)){
return;
}
final boolean isInInitialization = checkForInitialization(assignment);
if (!isInInitialization) {
final boolean isInInitialization =
checkForInitialization(assignment);
if(!isInInitialization){
return;
}
final PsiExpression psiExpression = getLastRightExpression(assignment);
final PsiExpression psiExpression =
getLastRightExpression(assignment);
if (psiExpression == null ||
!(psiExpression instanceof PsiThisExpression)) {
if(psiExpression == null ||
!(psiExpression instanceof PsiThisExpression)){
return;
}
final PsiThisExpression thisExpression = (PsiThisExpression) psiExpression;
final PsiThisExpression thisExpression =
(PsiThisExpression) psiExpression;
// Need to confirm that LeftExpression is outside of class relatives
if (!(assignment.getLExpression() instanceof PsiReferenceExpression)) {
if(!(assignment.getLExpression() instanceof PsiReferenceExpression)){
return;
}
final PsiReferenceExpression leftExpression = (PsiReferenceExpression) assignment.getLExpression();
if (!(leftExpression.resolve() instanceof PsiField)) {
final PsiReferenceExpression leftExpression =
(PsiReferenceExpression) assignment.getLExpression();
if(!(leftExpression.resolve() instanceof PsiField)){
return;
}
final PsiField field = (PsiField) leftExpression.resolve();
if (field.getContainingFile().equals(assignment.getContainingFile())) {
if(field.getContainingFile()
.equals(assignment.getContainingFile())){
return;
}
// Inheritance check
final PsiClass cls = ClassUtils.getContainingClass(assignment);
if (cls.isInheritor(field.getContainingClass(), true)) {
if(cls.isInheritor(field.getContainingClass(), true)){
return;
}
registerError(thisExpression);
}
public void visitMethodCallExpression(PsiMethodCallExpression call) {
public void visitMethodCallExpression(PsiMethodCallExpression call){
super.visitMethodCallExpression(call);
final boolean isInInitialization = checkForInitialization(call);
if (!isInInitialization) {
if(!isInInitialization){
return;
}
final PsiReferenceExpression methodExpression = call.getMethodExpression();
if (methodExpression == null) {
final PsiReferenceExpression methodExpression =
call.getMethodExpression();
if(methodExpression == null){
return;
}
final PsiMethod calledMethod = call.resolveMethod();
if (calledMethod == null) {
if(calledMethod == null){
return;
}
if (calledMethod.isConstructor()) {
if(calledMethod.isConstructor()){
return;
}
final PsiClass calledMethodClass = calledMethod.getContainingClass();
final PsiClass methodClass = (PsiClass) PsiTreeUtil.getParentOfType(call, PsiClass.class);
final PsiClass calledMethodClass =
calledMethod.getContainingClass();
final PsiClass methodClass =
(PsiClass) PsiTreeUtil.getParentOfType(call,
PsiClass.class);
if (calledMethodClass.equals(methodClass)) // compares class types statically?
if(calledMethodClass.equals(methodClass)) // compares class types statically?
{
return;
}
final PsiThisExpression thisExposed = checkArgumentsForThis(call);
if (thisExposed == null) {
if(thisExposed == null){
return;
}
// Methods - static or not - from superclasses don't trigger
if (methodClass.isInheritor(calledMethodClass, true)) {
if(methodClass.isInheritor(calledMethodClass, true)){
return;
}
// Make sure using this with members of self or superclasses doesn't trigger
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (!(qualifier instanceof PsiReferenceExpression)) {
final PsiExpression qualifier =
methodExpression.getQualifierExpression();
if(!(qualifier instanceof PsiReferenceExpression)){
return;
}
final PsiReferenceExpression qualifiedExpression =
(PsiReferenceExpression) qualifier;
final PsiElement referent = qualifiedExpression.resolve();
if (referent instanceof PsiField) {
if(referent instanceof PsiField){
final PsiField field = (PsiField) referent;
final PsiClass containingClass = field.getContainingClass();
if (methodClass.equals(containingClass) ||
methodClass.isInheritor(containingClass, true)) {
if(methodClass.equals(containingClass) ||
methodClass.isInheritor(containingClass, true)){
return;
}
}
@@ -181,60 +201,66 @@ public class ThisEscapedInConstructorInspection extends ClassInspection {
}
// Get rightmost expression of assignment. Used when assignments are chained. Recursive
private static PsiExpression getLastRightExpression(PsiAssignmentExpression assignmentExp) {
private static PsiExpression getLastRightExpression(PsiAssignmentExpression assignmentExp){
if (assignmentExp == null) {
if(assignmentExp == null){
return null;
}
final PsiExpression expression = assignmentExp.getRExpression();
if (expression == null) {
if(expression == null){
return null;
}
if (expression instanceof PsiAssignmentExpression) {
if(expression instanceof PsiAssignmentExpression){
return getLastRightExpression((PsiAssignmentExpression) expression);
}
return expression;
}
/**
* @param call
* @return true if CallExpression is in a constructor, instance
* initializer, or field initializaer. Otherwise it returns false
*/
private static boolean checkForInitialization(PsiElement call) {
final PsiMethod method = (PsiMethod) PsiTreeUtil.getParentOfType(call, PsiMethod.class);
if (method != null) {
* @param call
* @return true if CallExpression is in a constructor, instance
* initializer, or field initializaer. Otherwise it returns
* false
*/
private static boolean checkForInitialization(PsiElement call){
final PsiMethod method =
(PsiMethod) PsiTreeUtil.getParentOfType(call,
PsiMethod.class);
if(method != null){
return method.isConstructor();
}
final PsiField field = (PsiField) PsiTreeUtil.getParentOfType(call, PsiField.class);
if (field != null) {
final PsiField field =
(PsiField) PsiTreeUtil.getParentOfType(call,
PsiField.class);
if(field != null){
return true;
}
final PsiClassInitializer classInitializer = (PsiClassInitializer) PsiTreeUtil.getParentOfType(call, PsiClassInitializer.class);
if (classInitializer != null) {
final PsiClassInitializer classInitializer =
(PsiClassInitializer) PsiTreeUtil.getParentOfType(call,
PsiClassInitializer.class);
if(classInitializer != null){
return !classInitializer.hasModifierProperty(PsiModifier.STATIC);
}
return false;
return false;
}
// If there are more than two of 'this' as arguments, only marks the first until it is removed. No big deal.
private static PsiThisExpression checkArgumentsForThis(PsiCall call) {
private static PsiThisExpression checkArgumentsForThis(PsiCall call){
final PsiExpressionList peList = call.getArgumentList();
if (peList == null) { // array initializer
if(peList == null){ // array initializer
return null;
}
final PsiExpression[] argExpressions = peList.getExpressions();
for (int i = 0; i < argExpressions.length; i++) {
for(int i = 0; i < argExpressions.length; i++){
final PsiExpression argExpression = argExpressions[i];
if (argExpression instanceof PsiThisExpression) {
if(argExpression instanceof PsiThisExpression){
return (PsiThisExpression) argExpression;
}
}
return null;
}
}
}
@@ -13,7 +13,9 @@ import com.siyeh.ig.psiutils.ComparisonUtils;
import com.siyeh.ig.psiutils.WellFormednessUtils;
public class CharacterComparisonInspection extends ExpressionInspection {
public String getID(){
return "CharacterComparison";
}
public String getDisplayName() {
return "Character comparison";
}
@@ -13,7 +13,9 @@ import com.siyeh.ig.psiutils.MethodCallUtils;
import com.siyeh.ig.psiutils.TypeUtils;
public class DateToStringInspection extends ExpressionInspection {
public String getID(){
return "CallToDateToString";
}
public String getDisplayName() {
return "Call to Date.toString()";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class NumericToStringInspection extends ExpressionInspection {
public String getID(){
return "CallToNumericToString";
}
public String getDisplayName() {
return "Call to Numeric .toString()";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.TypeUtils;
public class StringCompareToInspection extends ExpressionInspection {
public String getID(){
return "CallToStringCompareTo";
}
public String getDisplayName() {
return "Call to String.compareTo()";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.TypeUtils;
public class StringEqualsIgnoreCaseInspection extends ExpressionInspection {
public String getID(){
return "CallToStringEqualsIgnoreCase";
}
public String getDisplayName() {
return "Call to String.equalsIgnoreCase()";
}
@@ -9,7 +9,9 @@ import com.siyeh.ig.GroupNames;
import com.siyeh.ig.psiutils.TypeUtils;
public class StringEqualsInspection extends ExpressionInspection {
public String getID(){
return "CallToStringEquals";
}
public String getDisplayName() {
return "Call to String.equals()";
}
@@ -8,7 +8,9 @@ import com.siyeh.ig.ExpressionInspection;
import com.siyeh.ig.GroupNames;
public class StringToUpperWithoutLocaleInspection extends ExpressionInspection {
public String getID(){
return "StringToUpperCaseOrToLowerCaseWithoutLocale";
}
public String getDisplayName() {
return "Call to String.toUpperCase() or .toLowerCase() without a Locale";
}

Some files were not shown because too many files have changed in this diff Show More