IDEA-100840 ("No-op method in abstract class": Complains about native methods)

This commit is contained in:
Bas Leijdekkers
2013-02-11 21:09:30 +01:00
parent 40663aef8f
commit 149159c6cf
4 changed files with 33 additions and 11 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2013 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.
@@ -28,26 +28,22 @@ public class NoopMethodInAbstractClassInspection extends BaseInspection {
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"noop.method.in.abstract.class.display.name");
return InspectionGadgetsBundle.message("noop.method.in.abstract.class.display.name");
}
@NotNull
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"noop.method.in.abstract.class.problem.descriptor");
return InspectionGadgetsBundle.message("noop.method.in.abstract.class.problem.descriptor");
}
public BaseInspectionVisitor buildVisitor() {
return new NoopMethodInAbstractClassVisitor();
}
private static class NoopMethodInAbstractClassVisitor
extends BaseInspectionVisitor {
private static class NoopMethodInAbstractClassVisitor extends BaseInspectionVisitor {
@Override
public void visitMethod(@NotNull PsiMethod method) {
//no call to super, so we don't drill into anonymous classes
if (method.isConstructor()) {
return;
}
@@ -55,14 +51,13 @@ public class NoopMethodInAbstractClassInspection extends BaseInspection {
if (containingClass == null) {
return;
}
if (containingClass.isInterface() ||
containingClass.isAnnotationType()) {
if (containingClass.isInterface() || containingClass.isAnnotationType()) {
return;
}
if (!containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return;
}
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
if (method.hasModifierProperty(PsiModifier.ABSTRACT) || method.hasModifierProperty(PsiModifier.NATIVE)) {
return;
}
if (!MethodUtils.isEmpty(method)) {
@@ -0,0 +1,8 @@
package com.siyeh.igtest.classlayout.noop_method_in_abstract_class;
abstract class NoopMethodInAbstractClass {
void foo() {}
native int bar();
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>NoopMethodInAbstractClass.java</file>
<line>5</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">No-op method in abstract class</problem_class>
<description>No-op Method &lt;code&gt;foo()&lt;/code&gt; should be made abstract #loc</description>
</problem>
</problems>
@@ -0,0 +1,10 @@
package com.siyeh.ig.classlayout;
import com.siyeh.ig.IGInspectionTestCase;
public class NoopMethodInAbstractClassInspectionTest extends IGInspectionTestCase {
public void test() throws Exception {
doTest("com/siyeh/igtest/classlayout/noop_method_in_abstract_class", new NoopMethodInAbstractClassInspection());
}
}