mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-90328 (Marker Interface inspection reports non marker interfaces incorrectly.)
This commit is contained in:
+21
-9
@@ -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);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
<body>
|
||||
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.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.siyeh.igtest.classlayout;
|
||||
|
||||
public interface MarkerInterface {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.siyeh.igtest.classlayout.marker_interface;
|
||||
|
||||
public interface MarkerInterface {
|
||||
}
|
||||
interface X<T> {}
|
||||
interface Y extends X<String> {}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
|
||||
<problem>
|
||||
<file>MarkerInterface.java</file>
|
||||
<line>3</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Marker interface</problem_class>
|
||||
<description>Marker interface <code>MarkerInterface</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>MarkerInterface.java</file>
|
||||
<line>5</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Marker interface</problem_class>
|
||||
<description>Marker interface <code>X</code> #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+10
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user