mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-82368 (Add "Ignore for exceptions" for EmptyClass inspection)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<html>
|
||||
<body>
|
||||
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.
|
||||
<p>
|
||||
Use the list below to specify special annotations. Classes annotated with one of
|
||||
these annotations will be ignored by this inspection.
|
||||
<p>
|
||||
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
|
||||
<pre><code><b>class</b> MyList <b>extends</b> ArrayList<String> {}</code></pre>
|
||||
<p>
|
||||
Use the second checkbox below to ignore classes which extend <b>java.lang.Throwable</b>.
|
||||
<p>
|
||||
<small>Powered by InspectionGadgets</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -7,3 +7,5 @@ public class EmptyClass {
|
||||
}
|
||||
}
|
||||
class MyList extends java.util.ArrayList<String> {}
|
||||
class MyException extends java.lang.Exception {}
|
||||
abstract class ReportMe implements java.util.List {}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
|
||||
<problem>
|
||||
<file>EmptyClass.java</file>
|
||||
<line>11</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Empty class</problem_class>
|
||||
<description>Class <code>ReportMe</code> is empty #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+1
@@ -7,6 +7,7 @@ public class EmptyClassInspectionTest extends IGInspectionTestCase {
|
||||
public void test() throws Exception {
|
||||
final EmptyClassInspection tool = new EmptyClassInspection();
|
||||
tool.ignoreClassWithParameterization = true;
|
||||
tool.ignoreThrowables = true;
|
||||
doTest("com/siyeh/igtest/classlayout/emptyclass", tool);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user