mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 09:03:31 +07:00
(no message)
This commit is contained in:
@@ -8,16 +8,15 @@
|
||||
Paired open/close for Sockets
|
||||
Paired open/close for Channels
|
||||
Paired acquire/release for Locks
|
||||
Duplicate condition
|
||||
Empty zip file entry
|
||||
Empty jar file entry
|
||||
getClass().getResource()
|
||||
Inefficient use of keySet iterator rather than entrySet iterator
|
||||
Encapsulatable use of field
|
||||
|
||||
Static inheritance quickfix
|
||||
Static import quickfix
|
||||
Vararg quickfix
|
||||
Non non-static initializer quickfix
|
||||
Fix the "variable accessed in synchronized and unsynchronized contexts"
|
||||
to deal with unsynchronized private methods called only from synchronized contexts
|
||||
to deal with unsynchronized private methods called only from synchronized contexts
|
||||
Telemetry
|
||||
@@ -15,5 +15,10 @@
|
||||
<implementation-class>com.siyeh.ig.InspectionGadgetsPlugin</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
<project-components>
|
||||
<component>
|
||||
<implementation-class>com.siyeh.ig.InspectionGadgetsProjectComponent</implementation-class>
|
||||
</component>
|
||||
</project-components>
|
||||
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,32 @@
|
||||
50 unused import
|
||||
19 implicit numeric conversion
|
||||
17 method may be static
|
||||
15 unnecessary funlly qualified name
|
||||
11 infinite recursion
|
||||
11 Accessing a non-public class of another object
|
||||
11 Class references subclass
|
||||
10 JDBC resource opened but not safely closed
|
||||
8 Non-synchronized method overrides synchronized method
|
||||
8 Overly coupled class
|
||||
7 Overly coupled method
|
||||
7 c-style array declaration
|
||||
7 mismatched query and update of collection
|
||||
6 Collection declared by class not interface
|
||||
6 Field accessed by synchronized and unsynchronized
|
||||
6 raw use of parameterized class
|
||||
5 Pointless bitwise expression
|
||||
5 use of obsolete collection type
|
||||
4 casting to incompatible interface
|
||||
4 concatenation with empty string
|
||||
4 constant string buffer may be string
|
||||
4 non-constant string should be stringBuffer
|
||||
4 method overrides private method of superclass
|
||||
4 pointless arithmetic expression
|
||||
4 static method accessed via subclass
|
||||
4 use of java.lang.reflect
|
||||
3 readObject or writeObject not private
|
||||
3 readResolve or writeReplace not protected
|
||||
3 setup instead of setUp()
|
||||
3 comparison of short and char
|
||||
3 overly strong type cast
|
||||
3 pointless boolean expression
|
||||
@@ -2,12 +2,19 @@ package com.siyeh.ig;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public abstract class BaseInspection extends LocalInspectionTool {
|
||||
private final String m_shortName = null;
|
||||
private InspectionRunListener listener = null;
|
||||
|
||||
public String getShortName() {
|
||||
if (m_shortName == null) {
|
||||
@@ -37,6 +44,73 @@ public abstract class BaseInspection extends LocalInspectionTool {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
bindListener();
|
||||
final long start = System.currentTimeMillis();
|
||||
try{
|
||||
return doCheckMethod(method, manager, isOnTheFly);
|
||||
} finally{
|
||||
final long end = System.currentTimeMillis();
|
||||
listener.reportRun(getDisplayName(), end-start);
|
||||
}
|
||||
}
|
||||
|
||||
protected ProblemDescriptor[] doCheckMethod(PsiMethod method,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
return super.checkMethod(method, manager, isOnTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
bindListener();
|
||||
final long start = System.currentTimeMillis();
|
||||
try{
|
||||
return doCheckClass(aClass, manager, isOnTheFly);
|
||||
} finally{
|
||||
final long end = System.currentTimeMillis();
|
||||
listener.reportRun(getDisplayName(), end - start);
|
||||
}
|
||||
}
|
||||
|
||||
protected ProblemDescriptor[] doCheckClass(PsiClass aClass,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
return super.checkClass(aClass, manager, isOnTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
bindListener();
|
||||
final long start = System.currentTimeMillis();
|
||||
try{
|
||||
return doCheckField(field, manager, isOnTheFly);
|
||||
} finally{
|
||||
final long end = System.currentTimeMillis();
|
||||
listener.reportRun(getDisplayName(), end - start);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindListener(){
|
||||
if(listener== null)
|
||||
{
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
final InspectionGadgetsPlugin plugin =
|
||||
(InspectionGadgetsPlugin) application.getComponent("InspectionGadgets");
|
||||
listener = plugin.getTelemetry();
|
||||
}
|
||||
}
|
||||
|
||||
protected ProblemDescriptor[] doCheckField(PsiField field,
|
||||
InspectionManager manager,
|
||||
boolean isOnTheFly){
|
||||
return super.checkField(field, manager, isOnTheFly);
|
||||
}
|
||||
|
||||
public boolean hasQuickFix() {
|
||||
final Method[] methods = getClass().getDeclaredMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.siyeh.ig.style.*;
|
||||
import com.siyeh.ig.threading.*;
|
||||
import com.siyeh.ig.verbose.*;
|
||||
import com.siyeh.ig.visibility.*;
|
||||
import com.siyeh.ig.telemetry.InspectionGadgetsTelemetry;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
@@ -54,6 +55,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
|
||||
private final List m_inspectionClasses = new ArrayList(NUM_INSPECTIONS);
|
||||
private static final String DESCRIPTION_DIRECTORY_NAME =
|
||||
"C:/My Open Source Projects/InspectionGadgetsSVN/src/inspectionDescriptions/";
|
||||
private final InspectionGadgetsTelemetry telemetry = new InspectionGadgetsTelemetry();
|
||||
|
||||
public static void main(String[] args){
|
||||
final InspectionGadgetsPlugin plugin = new InspectionGadgetsPlugin();
|
||||
@@ -344,6 +346,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
|
||||
inspectionClasses.add(MismatchedCollectionQueryUpdateInspection.class);
|
||||
inspectionClasses.add(TextLabelInSwitchStatementInspection.class);
|
||||
inspectionClasses.add(AssignmentToNullInspection.class);
|
||||
inspectionClasses.add(DuplicateConditionInspection.class);
|
||||
inspectionClasses.add(IteratorNextDoesNotThrowNoSuchElementExceptionInspection.class);
|
||||
inspectionClasses.add(ReturnNullInspection.class);
|
||||
inspectionClasses.add(StaticCallOnSubclassInspection.class);
|
||||
@@ -769,4 +772,8 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
|
||||
|
||||
public void disposeComponent(){
|
||||
}
|
||||
|
||||
public InspectionGadgetsTelemetry getTelemetry(){
|
||||
return telemetry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.siyeh.ig;
|
||||
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.siyeh.ig.telemetry.TelemetryToolWindowImpl;
|
||||
import com.siyeh.ig.telemetry.TelemetryToolWindow;
|
||||
|
||||
public class InspectionGadgetsProjectComponent implements ProjectComponent{
|
||||
private TelemetryToolWindow toolWindow = null;
|
||||
|
||||
public InspectionGadgetsProjectComponent(Project project){
|
||||
super();
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
private Project project;
|
||||
|
||||
public void projectOpened(){
|
||||
toolWindow = new TelemetryToolWindowImpl(project);
|
||||
toolWindow.register();
|
||||
}
|
||||
|
||||
public void projectClosed(){
|
||||
toolWindow.unregister();
|
||||
}
|
||||
|
||||
public String getComponentName(){
|
||||
return "InspectionGadgetsProjectComponent";
|
||||
}
|
||||
|
||||
public void initComponent(){
|
||||
}
|
||||
|
||||
public void disposeComponent(){
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.siyeh.ig;
|
||||
|
||||
public interface InspectionRunListener{
|
||||
void reportRun(String inspectionID, long runTime);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.ExpressionInspection;
|
||||
import com.siyeh.ig.GroupNames;
|
||||
import com.siyeh.ig.psiutils.ExpressionEquivalenceChecker;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DuplicateConditionInspection extends ExpressionInspection{
|
||||
public String getDisplayName(){
|
||||
return "Duplicate condition in 'if' statement";
|
||||
}
|
||||
|
||||
public String getGroupDisplayName(){
|
||||
return GroupNames.BUGS_GROUP_NAME;
|
||||
}
|
||||
|
||||
public String buildErrorString(PsiElement location){
|
||||
return "Duplicate condition #ref #loc";
|
||||
}
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager,
|
||||
boolean onTheFly){
|
||||
return new DuplicateConditionVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
private static class DuplicateConditionVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private DuplicateConditionVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
super(inspection, inspectionManager, isOnTheFly);
|
||||
}
|
||||
|
||||
public void visitIfStatement(PsiIfStatement statement){
|
||||
super.visitIfStatement(statement);
|
||||
final PsiElement parent = statement.getParent();
|
||||
if(parent instanceof PsiIfStatement){
|
||||
final PsiIfStatement parentStatement = (PsiIfStatement) parent;
|
||||
final PsiStatement elseBranch = parentStatement.getElseBranch();
|
||||
if(statement.equals(elseBranch)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
final Set conditions = new HashSet();
|
||||
collectConditionsForIfStatement(statement, conditions);
|
||||
if(conditions.size() < 2){
|
||||
return;
|
||||
}
|
||||
final PsiExpression[] conditionArray =
|
||||
(PsiExpression[]) conditions.toArray(new PsiExpression[conditions.size()]);
|
||||
final boolean[] matched = new boolean[conditionArray.length];
|
||||
Arrays.fill(matched, false);
|
||||
for(int i = 0; i < conditionArray.length; i++){
|
||||
if(matched[i]){
|
||||
continue;
|
||||
}
|
||||
final PsiExpression condition = conditionArray[i];
|
||||
for(int j = i+1; j < conditionArray.length; j++){
|
||||
if(matched[j]){
|
||||
continue;
|
||||
}
|
||||
final PsiExpression testCondition = conditionArray[j];
|
||||
final boolean areEquivalent =
|
||||
ExpressionEquivalenceChecker.expressionsAreEquivalent(condition,
|
||||
testCondition);
|
||||
if(areEquivalent){
|
||||
registerError(testCondition);
|
||||
if(!matched[i]){
|
||||
registerError(condition);
|
||||
}
|
||||
matched[i] = true;
|
||||
matched[j] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectConditionsForIfStatement(PsiIfStatement statement,
|
||||
Set conditions){
|
||||
final PsiExpression condition = statement.getCondition();
|
||||
collectConditionsForExpression(condition, conditions);
|
||||
final PsiStatement branch = statement.getElseBranch();
|
||||
if(branch instanceof PsiIfStatement)
|
||||
{
|
||||
collectConditionsForIfStatement((PsiIfStatement)branch, conditions);
|
||||
}
|
||||
}
|
||||
|
||||
private void collectConditionsForExpression(PsiExpression condition, Set conditions){
|
||||
if(condition == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(condition instanceof PsiParenthesizedExpression)
|
||||
{
|
||||
final PsiExpression contents = ((PsiParenthesizedExpression) condition).getExpression();
|
||||
collectConditionsForExpression(contents, conditions);
|
||||
return;
|
||||
}
|
||||
if(condition instanceof PsiBinaryExpression)
|
||||
{
|
||||
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression) condition;
|
||||
final PsiJavaToken sign = binaryExpression.getOperationSign();
|
||||
if(sign!=null)
|
||||
{
|
||||
final IElementType tokenType = sign.getTokenType();
|
||||
if(JavaTokenType.OROR.equals(tokenType))
|
||||
{
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
collectConditionsForExpression(lhs, conditions);
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
collectConditionsForExpression(rhs, conditions);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
conditions.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -87,10 +87,8 @@ public class EqualsBetweenInconvertibleTypesInspection extends ExpressionInspect
|
||||
if (comparisonType == null) {
|
||||
return false;
|
||||
}
|
||||
if (TypeConversionUtil.areTypesConvertible(comparedType, comparisonType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !TypeConversionUtil.areTypesConvertible(comparedType,
|
||||
comparisonType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -85,10 +85,7 @@ public class EqualsUsesNonFinalVariableInspection extends ExpressionInspection{
|
||||
if(returnType == null){
|
||||
return false;
|
||||
}
|
||||
if(!returnType.equals(PsiType.BOOLEAN)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return returnType.equals(PsiType.BOOLEAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -80,10 +80,7 @@ public class HashCodeUsesNonFinalVariableInspection extends ExpressionInspection
|
||||
if (returnType == null) {
|
||||
return false;
|
||||
}
|
||||
if (!returnType.equals(PsiType.INT)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return returnType.equals(PsiType.INT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -168,9 +168,6 @@ public class IncompatibleMaskInspection extends ExpressionInspection{
|
||||
return true;
|
||||
}
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
if(PsiUtil.isConstantExpression(lhs)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return PsiUtil.isConstantExpression(lhs);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-12
@@ -109,10 +109,7 @@ public class MismatchedArrayReadWriteInspection extends VariableInspection {
|
||||
if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
if (VariableAccessUtils.arrayContentsAreAssigned(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return VariableAccessUtils.arrayContentsAreAssigned(variable, context);
|
||||
}
|
||||
|
||||
private static boolean isDefaultArrayInitializer(PsiExpression initializer) {
|
||||
@@ -120,10 +117,7 @@ public class MismatchedArrayReadWriteInspection extends VariableInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiNewExpression newExpression = (PsiNewExpression) initializer;
|
||||
if (newExpression.getArrayInitializer() != null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return newExpression.getArrayInitializer() == null;
|
||||
}
|
||||
|
||||
private static boolean arrayContentsAreRead(PsiVariable variable, PsiElement context) {
|
||||
@@ -143,10 +137,7 @@ public class MismatchedArrayReadWriteInspection extends VariableInspection {
|
||||
if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
if (VariableAccessUtils.arrayContentsAreAccessed(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return VariableAccessUtils.arrayContentsAreAccessed(variable, context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-8
@@ -114,10 +114,7 @@ public class MismatchedCollectionQueryUpdateInspection extends VariableInspectio
|
||||
if (variableIsPassedAsMethodArgument(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
if (collectionUpdateCalled(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return collectionUpdateCalled(variable, context);
|
||||
}
|
||||
|
||||
private static boolean collectionContentsAreQueried(PsiVariable variable, PsiElement context) {
|
||||
@@ -137,10 +134,7 @@ public class MismatchedCollectionQueryUpdateInspection extends VariableInspectio
|
||||
if (variableIsPassedAsMethodArgument(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
if (collectionQueryCalled(variable, context)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return collectionQueryCalled(variable, context);
|
||||
}
|
||||
|
||||
private static boolean variableIsAssignedFrom(PsiVariable variable, PsiElement context) {
|
||||
|
||||
+1
-4
@@ -67,10 +67,7 @@ public class SubtractionInCompareToInspection extends ExpressionInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (!TypeUtils.typeEquals("int", returnType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.typeEquals("int", returnType);
|
||||
}
|
||||
|
||||
private static boolean isSubtraction(PsiBinaryExpression exp) {
|
||||
|
||||
+2
-4
@@ -154,11 +154,9 @@ public class ImplicitNumericConversionInspection extends ExpressionInspection {
|
||||
if (isIntegral(expressionType) && isFloatingPoint(expectedType)) {
|
||||
return true;
|
||||
}
|
||||
if (isFloatingPoint(expressionType) && isFloatingPoint(expectedType)) {
|
||||
return true;
|
||||
}
|
||||
return isFloatingPoint(expressionType) &&
|
||||
isFloatingPoint(expectedType);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isNegatedLiteral(PsiExpression expression) {
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import com.siyeh.ig.GroupNames;
|
||||
|
||||
public class NoExplicitFinalizeCallsInspection extends ExpressionInspection {
|
||||
public String getID(){
|
||||
return "Finalize called explicitly";
|
||||
return "FinalizeCalledExplicitly";
|
||||
}
|
||||
public String getDisplayName() {
|
||||
return "'finalize()' called explicitly";
|
||||
@@ -27,7 +27,7 @@ public class NoExplicitFinalizeCallsInspection extends ExpressionInspection {
|
||||
public boolean isEnabledByDefault(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public BaseInspectionVisitor createVisitor(InspectionManager inspectionManager, boolean onTheFly) {
|
||||
return new NoExplicitFinalizeCallsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.siyeh.ig.imports;
|
||||
|
||||
import com.intellij.codeInspection.InspectionManager;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.*;
|
||||
import com.siyeh.ig.fixes.DeleteImportFix;
|
||||
|
||||
@@ -17,9 +17,9 @@ public class AnnotationInspection extends BaseInspection {
|
||||
return GroupNames.JDK_GROUP_NAME;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!aClass.isPhysical()) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
@@ -27,18 +27,18 @@ public class AnnotationInspection extends BaseInspection {
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!method.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!field.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
@@ -31,42 +31,42 @@ public class AssertAsNameInspection extends BaseInspection {
|
||||
return fix;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
@@ -33,42 +33,42 @@ public class EnumAsNameInspection extends BaseInspection {
|
||||
return fix;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
|
||||
+1
-4
@@ -77,10 +77,7 @@ public class ObsoleteCollectionInspection extends VariableInspection{
|
||||
if(typeName.indexOf('<') > 0){
|
||||
typeName = typeName.substring(0, typeName.indexOf('<'));
|
||||
}
|
||||
if(!s_obsoleteCollectionTypes.contains(typeName)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return s_obsoleteCollectionTypes.contains(typeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -58,9 +58,9 @@ public class ClassNamingConventionInspection extends ConventionInspection {
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!aClass.isPhysical()) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
|
||||
+3
-3
@@ -58,13 +58,13 @@ public class ConstantNamingConventionInspection extends ConventionInspection {
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
|
||||
@@ -32,41 +32,41 @@ public class DollarSignInNameInspection extends BaseInspection {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (containingClass instanceof PsiAnonymousClass) {
|
||||
return super.checkClass(containingClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(containingClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
+3
-3
@@ -62,13 +62,13 @@ public class InstanceMethodNamingConventionInspection extends ConventionInspecti
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
|
||||
+3
-3
@@ -60,13 +60,13 @@ public class InstanceVariableNamingConventionInspection extends ConventionInspec
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
+2
-2
@@ -58,10 +58,10 @@ public class InterfaceNamingConventionInspection extends ConventionInspection {
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
|
||||
if (!aClass.isPhysical()) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
|
||||
+3
-3
@@ -71,13 +71,13 @@ public class LocalVariableNamingConventionInspection extends ConventionInspectio
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
|
||||
+3
-3
@@ -61,13 +61,13 @@ public class ParameterNamingConventionInspection extends ConventionInspection {
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
|
||||
+3
-3
@@ -60,13 +60,13 @@ public class StaticMethodNamingConventionInspection extends ConventionInspection
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
|
||||
+3
-3
@@ -58,13 +58,13 @@ public class StaticVariableNamingConventionInspection extends ConventionInspecti
|
||||
return new NamingConventionsVisitor(this, inspectionManager, onTheFly);
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
if (!containingClass.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
+1
-5
@@ -109,10 +109,6 @@ public class CallToSimpleGetterInClassInspection extends ExpressionInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiField field = (PsiField) referent;
|
||||
if(!field.getContainingClass().equals(method.getContainingClass()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return field.getContainingClass().equals(method.getContainingClass());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -92,7 +92,8 @@ public class CallToSimpleSetterInClassInspection extends ExpressionInspection{
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final PsiAssignmentExpression assignment = ((PsiAssignmentExpression) possibleAssignment);
|
||||
final PsiAssignmentExpression assignment =
|
||||
(PsiAssignmentExpression) possibleAssignment;
|
||||
final PsiJavaToken sign = assignment.getOperationSign();
|
||||
if(!sign.getTokenType().equals(JavaTokenType.EQ)){
|
||||
return false;
|
||||
@@ -136,10 +137,7 @@ public class CallToSimpleSetterInClassInspection extends ExpressionInspection{
|
||||
if(rReferent == null){
|
||||
return false;
|
||||
}
|
||||
if(!(rReferent instanceof PsiParameter)){
|
||||
return false;
|
||||
}
|
||||
return rReferent instanceof PsiParameter;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -107,10 +107,7 @@ public class LengthOneStringsInConcatenationInspection extends ExpressionInspect
|
||||
return false;
|
||||
}
|
||||
final PsiType siblingType = sibling.getType();
|
||||
if (!TypeUtils.isJavaLangString(siblingType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.isJavaLangString(siblingType);
|
||||
}
|
||||
|
||||
static boolean isArgumentOfStringAppend(PsiExpression expression) {
|
||||
|
||||
+7
-24
@@ -203,10 +203,7 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
if (SideEffectChecker.mayHaveSideEffects(rhs)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOffsetArrayAccess(rhs, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return isOffsetArrayAccess(rhs, var);
|
||||
}
|
||||
|
||||
private static boolean isOffsetArrayAccess(PsiExpression expression, PsiLocalVariable var) {
|
||||
@@ -219,10 +216,7 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
if (index == null) {
|
||||
return false;
|
||||
}
|
||||
if (!expressionIsOffsetVariableLookup(index, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsOffsetVariableLookup(index, var);
|
||||
}
|
||||
|
||||
private static boolean isIncrement(PsiStatement statement, PsiLocalVariable var) {
|
||||
@@ -242,10 +236,7 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = prefixExp.getOperand();
|
||||
if (!expressionIsVariableLookup(operand, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
} else if (exp instanceof PsiPostfixExpression) {
|
||||
final PsiPostfixExpression postfixExp = (PsiPostfixExpression) exp;
|
||||
final PsiJavaToken sign = postfixExp.getOperationSign();
|
||||
@@ -257,10 +248,7 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = postfixExp.getOperand();
|
||||
if (!expressionIsVariableLookup(operand, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -280,10 +268,7 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression lhs = binaryExp.getLOperand();
|
||||
if (!expressionIsVariableLookup(lhs, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(lhs, var);
|
||||
}
|
||||
|
||||
private static boolean expressionIsVariableLookup(PsiExpression expression, PsiLocalVariable var) {
|
||||
@@ -315,10 +300,8 @@ public class ManualArrayCopyInspection extends ExpressionInspection {
|
||||
return false;
|
||||
}
|
||||
final IElementType tokenType = sign.getTokenType();
|
||||
if (!tokenType.equals(JavaTokenType.PLUS) && !tokenType.equals(JavaTokenType.MINUS)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(!tokenType.equals(JavaTokenType.PLUS) &&
|
||||
!tokenType.equals(JavaTokenType.MINUS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,10 +61,8 @@ class MethodReferenceVisitor extends PsiRecursiveElementVisitor {
|
||||
}
|
||||
final PsiClass referenceContainingClass = m_method.getContainingClass();
|
||||
final PsiClass methodContainingClass = method.getContainingClass();
|
||||
if (InheritanceUtil.isInheritorOrSelf(referenceContainingClass, methodContainingClass, true)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !InheritanceUtil.isInheritorOrSelf(referenceContainingClass,
|
||||
methodContainingClass, true);
|
||||
}
|
||||
|
||||
boolean isFieldStaticallyAccessible(PsiField field) {
|
||||
@@ -73,9 +71,7 @@ class MethodReferenceVisitor extends PsiRecursiveElementVisitor {
|
||||
}
|
||||
final PsiClass referenceContainingClass = m_method.getContainingClass();
|
||||
final PsiClass fieldContainingClass = field.getContainingClass();
|
||||
if (InheritanceUtil.isInheritorOrSelf(referenceContainingClass, fieldContainingClass, true)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !InheritanceUtil.isInheritorOrSelf(referenceContainingClass,
|
||||
fieldContainingClass, true);
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -73,10 +73,7 @@ public class SingleCharacterStartsWithInspection extends ExpressionInspection {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (value.length() != 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return value.length() == 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -105,10 +105,7 @@ public class StringBufferToStringInConcatenationInspection extends ExpressionIns
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
final String className = aClass.getQualifiedName();
|
||||
if (!"java.lang.StringBuffer".equals(className)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return "java.lang.StringBuffer".equals(className);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ public class TrivialStringConcatenationInspection extends ExpressionInspection{
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private class TrivialStringConcatenationVisitor
|
||||
private static class TrivialStringConcatenationVisitor
|
||||
extends BaseInspectionVisitor{
|
||||
private TrivialStringConcatenationVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
|
||||
+2
-8
@@ -85,11 +85,8 @@ public class HardcodedFileSeparatorsInspection extends ExpressionInspection{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isURLString(str)){
|
||||
return false;
|
||||
}
|
||||
return !isURLString(str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,11 +102,8 @@ public class HardcodedFileSeparatorsInspection extends ExpressionInspection{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(str.indexOf("/>") != -1){
|
||||
return true;
|
||||
}
|
||||
return str.indexOf("/>") != -1;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,11 +81,8 @@ public class SystemExitInspection extends ExpressionInspection {
|
||||
if (className == null) {
|
||||
return false;
|
||||
}
|
||||
if (!"java.lang.System".equals(className) &&
|
||||
!"java.lang.Runtime".equals(className)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(!"java.lang.System".equals(className) &&
|
||||
!"java.lang.Runtime".equals(className));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,6 @@ public class BoolUtils {
|
||||
return false;
|
||||
}
|
||||
final String text = test.getText();
|
||||
if ("true".equals(text)) {
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
return "true".equals(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +73,7 @@ public class ControlFlowUtils {
|
||||
if (test == null) {
|
||||
return false;
|
||||
}
|
||||
if (BoolUtils.isTrue(test)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !BoolUtils.isTrue(test);
|
||||
}
|
||||
|
||||
private static boolean foreachStatementMayReturnNormally(PsiForeachStatement loopStatement) {
|
||||
@@ -129,11 +126,8 @@ public class ControlFlowUtils {
|
||||
return true;
|
||||
}
|
||||
final PsiStatement elseBranch = ifStatement.getElseBranch();
|
||||
if (elseBranch == null ||
|
||||
statementMayCompleteNormally(elseBranch)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return elseBranch == null ||
|
||||
statementMayCompleteNormally(elseBranch);
|
||||
}
|
||||
|
||||
private static boolean labeledStatementMayCompleteNormally(PsiLabeledStatement labeledStatement) {
|
||||
@@ -454,10 +448,7 @@ public class ControlFlowUtils {
|
||||
if (returnFinder.returnFound()) {
|
||||
return false;
|
||||
}
|
||||
if (codeBlockMayCompleteNormally(body)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !codeBlockMayCompleteNormally(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ExpectedTypeUtils{
|
||||
final PsiElement parent = ref.getParent();
|
||||
if(parent instanceof PsiMethodCallExpression){
|
||||
final PsiMethod psiMethod =
|
||||
((PsiMethodCallExpression) parent).resolveMethod();
|
||||
((PsiCall) parent).resolveMethod();
|
||||
if(psiMethod == null){
|
||||
return null;
|
||||
}
|
||||
@@ -42,10 +42,10 @@ public class ExpectedTypeUtils{
|
||||
return factory.createType(aClass);
|
||||
} else if(parent instanceof PsiReferenceExpression){
|
||||
final PsiElement elt =
|
||||
((PsiReferenceExpression) parent).resolve();
|
||||
((PsiReference) parent).resolve();
|
||||
if(elt instanceof PsiField){
|
||||
final PsiClass aClass =
|
||||
((PsiField) elt).getContainingClass();
|
||||
((PsiMember) elt).getContainingClass();
|
||||
final PsiElementFactory factory =
|
||||
manager.getElementFactory();
|
||||
return factory.createType(aClass);
|
||||
|
||||
@@ -17,10 +17,7 @@ public class ImportUtils {
|
||||
if (hasOnDemandImportConflict(fqName, file)) {
|
||||
return false;
|
||||
}
|
||||
if (containsConflictingClassReference(fqName, file)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !containsConflictingClassReference(fqName, file);
|
||||
}
|
||||
|
||||
private static boolean hasExactImportMatch(String fqName, PsiJavaFile file) {
|
||||
|
||||
@@ -326,7 +326,7 @@ public class InitializationReadUtils {
|
||||
return true;
|
||||
}
|
||||
if (lhs instanceof PsiReferenceExpression) {
|
||||
final PsiElement element = ((PsiReferenceExpression) lhs).resolve();
|
||||
final PsiElement element = ((PsiReference) lhs).resolve();
|
||||
if (element != null &&
|
||||
field != null &&
|
||||
element.equals(field)) {
|
||||
|
||||
@@ -254,7 +254,7 @@ public class InitializationUtils {
|
||||
return true;
|
||||
}
|
||||
if (lhs instanceof PsiReferenceExpression) {
|
||||
final PsiElement element = ((PsiReferenceExpression) lhs).resolve();
|
||||
final PsiElement element = ((PsiReference) lhs).resolve();
|
||||
if (element != null &&
|
||||
field != null &&
|
||||
element.equals(field)) {
|
||||
|
||||
@@ -147,11 +147,8 @@ public class RecursionUtils {
|
||||
return true;
|
||||
}
|
||||
final PsiStatement elseBranch = ifStatement.getElseBranch();
|
||||
if (elseBranch != null &&
|
||||
statementMayReturnBeforeRecursing(elseBranch, method)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return elseBranch != null &&
|
||||
statementMayReturnBeforeRecursing(elseBranch, method);
|
||||
}
|
||||
|
||||
private static boolean labeledStatementMayReturnBeforeRecursing(PsiLabeledStatement labeledStatement, PsiMethod method) {
|
||||
@@ -473,10 +470,7 @@ public class RecursionUtils {
|
||||
return true;
|
||||
}
|
||||
final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
|
||||
if (codeBlockMustRecurse(finallyBlock, method)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return codeBlockMustRecurse(finallyBlock, method);
|
||||
}
|
||||
|
||||
private static boolean codeBlockMustRecurse(PsiCodeBlock block, PsiMethod method) {
|
||||
@@ -528,10 +522,7 @@ public class RecursionUtils {
|
||||
|
||||
private static boolean foreachStatementMustRecurse(PsiForeachStatement foreachStatement, PsiMethod method) {
|
||||
final PsiExpression iteration = foreachStatement.getIteratedValue();
|
||||
if (expressionMustRecurse(iteration, method)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return expressionMustRecurse(iteration, method);
|
||||
}
|
||||
|
||||
private static boolean whileStatementMustRecurse(PsiWhileStatement whileStatement, PsiMethod method) {
|
||||
|
||||
@@ -86,10 +86,7 @@ public class SerializationUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!TypeUtils.typeEquals("void", returnType)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.typeEquals("void", returnType);
|
||||
}
|
||||
|
||||
public static boolean isWriteObject(PsiMethod method){
|
||||
@@ -107,10 +104,7 @@ public class SerializationUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!TypeUtils.typeEquals("void", returnType)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.typeEquals("void", returnType);
|
||||
}
|
||||
|
||||
public static boolean isReadResolve(PsiMethod method){
|
||||
@@ -124,10 +118,7 @@ public class SerializationUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!TypeUtils.isJavaLangObject(returnType)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.isJavaLangObject(returnType);
|
||||
}
|
||||
|
||||
public static boolean isWriteReplace(PsiMethod method){
|
||||
@@ -141,10 +132,7 @@ public class SerializationUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if(!TypeUtils.isJavaLangObject(returnType)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return TypeUtils.isJavaLangObject(returnType);
|
||||
}
|
||||
|
||||
public static boolean typeIsSerializable(PsiType type){
|
||||
|
||||
@@ -17,10 +17,7 @@ public class SingletonUtil {
|
||||
if (hasVisibleConstructor(aClass)) {
|
||||
return false;
|
||||
}
|
||||
if (!containsOneStaticSelfInstance(aClass)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return containsOneStaticSelfInstance(aClass);
|
||||
}
|
||||
|
||||
private static boolean containsOneStaticSelfInstance(PsiClass aClass) {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TypeUtils {
|
||||
return typeInherits(type, typeName);
|
||||
}
|
||||
|
||||
private static boolean typeInherits(final PsiType type, String typeName) {
|
||||
private static boolean typeInherits(PsiType type, String typeName) {
|
||||
final String text = type.getCanonicalText();
|
||||
if(typeName.equals(text))
|
||||
{
|
||||
|
||||
@@ -22,10 +22,8 @@ public class UtilityClassUtil {
|
||||
if (!allFieldsStatic(aClass)) {
|
||||
return false;
|
||||
}
|
||||
if (aClass.getMethods().length == 0 && aClass.getFields().length == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(aClass.getMethods().length == 0 &&
|
||||
aClass.getFields().length == 0);
|
||||
}
|
||||
|
||||
private static boolean allFieldsStatic(PsiClass aClass) {
|
||||
|
||||
@@ -23,11 +23,7 @@ public class WellFormednessUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiJavaToken operationSign = expression.getOperationSign();
|
||||
if(operationSign == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return operationSign != null;
|
||||
}
|
||||
|
||||
public static boolean isWellFormed(PsiAssignmentExpression expression){
|
||||
@@ -40,9 +36,6 @@ public class WellFormednessUtils{
|
||||
return false;
|
||||
}
|
||||
final PsiJavaToken operationSign = expression.getOperationSign();
|
||||
if(operationSign == null){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return operationSign != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public class IOResourceInspection extends ExpressionInspection{
|
||||
return;
|
||||
}
|
||||
final PsiElement referent =
|
||||
((PsiReferenceExpression) qualifier).resolve();
|
||||
((PsiReference) qualifier).resolve();
|
||||
if(referent.equals(streamToClose)){
|
||||
containsStreamClose = true;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class JDBCResourceInspection extends ExpressionInspection {
|
||||
return;
|
||||
}
|
||||
final PsiElement referent =
|
||||
((PsiReferenceExpression) qualifier).resolve();
|
||||
((PsiReference) qualifier).resolve();
|
||||
if(referent == null){
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-5
@@ -170,10 +170,7 @@ public class UnnecessarilyQualifiedStaticUsageInspection extends ExpressionInspe
|
||||
containingMethod =
|
||||
(PsiMethod) PsiTreeUtil.getParentOfType(containingMethod, PsiMethod.class);
|
||||
}
|
||||
if (!qualifierElement.equals(containingClass)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return qualifierElement.equals(containingClass);
|
||||
}
|
||||
|
||||
private boolean isUnnecessarilyQualifiedMethodCall(PsiReferenceExpression expression) {
|
||||
@@ -189,7 +186,7 @@ public class UnnecessarilyQualifiedStaticUsageInspection extends ExpressionInspe
|
||||
if (!(qualifierExpression instanceof PsiJavaCodeReferenceElement)) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement qualifierElement = ((PsiJavaCodeReferenceElement) qualifierExpression).resolve();
|
||||
final PsiElement qualifierElement = ((PsiReference) qualifierExpression).resolve();
|
||||
if (!(qualifierElement instanceof PsiClass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class IconHelper{
|
||||
private IconHelper(){
|
||||
super();
|
||||
}
|
||||
|
||||
public static ImageIcon getIcon(String location){
|
||||
final Class thisClass = IconHelper.class;
|
||||
final URL resource = thisClass.getResource(location);
|
||||
return new ImageIcon(resource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import com.siyeh.ig.InspectionRunListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class InspectionGadgetsTelemetry implements InspectionRunListener{
|
||||
private final Map totalRunCount = new HashMap(400);
|
||||
private final Map totalRunTime = new HashMap(400);
|
||||
private final Object lock = new Object();
|
||||
|
||||
public void reportRun(String inspectionID, long runTime)
|
||||
{
|
||||
synchronized(lock)
|
||||
{
|
||||
final Integer count = (Integer) totalRunCount.get(inspectionID);
|
||||
if(count == null){
|
||||
totalRunCount.put(inspectionID, new Integer(1));
|
||||
} else{
|
||||
totalRunCount.put(inspectionID,
|
||||
new Integer(count.intValue() + 1));
|
||||
}
|
||||
final Long runTimeSoFar = (Long) totalRunTime.get(inspectionID);
|
||||
if(runTimeSoFar == null){
|
||||
totalRunTime.put(inspectionID, new Long(runTime));
|
||||
} else{
|
||||
totalRunTime.put(inspectionID,
|
||||
new Long(runTimeSoFar.intValue() + runTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
synchronized(lock){
|
||||
totalRunCount.clear();
|
||||
totalRunTime.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public long getRunTimeForInspection(String inspectionID)
|
||||
{
|
||||
synchronized(lock){
|
||||
final Long runTime = (Long) totalRunTime.get(inspectionID);
|
||||
if(runTime == null)
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
return runTime.longValue();
|
||||
}
|
||||
}
|
||||
|
||||
public int getRunCountForInspection(String inspectionID)
|
||||
{
|
||||
synchronized(lock){
|
||||
final Integer runCount = (Integer) totalRunCount.get(inspectionID);
|
||||
if(runCount == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return runCount.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getInspections()
|
||||
{
|
||||
synchronized(lock)
|
||||
{
|
||||
final Set inspections = totalRunCount.keySet();
|
||||
final int numInspections = inspections.size();
|
||||
final String[] inspectionArray = (String[]) inspections.toArray(new String[numInspections]);
|
||||
Arrays.sort(inspectionArray);
|
||||
return inspectionArray;
|
||||
}
|
||||
}
|
||||
|
||||
public double getAverageRunTimeForInspection(String inspectionID){
|
||||
synchronized(lock){
|
||||
final Integer runCount = (Integer) totalRunCount.get(inspectionID);
|
||||
if(runCount == null){
|
||||
return 0.0;
|
||||
}
|
||||
final Long runTime = (Long) totalRunTime.get(inspectionID);
|
||||
|
||||
return (double) runTime.longValue() / (double) runCount.intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ResetTelemetryAction extends AnAction{
|
||||
private final InspectionGadgetsTelemetry telemetry;
|
||||
private final TelemetryDisplay display;
|
||||
|
||||
private static final Icon resetIcon =
|
||||
IconHelper.getIcon("/actions/reset.png");
|
||||
public ResetTelemetryAction(InspectionGadgetsTelemetry telemetry,
|
||||
TelemetryDisplay display){
|
||||
super("Reset" , "Reset telemetry data", resetIcon);
|
||||
this.telemetry = telemetry;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent event){
|
||||
telemetry.reset();
|
||||
display.update();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public interface TelemetryDisplay{
|
||||
|
||||
JComponent getContentPane();
|
||||
|
||||
void update();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.telemetry.TelemetryDisplayImpl">
|
||||
<scrollpane id="2507" binding="scrollPane">
|
||||
<constraints>
|
||||
<xy x="104" y="60" width="174" height="154"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="d0712" class="javax.swing.JTable" binding="table">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<rowSelectionAllowed value="true"/>
|
||||
<showVerticalLines value="false"/>
|
||||
<enabled value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</form>
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
|
||||
public class TelemetryDisplayImpl implements TelemetryDisplay{
|
||||
private JTable table;
|
||||
private JScrollPane scrollPane;
|
||||
private final TelemetryTableModel model;
|
||||
|
||||
public TelemetryDisplayImpl(InspectionGadgetsTelemetry telemetry){
|
||||
super();
|
||||
model = new TelemetryTableModel(telemetry);
|
||||
table.setModel(model);
|
||||
}
|
||||
|
||||
public JComponent getContentPane(){
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
table.tableChanged(new TableModelEvent(model,
|
||||
TableModelEvent.HEADER_ROW));
|
||||
table.tableChanged(new TableModelEvent(model));
|
||||
table.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class TelemetryTableModel extends DefaultTableModel{
|
||||
private final InspectionGadgetsTelemetry telemetry;
|
||||
private NumberFormat format = NumberFormat.getNumberInstance();
|
||||
{
|
||||
format.setMaximumFractionDigits(2);
|
||||
format.setMinimumFractionDigits(2);
|
||||
}
|
||||
|
||||
public TelemetryTableModel(InspectionGadgetsTelemetry telemetry){
|
||||
super();
|
||||
this.telemetry = telemetry;
|
||||
}
|
||||
|
||||
public int getColumnCount(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
public int getRowCount(){
|
||||
if(telemetry== null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return telemetry.getInspections().length;
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int column){
|
||||
if(telemetry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final String[] inspections = telemetry.getInspections();
|
||||
final String inspection = inspections[row];
|
||||
switch(column){
|
||||
case 0:
|
||||
return inspection;
|
||||
case 1:
|
||||
return Long.toString(telemetry.getRunTimeForInspection(inspection));
|
||||
case 2:
|
||||
return format.format(telemetry.getAverageRunTimeForInspection(inspection));
|
||||
case 3:
|
||||
return Integer.toString(telemetry.getRunCountForInspection(inspection));
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setValueAt(Object object, int i,
|
||||
int i1){
|
||||
//don't do anything
|
||||
}
|
||||
|
||||
public String getColumnName(int column){
|
||||
switch(column){
|
||||
case 0:
|
||||
return "Inspection Name";
|
||||
case 1:
|
||||
return "Total Run Time (msecs)";
|
||||
case 2:
|
||||
return "Average Run Time (msecs)";
|
||||
case 3:
|
||||
return "Total Run Count";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
|
||||
public interface TelemetryToolWindow{
|
||||
String CYCLE_TOOL_WINDOW_ID = "IG Telemetry";
|
||||
|
||||
void register();
|
||||
|
||||
void show();
|
||||
|
||||
void close();
|
||||
|
||||
void unregister();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.ActionToolbar;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.siyeh.ig.InspectionGadgetsPlugin;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class TelemetryToolWindowImpl implements TelemetryToolWindow{
|
||||
private TelemetryDisplay telemetryDisplay;
|
||||
private JPanel myContentPanel;
|
||||
private ToolWindow myToolWindow = null;
|
||||
private Project project;
|
||||
|
||||
public TelemetryToolWindowImpl(Project project){
|
||||
super();
|
||||
this.project = project;
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
final InspectionGadgetsPlugin plugin =
|
||||
(InspectionGadgetsPlugin) application.getComponent("InspectionGadgets");
|
||||
final InspectionGadgetsTelemetry telemetry = plugin.getTelemetry();
|
||||
telemetryDisplay = new TelemetryDisplayImpl(telemetry);
|
||||
final DefaultActionGroup toolbarGroup = new DefaultActionGroup();
|
||||
toolbarGroup.add(new UpdateTelemetryViewAction(telemetryDisplay));
|
||||
toolbarGroup.add(new ResetTelemetryAction(telemetry, telemetryDisplay));
|
||||
final ActionManager actionManager = ActionManager.getInstance();
|
||||
final ActionToolbar toolbar =
|
||||
actionManager.createActionToolbar(CYCLE_TOOL_WINDOW_ID,
|
||||
toolbarGroup, true);
|
||||
myContentPanel = new JPanel(new BorderLayout());
|
||||
myContentPanel.setBackground(Color.gray);
|
||||
final JComponent toolbarComponent = toolbar.getComponent();
|
||||
myContentPanel.add(toolbarComponent, BorderLayout.NORTH);
|
||||
final JComponent displayContentPane = telemetryDisplay.getContentPane();
|
||||
myContentPanel.add(displayContentPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public void register(){
|
||||
final ToolWindowManager toolWindowManager =
|
||||
ToolWindowManager.getInstance(project);
|
||||
myToolWindow =
|
||||
toolWindowManager.registerToolWindow(CYCLE_TOOL_WINDOW_ID,
|
||||
myContentPanel,
|
||||
ToolWindowAnchor.BOTTOM);
|
||||
myToolWindow.setTitle("IG Telemetry");
|
||||
myToolWindow.setAvailable(true, null);
|
||||
}
|
||||
|
||||
public void show(){
|
||||
myToolWindow.setAvailable(true, null);
|
||||
telemetryDisplay.update();
|
||||
myToolWindow.show(null);
|
||||
}
|
||||
|
||||
public void close(){
|
||||
myToolWindow.hide(null);
|
||||
myToolWindow.setAvailable(false, null);
|
||||
}
|
||||
|
||||
|
||||
public void unregister(){
|
||||
final ToolWindowManager toolWindowManager =
|
||||
ToolWindowManager.getInstance(project);
|
||||
toolWindowManager.unregisterToolWindow(CYCLE_TOOL_WINDOW_ID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class UpdateTelemetryViewAction extends AnAction{
|
||||
private final TelemetryDisplay telemetryDisplay;
|
||||
|
||||
private static final Icon refreshIcon =
|
||||
IconHelper.getIcon("/actions/sync.png");
|
||||
|
||||
public UpdateTelemetryViewAction(TelemetryDisplay telemetryDisplay){
|
||||
super("Refresh", "Refresh telemetry display", refreshIcon);
|
||||
this.telemetryDisplay = telemetryDisplay;
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent event){
|
||||
telemetryDisplay.update();
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -71,7 +71,8 @@ public class WhileLoopSpinsOnFieldInspection extends MethodInspection {
|
||||
(PsiBinaryExpression) condition;
|
||||
final PsiExpression lOperand = binaryExpression.getLOperand();
|
||||
final PsiExpression rOperand = binaryExpression.getROperand();
|
||||
return (isSimpleFieldComparison(lOperand) && isLiteral(rOperand)) ||
|
||||
return isSimpleFieldComparison(lOperand) &&
|
||||
isLiteral(rOperand) ||
|
||||
(isSimpleFieldComparison(rOperand) && isLiteral(lOperand));
|
||||
}
|
||||
return false;
|
||||
@@ -106,10 +107,7 @@ public class WhileLoopSpinsOnFieldInspection extends MethodInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiField field = (PsiField) referent;
|
||||
if (field.hasModifierProperty(PsiModifier.VOLATILE)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !field.hasModifierProperty(PsiModifier.VOLATILE);
|
||||
}
|
||||
|
||||
private boolean statementIsEmpty(PsiStatement statement) {
|
||||
|
||||
@@ -267,10 +267,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
if (arrayExpression == null) {
|
||||
return false;
|
||||
}
|
||||
if (!arrayName.equals(arrayExpression.getText())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return arrayName.equals(arrayExpression.getText());
|
||||
}
|
||||
|
||||
private boolean isIteratorNext(PsiElement element, String iteratorNameName) {
|
||||
@@ -302,10 +299,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final String referenceName = reference.getReferenceName();
|
||||
if (!"next".equals(referenceName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return "next".equals(referenceName);
|
||||
}
|
||||
|
||||
private String createNewVarName(Project project, PsiForStatement scope, PsiType type) {
|
||||
@@ -391,10 +385,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
if (!indexVarOnlyUsedAsIndex(arrayName, indexVar, body)) {
|
||||
return false;
|
||||
}
|
||||
if (isArrayAssigned(arrayName, body)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !isArrayAssigned(arrayName, body);
|
||||
}
|
||||
|
||||
private static boolean isArrayAssigned(String arrayReference, PsiStatement body) {
|
||||
@@ -455,10 +446,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
if (isIteratorRemoveCalled(iteratorName, body)) {
|
||||
return false;
|
||||
}
|
||||
if (isIteratorAssigned(iteratorName, body)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !isIteratorAssigned(iteratorName, body);
|
||||
}
|
||||
|
||||
private static int calculateCallsToIteratorNext(String iteratorName, PsiStatement body) {
|
||||
@@ -505,10 +493,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
return true;
|
||||
}
|
||||
final String target = qualifier.getText();
|
||||
if (!iterator.equals(target)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return iterator.equals(target);
|
||||
}
|
||||
|
||||
private static PsiReferenceExpression getArrayFromCondition(PsiExpression condition) {
|
||||
@@ -537,10 +522,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = prefixExp.getOperand();
|
||||
if (!expressionIsVariableLookup(operand, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
} else if (exp instanceof PsiPostfixExpression) {
|
||||
final PsiPostfixExpression postfixExp = (PsiPostfixExpression) exp;
|
||||
final PsiJavaToken sign = postfixExp.getOperationSign();
|
||||
@@ -552,10 +534,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = postfixExp.getOperand();
|
||||
if (!expressionIsVariableLookup(operand, var)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -579,10 +558,7 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression rhs = binaryExp.getROperand();
|
||||
if (!expressionIsArrayLengthLookup(rhs)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsArrayLengthLookup(rhs);
|
||||
}
|
||||
|
||||
private static boolean expressionIsArrayLengthLookup(PsiExpression expression) {
|
||||
@@ -773,7 +749,6 @@ public class ForCanBeForeachInspection extends StatementInspection {
|
||||
final PsiExpression lhs = assignment.getLExpression();
|
||||
if (lhs.equals(arrayAccess)) {
|
||||
indexVariableUsedOnlyAsIndex = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-8
@@ -185,10 +185,7 @@ public class PointlessBitwiseExpressionInspection extends ExpressionInspection {
|
||||
if (value instanceof Character && ((Character) value).charValue() == 0) {
|
||||
return true;
|
||||
}
|
||||
if (value instanceof Byte && ((Byte) value).byteValue() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return value instanceof Byte && ((Byte) value).byteValue() == 0;
|
||||
}
|
||||
|
||||
private static boolean isAllOnes(PsiExpression expression, PsiType expressionType) {
|
||||
@@ -208,10 +205,8 @@ public class PointlessBitwiseExpressionInspection extends ExpressionInspection {
|
||||
if (value instanceof Character && ((Character) value).charValue() == (char) 0xffff) {
|
||||
return true;
|
||||
}
|
||||
if (value instanceof Byte && ((Byte) value).byteValue() == (byte) 0xff) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return value instanceof Byte &&
|
||||
((Byte) value).byteValue() == (byte) 0xff;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class TrivialIfInspection extends ExpressionInspection{
|
||||
return fix;
|
||||
}
|
||||
|
||||
private class TrivialIfFix extends InspectionGadgetsFix{
|
||||
private static class TrivialIfFix extends InspectionGadgetsFix{
|
||||
public String getName(){
|
||||
return "Simplify";
|
||||
}
|
||||
@@ -313,11 +313,8 @@ public class TrivialIfInspection extends ExpressionInspection{
|
||||
}
|
||||
|
||||
final PsiStatement elseBranch = (PsiStatement) nextStatement;
|
||||
if(ConditionalUtils.isReturn(thenBranch, "true")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "false")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ConditionalUtils.isReturn(thenBranch, "true")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "false");
|
||||
}
|
||||
|
||||
public static boolean isSimplifiableImplicitReturnNegated(PsiIfStatement ifStatement){
|
||||
@@ -334,11 +331,8 @@ public class TrivialIfInspection extends ExpressionInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiStatement elseBranch = (PsiStatement) nextStatement;
|
||||
if(ConditionalUtils.isReturn(thenBranch, "false")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "true")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ConditionalUtils.isReturn(thenBranch, "false")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "true");
|
||||
}
|
||||
|
||||
public static boolean isSimplifiableReturn(PsiIfStatement ifStatement){
|
||||
@@ -346,11 +340,8 @@ public class TrivialIfInspection extends ExpressionInspection{
|
||||
thenBranch = ConditionalUtils.stripBraces(thenBranch);
|
||||
PsiStatement elseBranch = ifStatement.getElseBranch();
|
||||
elseBranch = ConditionalUtils.stripBraces(elseBranch);
|
||||
if(ConditionalUtils.isReturn(thenBranch, "true")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "false")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ConditionalUtils.isReturn(thenBranch, "true")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "false");
|
||||
}
|
||||
|
||||
public static boolean isSimplifiableReturnNegated(PsiIfStatement ifStatement){
|
||||
@@ -358,11 +349,8 @@ public class TrivialIfInspection extends ExpressionInspection{
|
||||
thenBranch = ConditionalUtils.stripBraces(thenBranch);
|
||||
PsiStatement elseBranch = ifStatement.getElseBranch();
|
||||
elseBranch = ConditionalUtils.stripBraces(elseBranch);
|
||||
if(ConditionalUtils.isReturn(thenBranch, "false")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "true")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ConditionalUtils.isReturn(thenBranch, "false")
|
||||
&& ConditionalUtils.isReturn(elseBranch, "true");
|
||||
}
|
||||
|
||||
public static boolean isSimplifiableAssignment(PsiIfStatement ifStatement){
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class UnnecessaryBlockStatementInspection extends StatementInspection{
|
||||
if(brace == null){
|
||||
return;
|
||||
}
|
||||
final PsiCodeBlock parentBlock = ((PsiCodeBlock) parent);
|
||||
final PsiCodeBlock parentBlock = (PsiCodeBlock) parent;
|
||||
if(parentBlock.getStatements().length > 1 &&
|
||||
containsConflictingDeclarations(codeBlock, parentBlock)){
|
||||
return;
|
||||
|
||||
+6
-6
@@ -22,9 +22,9 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
|
||||
return GroupNames.VERBOSE_GROUP_NAME;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckClass(PsiClass aClass, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!aClass.isPhysical()) {
|
||||
return super.checkClass(aClass, mgr, isOnTheFly);
|
||||
return super.doCheckClass(aClass, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
aClass.accept(visitor);
|
||||
@@ -32,18 +32,18 @@ public class UnnecessaryInterfaceModifierInspection extends BaseInspection {
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckMethod(PsiMethod method, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!method.isPhysical()) {
|
||||
return super.checkMethod(method, mgr, isOnTheFly);
|
||||
return super.doCheckMethod(method, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
method.accept(visitor);
|
||||
return visitor.getErrors();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] doCheckField(PsiField field, InspectionManager mgr, boolean isOnTheFly) {
|
||||
if (!field.isPhysical()) {
|
||||
return super.checkField(field, mgr, isOnTheFly);
|
||||
return super.doCheckField(field, mgr, isOnTheFly);
|
||||
}
|
||||
final BaseInspectionVisitor visitor = createVisitor(mgr, isOnTheFly);
|
||||
field.accept(visitor);
|
||||
|
||||
+2
-8
@@ -135,10 +135,7 @@ public class UnnecessaryLocalVariableInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiElement referent = ((PsiReference) returnValue).resolve();
|
||||
if (referent == null || !referent.equals(variable)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(referent == null || !referent.equals(variable));
|
||||
}
|
||||
private static boolean isImmediatelyThrown(PsiVariable variable) {
|
||||
|
||||
@@ -174,10 +171,7 @@ public class UnnecessaryLocalVariableInspection extends StatementInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiElement referent = ((PsiReference) returnValue).resolve();
|
||||
if (referent == null || !referent.equals(variable)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(referent == null || !referent.equals(variable));
|
||||
}
|
||||
|
||||
private static boolean isImmediatelyAssigned(PsiVariable variable) {
|
||||
|
||||
+7
-26
@@ -219,10 +219,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
return false;
|
||||
}
|
||||
final String referenceName = reference.getReferenceName();
|
||||
if(!"next".equals(referenceName)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return "next".equals(referenceName);
|
||||
}
|
||||
|
||||
private String createNewVarName(Project project, PsiWhileStatement scope,
|
||||
@@ -253,7 +250,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
}
|
||||
}
|
||||
|
||||
private class WhileBeForeachVisitor extends BaseInspectionVisitor{
|
||||
private static class WhileBeForeachVisitor extends BaseInspectionVisitor{
|
||||
private WhileBeForeachVisitor(BaseInspection inspection,
|
||||
InspectionManager inspectionManager,
|
||||
boolean isOnTheFly){
|
||||
@@ -341,10 +338,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
if(isIteratorRemoveCalled(iteratorName, body)){
|
||||
return false;
|
||||
}
|
||||
if(isIteratorAssigned(iteratorName, body)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !isIteratorAssigned(iteratorName, body);
|
||||
}
|
||||
|
||||
private static PsiStatement getPreviousStatement(PsiWhileStatement statement){
|
||||
@@ -410,10 +404,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
return true;
|
||||
}
|
||||
final String target = qualifier.getText();
|
||||
if(!iterator.equals(target)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return iterator.equals(target);
|
||||
}
|
||||
|
||||
private static PsiReferenceExpression getArrayFromCondition(PsiExpression condition){
|
||||
@@ -446,10 +437,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = prefixExp.getOperand();
|
||||
if(!expressionIsVariableLookup(operand, var)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
} else if(exp instanceof PsiPostfixExpression){
|
||||
final PsiPostfixExpression postfixExp = (PsiPostfixExpression) exp;
|
||||
final PsiJavaToken sign = postfixExp.getOperationSign();
|
||||
@@ -461,10 +449,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiExpression operand = postfixExp.getOperand();
|
||||
if(!expressionIsVariableLookup(operand, var)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsVariableLookup(operand, var);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -491,10 +476,7 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiExpression rhs = binaryExp.getROperand();
|
||||
if(!expressionIsArrayLengthLookup(rhs)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return expressionIsArrayLengthLookup(rhs);
|
||||
}
|
||||
|
||||
private static boolean expressionIsArrayLengthLookup(PsiExpression expression){
|
||||
@@ -699,7 +681,6 @@ public class WhileCanBeForeachInspection extends StatementInspection{
|
||||
final PsiExpression lhs = assignment.getLExpression();
|
||||
if(lhs.equals(arrayAccess)){
|
||||
indexVariableUsedOnlyAsIndex = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<body><table> <tr> <td valign = "top" height="150">
|
||||
<font face="verdana" size="-1">
|
||||
This inspection reports on any duplicate conditions among different branches of an
|
||||
<b><font color="#000080">if</font></b> statement. While it may rarely be the
|
||||
desired semantics, duplicate conditions usually represent programmer oversight.
|
||||
</font></td> </tr> <tr> <td height="20"> <font face="verdana" size="-2">Powered by InspectionGadgets </font> </td> </tr> </table> </body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.siyeh.igtest.bugs;
|
||||
|
||||
public class DuplicateCondition {
|
||||
public void foo()
|
||||
{
|
||||
if(bar())
|
||||
{
|
||||
System.out.println("1");
|
||||
}else if(bar()|| true)
|
||||
{
|
||||
System.out.println("2");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean bar()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user