diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 5c766cba8318..fe13cab4ce4d 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1458,6 +1458,8 @@ interface.never.implemented.option=Ignore interfaces which only declare constant size.replaceable.by.isempty.display.name='size() == 0' replaceable with 'isEmpty()' size.replaceable.by.isempty.quickfix=Replace with 'isEmpty()' size.replaceable.by.isempty.negation.ignore.option=Ignore expressions which would be replaced with '!isEmpty()' +ignored.classes.table=Ignored classes +choose.class.type.to.ignore=Choose class type to ignore loop.condition.not.updated.inside.loop.display.name=Loop variable not updated inside loop loop.condition.not.updated.inside.loop.problem.descriptor='#ref' is not updated inside loop #loc utility.class.without.private.constructor.option=Ignore classes with only a main method diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspection.java index 092a2d1eec21..35f57a45f222 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2011 Bas Leijdekkers + * Copyright 2006-2012 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,15 @@ package com.siyeh.ig.style; import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; +import com.intellij.codeInspection.ui.ListTable; +import com.intellij.codeInspection.ui.ListWrappingTableModel; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.tree.IElementType; +import com.intellij.psi.util.InheritanceUtil; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.containers.OrderedSet; +import com.intellij.util.ui.CheckBox; import com.siyeh.HardcodedMethodConstants; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; @@ -28,36 +32,47 @@ import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.ComparisonUtils; import com.siyeh.ig.psiutils.ExpressionUtils; +import com.siyeh.ig.ui.UiUtils; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.awt.*; public class SizeReplaceableByIsEmptyInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean ignoreNegations = false; + @SuppressWarnings("PublicField") + public OrderedSet ignoredTypes = new OrderedSet(); + @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "size.replaceable.by.isempty.display.name"); + return InspectionGadgetsBundle.message("size.replaceable.by.isempty.display.name"); } @Override @NotNull protected String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "expression.can.be.replaced.problem.descriptor", infos[0]); + return InspectionGadgetsBundle.message("expression.can.be.replaced.problem.descriptor", infos[0]); } @Override @Nullable public JComponent createOptionsPanel() { - return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message( + final JComponent panel = new JPanel(new BorderLayout()); + final ListTable table = + new ListTable(new ListWrappingTableModel(ignoredTypes, InspectionGadgetsBundle.message("ignored.classes.table"))); + JPanel tablePanel = + UiUtils.createAddRemoveTreeClassChooserPanel(table, InspectionGadgetsBundle.message("choose.class.type.to.ignore")); + final CheckBox checkBox = new CheckBox(InspectionGadgetsBundle.message( "size.replaceable.by.isempty.negation.ignore.option"), this, "ignoreNegations"); + panel.add(tablePanel, BorderLayout.CENTER); + panel.add(checkBox, BorderLayout.SOUTH); + return panel; } @Override @@ -71,8 +86,7 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection { @NotNull public String getName() { - return InspectionGadgetsBundle.message( - "size.replaceable.by.isempty.quickfix"); + return InspectionGadgetsBundle.message("size.replaceable.by.isempty.quickfix"); } @Override @@ -195,6 +209,11 @@ public class SizeReplaceableByIsEmptyInspection extends BaseInspection { if (aClass == null) { return null; } + for (String ignoredType : ignoredTypes) { + if (InheritanceUtil.isInheritor(aClass, ignoredType)) { + return null; + } + } final PsiMethod[] methods = aClass.findMethodsByName("isEmpty", true); for (PsiMethod method : methods) { final PsiParameterList parameterList = method.getParameterList(); diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/SizeReplaceableByIsEmpty.html b/plugins/InspectionGadgets/src/inspectionDescriptions/SizeReplaceableByIsEmpty.html index 6788578061bd..4f86bb745afc 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/SizeReplaceableByIsEmpty.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/SizeReplaceableByIsEmpty.html @@ -4,6 +4,10 @@ This inspection reports any .size() or .length() comparisons with a 0 literal which can be replaced with a call to .isEmpty().

+Use the table below to add classes for which any .size() or .length() comparisons should not be replaced. +

+Use the checkbox below to ignore any expressions which would be replaced with '!isEmpty()'. +

Powered by InspectionGadgets \ No newline at end of file