IDEA-135101 (False positive of "Empty class")

This commit is contained in:
Bas Leijdekkers
2015-11-05 21:43:56 +01:00
parent ee80a1da3a
commit 07bc39444c
2 changed files with 24 additions and 5 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* 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.
@@ -29,11 +29,11 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class EmptyClassInspectionBase extends BaseInspection {
@SuppressWarnings({"PublicField"})
@SuppressWarnings("PublicField")
public final ExternalizableStringSet ignorableAnnotations = new ExternalizableStringSet();
@SuppressWarnings({"PublicField"})
@SuppressWarnings("PublicField")
public boolean ignoreClassWithParameterization = false;
@SuppressWarnings({"PublicField"})
@SuppressWarnings("PublicField")
public boolean ignoreThrowables = true;
@Override
@@ -76,6 +76,7 @@ public class EmptyClassInspectionBase extends BaseInspection {
@Override
public void visitFile(PsiFile file) {
super.visitFile(file);
if (!(file instanceof PsiJavaFile)) {
return;
}
@@ -92,13 +93,20 @@ public class EmptyClassInspectionBase extends BaseInspection {
@Override
public void visitClass(@NotNull PsiClass aClass) {
//don't call super, to prevent drilldown
super.visitClass(aClass);
if (FileTypeUtils.isInServerPageFile(aClass.getContainingFile())) {
return;
}
if (aClass.isInterface() || aClass.isEnum() || aClass.isAnnotationType()) {
return;
}
if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
for (PsiClass superClass : aClass.getSupers()) {
if (superClass.isInterface() || superClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
}
}
if (aClass instanceof PsiTypeParameter) {
return;
}
@@ -1,5 +1,7 @@
package com.siyeh.igtest.classlayout.emptyclass;
import java.io.Serializable;
public class EmptyClass {
{
final java.util.ArrayList<String> stringList = new java.util.ArrayList<String>() {};
@@ -9,3 +11,12 @@ public class EmptyClass {
class MyList extends java.util.ArrayList<String> {}
class MyException extends java.lang.Exception {}
abstract class <warning descr="Class 'ReportMe' is empty">ReportMe</warning> implements java.util.List {}
abstract class <warning descr="Class 'Empty1' is empty">Empty1</warning> extends <error descr="No interface expected here">Serializable</error> {}
interface Interface {
default void method() {
new Interface() { };
}
}
class EmptyClassTest implements Interface {
}