diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/EmptyClassInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/EmptyClassInspection.java index bcfd9aad82e1..c0e4787d23ee 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/EmptyClassInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/EmptyClassInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2012 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.siyeh.ig.classlayout; import com.intellij.codeInsight.AnnotationUtil; import com.intellij.codeInspection.util.SpecialAnnotationsUtil; import com.intellij.psi.*; +import com.intellij.psi.util.InheritanceUtil; import com.intellij.util.ui.CheckBox; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; @@ -34,8 +35,12 @@ public class EmptyClassInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public final ExternalizableStringSet ignorableAnnotations = new ExternalizableStringSet(); + @SuppressWarnings({"PublicField"}) public boolean ignoreClassWithParameterization = false; + @SuppressWarnings({"PublicField"}) + public boolean ignoreThrowables = true; + @Override @NotNull public String getDisplayName() { @@ -59,10 +64,26 @@ public class EmptyClassInspection extends BaseInspection { @Override public JComponent createOptionsPanel() { - final JPanel panel = SpecialAnnotationsUtil.createSpecialAnnotationsListControl( + final JPanel panel = new JPanel(new GridBagLayout()); + final JPanel annotationsListControl = SpecialAnnotationsUtil.createSpecialAnnotationsListControl( ignorableAnnotations, InspectionGadgetsBundle.message("ignore.if.annotated.by")); - panel.add(new CheckBox(InspectionGadgetsBundle.message("empty.class.ignore.parameterization.option"), - this, "ignoreClassWithParameterization"), BorderLayout.SOUTH); + final GridBagConstraints constraints = new GridBagConstraints(); + constraints.gridx = 0; + constraints.gridy = 0; + constraints.weightx = 1.0; + constraints.weighty = 1.0; + constraints.anchor = GridBagConstraints.WEST; + constraints.fill = GridBagConstraints.BOTH; + panel.add(annotationsListControl, constraints); + constraints.gridy++; + constraints.weighty = 0.0; + constraints.fill = GridBagConstraints.HORIZONTAL; + final CheckBox checkBox1 = new CheckBox(InspectionGadgetsBundle.message("empty.class.ignore.parameterization.option"), + this, "ignoreClassWithParameterization"); + panel.add(checkBox1, constraints); + constraints.gridy++; + final CheckBox checkBox2 = new CheckBox("Ignore subclasses of java.lang.Throwable", this, "ignoreThrowables"); + panel.add(checkBox2, constraints); return panel; } @@ -127,6 +148,9 @@ public class EmptyClassInspection extends BaseInspection { if (AnnotationUtil.isAnnotated(aClass, ignorableAnnotations)) { return; } + if (ignoreThrowables && InheritanceUtil.isInheritor(aClass, "java.lang.Throwable")) { + return; + } registerClassError(aClass, aClass); } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyClass.html b/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyClass.html index bbd73b5a331a..11084c2b9191 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyClass.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/EmptyClass.html @@ -1,15 +1,17 @@
-This inspection reports any empty classes or Java file without any class defined. A class is empty if it +This inspection reports empty classes and Java files without any defined classes. A class is empty if it doesn't have any fields, methods, constructors or initializers. Empty classes are often left over after large changes or refactorings.Use the list below to specify special annotations. Classes annotated with one of these annotations will be ignored by this inspection.
-Use the checkbox below to ignore classes which parameterize a super class, for example +Use the first checkbox below to ignore classes which parameterize a super class, for example
class MyList extends ArrayList<String> {}
+Use the second checkbox below to ignore classes which extend java.lang.Throwable. +
Powered by InspectionGadgets
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/emptyclass/EmptyClass.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/emptyclass/EmptyClass.java
index aa8b94f6a4f1..8c52556a7922 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/emptyclass/EmptyClass.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/emptyclass/EmptyClass.java
@@ -7,3 +7,5 @@ public class EmptyClass {
}
}
class MyList extends java.util.ArrayList