Fix for SuperClone and SuperFinalize checks reporting violations on

native methods, #1367
This commit is contained in:
Vladislav Lisetskiy 2015-07-19 21:30:17 +03:00 committed by Roman Ivanov
parent 0516374351
commit 068a1b4533
6 changed files with 19 additions and 5 deletions

View File

@ -229,7 +229,9 @@ public abstract class AbstractSuperCheck
}
final DetailAST nameAST = ast.findFirstToken(TokenTypes.IDENT);
final String name = nameAST.getText();
if (!getMethodName().equals(name)) {
final DetailAST modifiersAST = ast.findFirstToken(TokenTypes.MODIFIERS);
if (!getMethodName().equals(name)
|| modifiersAST.branchContains(TokenTypes.LITERAL_NATIVE)) {
return false;
}
final DetailAST params = ast.findFirstToken(TokenTypes.PARAMETERS);

View File

@ -23,6 +23,7 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
/**
* <p>
* Checks that an overriding clone() method invokes super.clone().
* Does not check native methods, as they have no possible java defined implementation.
* </p>
* <p>
* Reference:<a

View File

@ -23,6 +23,7 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
/**
* <p>
* Checks that an overriding finalize() method invokes super.finalize().
* Does not check native methods, as they have no possible java defined implementation.
* </p>
* <p>
* Reference:<a

View File

@ -93,3 +93,7 @@ class AnotherClass {
return null;
}
}
class NativeTest {
public native Object clone();
}

View File

@ -51,3 +51,7 @@ class MyClassWithGenericSuperMethod1
}
}
class TestNative {
public native void finalize();
}

View File

@ -1564,8 +1564,9 @@ if (&quot;something&quot;.equals(x))
<section name="SuperClone">
<subsection name="Description">
<p>
Checks that an overriding <code>clone()</code> method
invokes <code>super.clone()</code>.
Checks that an overriding <code>clone()</code> method invokes
<code>super.clone()</code>. Does not check native methods, as
they have no possible java defined implementation.
</p>
<p>
@ -1599,8 +1600,9 @@ if (&quot;something&quot;.equals(x))
<section name="SuperFinalize">
<subsection name="Description">
<p>
Checks that an overriding <code>finalize()</code>
method invokes <code>super.finalize()</code>.
Checks that an overriding <code>finalize()</code> method invokes
<code>super.finalize()</code>. Does not check native methods, as
they have no possible java defined implementation.
</p>
<p>