fixed bug 884035, DesignForExtension fires for private inner classes

This commit is contained in:
Lars Kühne 2004-03-23 22:28:47 +00:00
parent 8b42624fe9
commit 4039611539
3 changed files with 31 additions and 7 deletions

View File

@ -148,7 +148,7 @@
<li class="body">Ignore comments in GenericIllegalRegexp check,
contributed by Daniel Grenner (request 680988, patch 902109).
<li class="body">UnnecessaryParentheses check contributed by
<li class="body">UnnecessaryParentheses check contributed by
Eric Roe (patch 911086, request 634834)</li>
<li class="body">Added ignoreNonLocal property to UnusedParameter
@ -207,6 +207,9 @@
<li class="body">ExplicitInitialization shouldn't report about
explicitly initialized member of interface (bug 909619)</li>
<li class="body">DesignForExtension fires for private inner
classes (bug 884035).</li>
<li class="body">Entity resolver for configuration files now handles
all previous versions of the configuration DTD locally, without
accessing the internet (bug 909987).</li>

View File

@ -18,10 +18,7 @@
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.design;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
import com.puppycrawl.tools.checkstyle.api.*;
/**
* Checks that classes are designed for inheritance.
@ -53,7 +50,7 @@ import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
* </p>
*
* @author lkuehne
* @version $Revision: 1.4 $
* @version $Revision: 1.5 $
*/
public class DesignForExtensionCheck extends Check
{
@ -81,6 +78,13 @@ public class DesignForExtensionCheck extends Check
return;
}
// method is ok if containing class is not visible in API and
// cannot be extended by 3rd parties (bug #884035)
if (!ScopeUtils.getSurroundingScope(aAST).isIn(Scope.PROTECTED))
{
return;
}
// method is ok if it is implementation can verified to be empty
// Note: native methods don't have impl in java code, so
// implementation can be null even if method not abstract

View File

@ -49,7 +49,24 @@ public class InputDesignForExtension
}
// has a potentially complex implementation in native code.
// We can't check that, so to be safe DesignForExtension requirves
// We can't check that, so to be safe DesignForExtension requires
// native methods to also be final
public native void aNativeMethod();
// tries to trigger bug #884035
// MyComparator is a private class, so there cannot be subclasses
// and it should not be neccessary to declare compare() as final
private class MyComparator implements java.util.Comparator
{
public int compare(Object o1, Object o2)
{
// some complex stuff that would normally trigger an error report
if (o1.hashCode() > o2.hashCode()) {
return -1;
}
else {
return 1;
}
}
}
}