removed PublicMemberNameCheck, check public members with MemberNameCheck

updated docs to reflect that change
This commit is contained in:
Lars Kühne 2002-12-30 14:58:12 +00:00
parent 51d759b703
commit 2440fa45b2
8 changed files with 11 additions and 118 deletions

View File

@ -74,7 +74,6 @@
</module>
<module name="ParameterNumber"/>
<module name="ParenPad"/>
<module name="PublicMemberName"/>
<module name="RedundantImport"/>
<module name="RedundantModifier"/>
<module name="RightCurly">

View File

@ -124,10 +124,12 @@ Language specification, section 9.4</a>).
<a name="VisibilityModifier"></a><h2>VisibilityModifier</h2>
<p class="body">
Checks visibility of class members. Only static final members may be public;
other class members must be private unless property <span class="code">
protectedAllowed</span> or <span class="code">packageAllowed</span> is set.
Checks visibility of class members. Only static final members
may be public; other class members must be private unless
property <span class="code">protectedAllowed</span> or <span
class="code">packageAllowed</span> is set.
</p>
<p class="body">
Public members are not flagged if the name matches the public
member regular expression (contains <span
@ -136,7 +138,7 @@ Language specification, section 9.4</a>).
class="code">"^f[A-Z][a-zA-Z0-9]*$"</span> in the default
pattern to allow CMP for EJB 1.1 with the default settings.
With EJB 2.0 it is not longer necessary to have public access
for persistent fields.
for persistent fields, hence the default has been changed.
</p>
<p class="body">
Rationale: Enforce encapsulation.
@ -167,7 +169,7 @@ Language specification, section 9.4</a>).
<td>publicMemberPattern</td>
<td>pattern for public members that should be ignored</td>
<td><a href="property_types.html#regexp">regular expression</a></td>
<td><span class="default">^f[A-Z][a-zA-Z0-9]*$</span></td>
<td><span class="default">^serialVersionUID$</span></td>
</tr>
</table>
<h4>Examples</h4>

View File

@ -63,7 +63,7 @@
</tr>
<tr>
<td><span class="code">MemberName</span></td>
<td>non-<span class="code">public</span>, non-<span class="code">static</span> fields</td>
<td>non-<span class="code">static</span> fields</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
@ -81,11 +81,6 @@
<td>parameters</td>
<td><span class="default">^[a-z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">PublicMemberName</span></td>
<td><span class="code">public</span>, non-<span class="code">static</span> fields</td>
<td><span class="default">^f[A-Z][a-zA-Z0-9]*$</span></td>
</tr>
<tr>
<td><span class="code">StaticVariableName</span></td>
<td><span class="code">static</span>, non-<span class="code">final</span> fields</td>
@ -136,4 +131,4 @@ Copyright &copy; 2002 Oliver Burn. All rights Reserved.
</p>
</body>
</html>
</html>

View File

@ -79,7 +79,7 @@
<!-- don't create new instances of Boolean,
use Boolean.TRUE/FALSE or Boolean.valueOf() instead -->
<module name="IllegalInstantiation">
<property name="" value="java.lang.Boolean"/>
<property name="classes" value="java.lang.Boolean"/>
</module>

View File

@ -71,10 +71,8 @@ public class MemberNameCheck
DetailAST modifiersAST = aAST.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
final boolean isPublic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_PUBLIC);
return (!isStatic && !isPublic && !ScopeUtils.inInterfaceBlock(aAST)
return (!isStatic && !ScopeUtils.inInterfaceBlock(aAST)
&& !ScopeUtils.inCodeBlock(aAST));
}
}

View File

@ -1,79 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2002 Oliver Burn
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* <p>
* Checks that public instance variable names conform to a format specified
* by the format property. The format is a
* <a href="http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html">
* regular expression</a>
* and defaults to
* <strong>^f[A-Z][a-zA-Z0-9]*$</strong>.
* </p>
* <p>
* An example of how to configure the check is:
* </p>
* <pre>
* &lt;module name="PublicMemberName"/&gt;
* </pre>
* <p>
* An example of how to configure the check for names that begin with
*lower case letter, followed by letters and digits is:
* </p>
* <pre>
* &lt;module name="PublicMemberName"&gt;
* &lt;property name="format" value="^[a-z][a-zA-Z0-9]*$"/&gt;
* &lt;/module&gt;
* </pre>
*
* @author Rick Giles
* @version 1.0
*/
public class PublicMemberNameCheck
extends AbstractNameCheck
{
/** Creates a new <code>PublicMemberNameCheck</code> instance. */
public PublicMemberNameCheck()
{
super("^f[A-Z][a-zA-Z0-9]*$");
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {TokenTypes.VARIABLE_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.checks.AbstractNameCheck */
protected final boolean mustCheckName(DetailAST aAST)
{
DetailAST modifiersAST = aAST.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_STATIC);
final boolean isPublic = (modifiersAST != null)
&& modifiersAST.branchContains(TokenTypes.LITERAL_PUBLIC);
return (!isStatic && isPublic && !ScopeUtils.inInterfaceBlock(aAST));
}
}

View File

@ -33,7 +33,6 @@ import com.puppycrawl.tools.checkstyle.checks.PackageNameCheckTest;
import com.puppycrawl.tools.checkstyle.checks.ParameterNameCheckTest;
import com.puppycrawl.tools.checkstyle.checks.ParameterNumberCheckTest;
import com.puppycrawl.tools.checkstyle.checks.ParenPadCheckTest;
import com.puppycrawl.tools.checkstyle.checks.PublicMemberNameCheckTest;
import com.puppycrawl.tools.checkstyle.checks.RedundantImportCheckTest;
import com.puppycrawl.tools.checkstyle.checks.RedundantModifierTest;
import com.puppycrawl.tools.checkstyle.checks.RightCurlyCheckTest;
@ -108,7 +107,6 @@ public class AllTests {
suite.addTest(new TestSuite(ParameterNameCheckTest.class));
suite.addTest(new TestSuite(ParameterNumberCheckTest.class));
suite.addTest(new TestSuite(ParenPadCheckTest.class));
suite.addTest(new TestSuite(PublicMemberNameCheckTest.class));
suite.addTest(new TestSuite(RedundantImportCheckTest.class));
suite.addTest(new TestSuite(RedundantModifierTest.class));
suite.addTest(new TestSuite(RightCurlyCheckTest.class));

View File

@ -1,20 +0,0 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class PublicMemberNameCheckTest
extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(PublicMemberNameCheck.class);
final String[] expected = {
"58:16: Name 'mTest2' must match pattern '^f[A-Z][a-zA-Z0-9]*$'.",
};
verify(checkConfig, getPath("InputSimple.java"), expected);
}
}