From 93de5dfd131420c133821da45edf4215d36bf1e6 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 22 Aug 2012 17:00:17 +0200 Subject: [PATCH] IDEA-90328 (Marker Interface inspection reports non marker interfaces incorrectly.) --- .../MarkerInterfaceInspection.java | 30 +++++++++++++------ .../MarkerInterface.html | 3 +- .../igtest/classlayout/MarkerInterface.java | 4 --- .../marker_interface/MarkerInterface.java | 6 ++++ .../classlayout/marker_interface/expected.xml | 17 +++++++++++ .../MarkerInterfaceInspectionTest.java | 10 +++++++ 6 files changed, 56 insertions(+), 14 deletions(-) delete mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/MarkerInterface.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/MarkerInterface.java create mode 100644 plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/expected.xml create mode 100644 plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/MarkerInterfaceInspectionTest.java diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/MarkerInterfaceInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/MarkerInterfaceInspection.java index 4b65470c012f..989405f0c338 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/MarkerInterfaceInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/classlayout/MarkerInterfaceInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 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. @@ -15,10 +15,7 @@ */ package com.siyeh.ig.classlayout; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiClassType; -import com.intellij.psi.PsiField; -import com.intellij.psi.PsiMethod; +import com.intellij.psi.*; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; @@ -26,17 +23,20 @@ import org.jetbrains.annotations.NotNull; public class MarkerInterfaceInspection extends BaseInspection { + @Override @NotNull public String getDisplayName() { return InspectionGadgetsBundle.message("marker.interface.display.name"); } + @Override @NotNull protected String buildErrorString(Object... infos) { return InspectionGadgetsBundle.message( "marker.interface.problem.descriptor"); } + @Override public BaseInspectionVisitor buildVisitor() { return new MarkerInterfaceVisitor(); } @@ -45,7 +45,6 @@ public class MarkerInterfaceInspection extends BaseInspection { @Override public void visitClass(@NotNull PsiClass aClass) { - // no call to super, so that it doesn't drill down to inner classes if (!aClass.isInterface() || aClass.isAnnotationType()) { return; } @@ -57,9 +56,22 @@ public class MarkerInterfaceInspection extends BaseInspection { if (methods.length != 0) { return; } - final PsiClassType[] extendsList = aClass.getExtendsListTypes(); - if (extendsList.length > 1) { - return; + final PsiReferenceList extendsList = aClass.getExtendsList(); + if (extendsList != null) { + final PsiJavaCodeReferenceElement[] referenceElements = extendsList.getReferenceElements(); + if (referenceElements.length > 0) { + if (referenceElements.length > 1) { + return; + } + final PsiReferenceParameterList parameterList = referenceElements[0].getParameterList(); + if (parameterList == null) { + return; + } + final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements(); + if (typeParameterElements.length != 0) { + return; + } + } } registerClassError(aClass); } diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/MarkerInterface.html b/plugins/InspectionGadgets/src/inspectionDescriptions/MarkerInterface.html index 502650107988..37abc13b9278 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/MarkerInterface.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/MarkerInterface.html @@ -2,7 +2,8 @@ This inspection reports "marker" interfaces which have no methods or fields. Such interfaces may be confusing, and normally indicate a design failure. -Interfaces which extend two or more other interfaces will not be reported by +Interfaces which extend two or more other interfaces or or interfaces +which specialize the generic type of their superinterface will not be reported by this inspection.

diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/MarkerInterface.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/MarkerInterface.java deleted file mode 100644 index 69bf2830166c..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/MarkerInterface.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.siyeh.igtest.classlayout; - -public interface MarkerInterface { -} diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/MarkerInterface.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/MarkerInterface.java new file mode 100644 index 000000000000..baa443e8f28c --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/MarkerInterface.java @@ -0,0 +1,6 @@ +package com.siyeh.igtest.classlayout.marker_interface; + +public interface MarkerInterface { +} +interface X {} +interface Y extends X {} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/expected.xml new file mode 100644 index 000000000000..dccbd2499e3a --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/classlayout/marker_interface/expected.xml @@ -0,0 +1,17 @@ + + + + + MarkerInterface.java + 3 + Marker interface + Marker interface <code>MarkerInterface</code> #loc + + + + MarkerInterface.java + 5 + Marker interface + Marker interface <code>X</code> #loc + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/MarkerInterfaceInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/MarkerInterfaceInspectionTest.java new file mode 100644 index 000000000000..3c2981fe8fa2 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/classlayout/MarkerInterfaceInspectionTest.java @@ -0,0 +1,10 @@ +package com.siyeh.ig.classlayout; + +import com.siyeh.ig.IGInspectionTestCase; + +public class MarkerInterfaceInspectionTest extends IGInspectionTestCase { + + public void test() throws Exception { + doTest("com/siyeh/igtest/classlayout/marker_interface", new MarkerInterfaceInspection()); + } +} \ No newline at end of file