From 2440fa45b2ccf80b8ba8d044457a87a020832293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Mon, 30 Dec 2002 14:58:12 +0000 Subject: [PATCH] removed PublicMemberNameCheck, check public members with MemberNameCheck updated docs to reflect that change --- docs/checkstyle_checks.xml | 1 - docs/config_modifiers.html | 12 +-- docs/config_naming.html | 9 +-- docs/sun_checks.xml | 2 +- .../checkstyle/checks/MemberNameCheck.java | 4 +- .../checks/PublicMemberNameCheck.java | 79 ------------------- .../puppycrawl/tools/checkstyle/AllTests.java | 2 - .../checks/PublicMemberNameCheckTest.java | 20 ----- 8 files changed, 11 insertions(+), 118 deletions(-) delete mode 100644 src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheck.java delete mode 100644 src/tests/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheckTest.java diff --git a/docs/checkstyle_checks.xml b/docs/checkstyle_checks.xml index e53330718..ecf33ec72 100644 --- a/docs/checkstyle_checks.xml +++ b/docs/checkstyle_checks.xml @@ -74,7 +74,6 @@ - diff --git a/docs/config_modifiers.html b/docs/config_modifiers.html index 246d0de58..6b5402751 100644 --- a/docs/config_modifiers.html +++ b/docs/config_modifiers.html @@ -124,10 +124,12 @@ Language specification, section 9.4).

VisibilityModifier

- Checks visibility of class members. Only static final members may be public; - other class members must be private unless property - protectedAllowed or packageAllowed is set. + Checks visibility of class members. Only static final members + may be public; other class members must be private unless + property protectedAllowed or packageAllowed is set.

+

Public members are not flagged if the name matches the public member regular expression (contains ). class="code">"^f[A-Z][a-zA-Z0-9]*$" 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.

Rationale: Enforce encapsulation. @@ -167,7 +169,7 @@ Language specification, section 9.4). publicMemberPattern pattern for public members that should be ignored regular expression - ^f[A-Z][a-zA-Z0-9]*$ + ^serialVersionUID$

Examples

diff --git a/docs/config_naming.html b/docs/config_naming.html index 0aed4447f..859901bb8 100644 --- a/docs/config_naming.html +++ b/docs/config_naming.html @@ -63,7 +63,7 @@ MemberName - non-public, non-static fields + non-static fields ^[a-z][a-zA-Z0-9]*$ @@ -81,11 +81,6 @@ parameters ^[a-z][a-zA-Z0-9]*$ - - PublicMemberName - public, non-static fields - ^f[A-Z][a-zA-Z0-9]*$ - StaticVariableName static, non-final fields @@ -136,4 +131,4 @@ Copyright © 2002 Oliver Burn. All rights Reserved.

- \ No newline at end of file + diff --git a/docs/sun_checks.xml b/docs/sun_checks.xml index 52574af2e..120109d27 100644 --- a/docs/sun_checks.xml +++ b/docs/sun_checks.xml @@ -79,7 +79,7 @@ - + diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MemberNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MemberNameCheck.java index 129ffdc31..20e7cf3bc 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MemberNameCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/MemberNameCheck.java @@ -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)); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheck.java deleted file mode 100644 index a08defd2e..000000000 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheck.java +++ /dev/null @@ -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; - -/** - *

- * Checks that public instance variable names conform to a format specified - * by the format property. The format is a - * - * regular expression - * and defaults to - * ^f[A-Z][a-zA-Z0-9]*$. - *

- *

- * An example of how to configure the check is: - *

- *
- * <module name="PublicMemberName"/>
- * 
- *

- * An example of how to configure the check for names that begin with - *lower case letter, followed by letters and digits is: - *

- *
- * <module name="PublicMemberName">
- *    <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
- * </module>
- * 
- * - * @author Rick Giles - * @version 1.0 - */ -public class PublicMemberNameCheck - extends AbstractNameCheck -{ - /** Creates a new PublicMemberNameCheck 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)); - } -} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java b/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java index 57df9b33d..7c8b4c606 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java @@ -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)); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheckTest.java deleted file mode 100644 index 8c37bf8f8..000000000 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/PublicMemberNameCheckTest.java +++ /dev/null @@ -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); - } -} -