mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-98682 (Class extends utility class does not ignore on empty child classes)
This commit is contained in:
@@ -26,7 +26,7 @@ public class UtilityClassUtil {
|
||||
return isUtilityClass(aClass, true);
|
||||
}
|
||||
|
||||
public static boolean isUtilityClass(@NotNull PsiClass aClass, boolean checkExtends) {
|
||||
public static boolean isUtilityClass(@NotNull PsiClass aClass, boolean fullCheck) {
|
||||
if (aClass.isInterface() || aClass.isEnum() || aClass.isAnnotationType()) {
|
||||
return false;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class UtilityClassUtil {
|
||||
return false;
|
||||
}
|
||||
final PsiReferenceList extendsList = aClass.getExtendsList();
|
||||
if (checkExtends && extendsList != null && extendsList.getReferenceElements().length > 0) {
|
||||
if (fullCheck && extendsList != null && extendsList.getReferenceElements().length > 0) {
|
||||
return false;
|
||||
}
|
||||
final PsiReferenceList implementsList = aClass.getImplementsList();
|
||||
@@ -50,7 +50,7 @@ public class UtilityClassUtil {
|
||||
if (!allFieldsStatic(fields)) {
|
||||
return false;
|
||||
}
|
||||
return staticMethodCount != 0 || fields.length != 0;
|
||||
return (!fullCheck || staticMethodCount != 0) || fields.length != 0;
|
||||
}
|
||||
|
||||
private static boolean allFieldsStatic(PsiField[] fields) {
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.igtest.inheritance.extends_utility_class;
|
||||
|
||||
public class ExtendsUtilityClass {
|
||||
// all members are static
|
||||
|
||||
public static void member() {}
|
||||
}
|
||||
class Extender extends ExtendsUtilityClass {}
|
||||
class Extender2 extends ExtendsUtilityClass {
|
||||
|
||||
public void nonStaticMethod() {}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>ExtendsUtilityClass.java</file>
|
||||
<line>24</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Class extends utility class</problem_class>
|
||||
<description>Class <code>Extender2</code> extends utility class 'ExtendsUtilityClass' #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.siyeh.ig.inheritance;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class ExtendsUtilityClassInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
final ExtendsUtilityClassInspection tool = new ExtendsUtilityClassInspection();
|
||||
tool.ignoreUtilityClasses = true;
|
||||
doTest("com/siyeh/igtest/inheritance/extends_utility_class", tool);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user