forked from phoedos/pmd
#1288 MethodNamingConventions for native should be deactivated
This commit is contained in:
@@ -3,17 +3,37 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.naming;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
|
||||
|
||||
public class MethodNamingConventionsRule extends AbstractJavaRule {
|
||||
|
||||
private boolean checkNativeMethods;
|
||||
|
||||
private static final BooleanProperty CHECK_NATIVE_METHODS_DESCRIPTOR = new BooleanProperty("checkNativeMethods",
|
||||
"Check native methods", true, 1.0f);
|
||||
|
||||
public MethodNamingConventionsRule() {
|
||||
definePropertyDescriptor(CHECK_NATIVE_METHODS_DESCRIPTOR);
|
||||
}
|
||||
|
||||
public Object visit(ASTCompilationUnit node, Object data) {
|
||||
checkNativeMethods = getProperty(CHECK_NATIVE_METHODS_DESCRIPTOR);
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
public Object visit(ASTMethodDeclarator node, Object data) {
|
||||
|
||||
String methodName = node.getImage();
|
||||
|
||||
if (!checkNativeMethods && node.getFirstParentOfType(ASTMethodDeclaration.class).isNative()) {
|
||||
return data;
|
||||
}
|
||||
|
||||
String methodName = node.getImage();
|
||||
|
||||
if (Character.isUpperCase(methodName.charAt(0))) {
|
||||
addViolationWithMessage(data, node, "Method names should not start with capital letters");
|
||||
addViolationWithMessage(data, node, "Method names should not start with capital letters");
|
||||
}
|
||||
if (methodName.indexOf('_') >= 0) {
|
||||
addViolationWithMessage(data, node, "Method names should not contain underscores");
|
||||
|
@@ -33,4 +33,25 @@ public class Foo {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1288 MethodNamingConventions for native should be deactivated</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<rule-property name="checkNativeMethods">false</rule-property>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
protected final native void __surfunc__(float[] data);
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1288 MethodNamingConventions for native should be deactivated - prevent false negative</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>2</expected-linenumbers>
|
||||
<rule-property name="checkNativeMethods">true</rule-property>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
protected final native void __surfunc__(float[] data);
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
@@ -4,11 +4,13 @@
|
||||
|
||||
**Feature Requests and Improvements:**
|
||||
|
||||
* [#1288](https://sourceforge.net/p/pmd/bugs/1288/): MethodNamingConventions for native should be deactivated
|
||||
* [#1293](https://sourceforge.net/p/pmd/bugs/1293/): Disable VariableNamingConventions for native methods
|
||||
|
||||
**New/Modified Rules:**
|
||||
|
||||
* [Java / Design / UseVarargs](http://pmd.sourceforge.net/pmd-java/rules/java/design.html#UseVarargs): if `byte[]` is used as the last argument, it is ignored and no violation will be reported.
|
||||
* [Java / Naming / MethodNamingConventions](http://pmd.sourceforge.net/pmd-java/rules/java/naming.html#MethodNamingConventions): New property `checkNativeMethods`
|
||||
* [Java / Naming / VariableNamingConventions](http://pmd.sourceforge.net/pmd-java/rules/java/naming.html#VariableNamingConventions): New property `checkNativeMethodParameters`
|
||||
|
||||
**Pull requests:**
|
||||
|
Reference in New Issue
Block a user