IG: fix "Unchecked exception class" inspection

This commit is contained in:
Bas Leijdekkers
2015-05-13 16:47:46 +02:00
parent d5aad3da7f
commit 6bbb76cbf3
3 changed files with 45 additions and 11 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2015 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.
@@ -44,19 +44,11 @@ public class UncheckedExceptionClassInspection extends BaseInspection {
return new UncheckedExceptionClassVisitor();
}
private static class UncheckedExceptionClassVisitor
extends BaseInspectionVisitor {
private static class UncheckedExceptionClassVisitor extends BaseInspectionVisitor {
@Override
public void visitClass(@NotNull PsiClass aClass) {
if (!InheritanceUtil.isInheritor(aClass,
CommonClassNames.JAVA_LANG_THROWABLE)) {
return;
}
if (InheritanceUtil.isInheritor(aClass,
CommonClassNames.JAVA_LANG_EXCEPTION) &&
!InheritanceUtil.isInheritor(aClass,
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
if (!InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
return;
}
registerClassError(aClass);
@@ -0,0 +1,5 @@
public class <warning descr="Unchecked exception class 'UncheckedExceptionClass'">UncheckedExceptionClass</warning> extends RuntimeException {
}
class E1 extends Throwable {}
class E2 extends Exception {}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.errorhandling;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import junit.framework.TestCase;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class UncheckedExceptionClassInspectionTest extends LightInspectionTestCase {
public void testUncheckedExceptionClass() {
doTest();
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new UncheckedExceptionClassInspection();
}
}