Prefixes, design, #512

This commit is contained in:
alexkravin 2015-01-11 14:10:32 +04:00
parent 89a51ba032
commit 50c9bb69bc
9 changed files with 165 additions and 165 deletions

View File

@ -64,15 +64,15 @@ public class DesignForExtensionCheck extends Check
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
// nothing to do for Interfaces
if (ScopeUtils.inInterfaceOrAnnotationBlock(aAST)) {
if (ScopeUtils.inInterfaceOrAnnotationBlock(ast)) {
return;
}
// method is ok if it is private or abstract or final
final DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS);
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
if (modifiers.branchContains(TokenTypes.LITERAL_PRIVATE)
|| modifiers.branchContains(TokenTypes.ABSTRACT)
|| modifiers.branchContains(TokenTypes.FINAL)
@ -83,14 +83,14 @@ public class DesignForExtensionCheck extends Check
// 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)) {
if (!ScopeUtils.getSurroundingScope(ast).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
final DetailAST implementation = aAST.findFirstToken(TokenTypes.SLIST);
final DetailAST implementation = ast.findFirstToken(TokenTypes.SLIST);
if ((implementation != null)
&& (implementation.getFirstChild().getType() == TokenTypes.RCURLY))
{
@ -98,7 +98,7 @@ public class DesignForExtensionCheck extends Check
}
// check if the containing class can be subclassed
final DetailAST classDef = findContainingClass(aAST);
final DetailAST classDef = findContainingClass(ast);
final DetailAST classMods =
classDef.findFirstToken(TokenTypes.MODIFIERS);
if ((classDef.getType() == TokenTypes.ENUM_DEF)
@ -130,8 +130,8 @@ public class DesignForExtensionCheck extends Check
}
if (hasDefaultConstructor || hasExplNonPrivateCtor) {
final String name = aAST.findFirstToken(TokenTypes.IDENT).getText();
log(aAST.getLineNo(), aAST.getColumnNo(),
final String name = ast.findFirstToken(TokenTypes.IDENT).getText();
log(ast.getLineNo(), ast.getColumnNo(),
"design.forExtension", name);
}
@ -141,12 +141,12 @@ public class DesignForExtensionCheck extends Check
/**
* Searches the tree towards the root until it finds a CLASS_DEF node.
* @param aAST the start node for searching
* @param ast the start node for searching
* @return the CLASS_DEF node.
*/
private DetailAST findContainingClass(DetailAST aAST)
private DetailAST findContainingClass(DetailAST ast)
{
DetailAST searchAST = aAST;
DetailAST searchAST = ast;
while ((searchAST.getType() != TokenTypes.CLASS_DEF)
&& (searchAST.getType() != TokenTypes.ENUM_DEF))
{

View File

@ -41,7 +41,7 @@ public class FinalClassCheck
extends Check
{
/** Keeps ClassDesc objects for stack of declared classes. */
private final FastStack<ClassDesc> mClasses = FastStack.newInstance();
private final FastStack<ClassDesc> classes = FastStack.newInstance();
@Override
public int[] getDefaultTokens()
@ -50,19 +50,19 @@ public class FinalClassCheck
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
final DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS);
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
if (aAST.getType() == TokenTypes.CLASS_DEF) {
if (ast.getType() == TokenTypes.CLASS_DEF) {
final boolean isFinal = (modifiers != null)
&& modifiers.branchContains(TokenTypes.FINAL);
final boolean isAbstract = (modifiers != null)
&& modifiers.branchContains(TokenTypes.ABSTRACT);
mClasses.push(new ClassDesc(isFinal, isAbstract));
classes.push(new ClassDesc(isFinal, isAbstract));
}
else if (!ScopeUtils.inEnumBlock(aAST)) { //ctors in enums don't matter
final ClassDesc desc = mClasses.peek();
else if (!ScopeUtils.inEnumBlock(ast)) { //ctors in enums don't matter
final ClassDesc desc = classes.peek();
if ((modifiers != null)
&& modifiers.branchContains(TokenTypes.LITERAL_PRIVATE))
{
@ -75,21 +75,21 @@ public class FinalClassCheck
}
@Override
public void leaveToken(DetailAST aAST)
public void leaveToken(DetailAST ast)
{
if (aAST.getType() != TokenTypes.CLASS_DEF) {
if (ast.getType() != TokenTypes.CLASS_DEF) {
return;
}
final ClassDesc desc = mClasses.pop();
final ClassDesc desc = classes.pop();
if (!desc.isDeclaredAsFinal()
&& !desc.isDeclaredAsAbstract()
&& desc.hasPrivateCtor()
&& !desc.hasNonPrivateCtor())
{
final String className =
aAST.findFirstToken(TokenTypes.IDENT).getText();
log(aAST.getLineNo(), "final.class", className);
ast.findFirstToken(TokenTypes.IDENT).getText();
log(ast.getLineNo(), "final.class", className);
}
}
@ -97,40 +97,40 @@ public class FinalClassCheck
private static final class ClassDesc
{
/** is class declared as final */
private final boolean mDeclaredAsFinal;
private final boolean declaredAsFinal;
/** is class declared as abstract */
private final boolean mDeclaredAsAbstract;
private final boolean declaredAsAbstract;
/** does class have non-provate ctors */
private boolean mHasNonPrivateCtor;
private boolean hasNonPrivateCtor;
/** does class have private ctors */
private boolean mHasPrivateCtor;
private boolean hasPrivateCtor;
/**
* create a new ClassDesc instance.
* @param aDeclaredAsFinal indicates if the
* @param declaredAsFinal indicates if the
* class declared as final
* @param aDeclaredAsAbstract indicates if the
* @param declaredAsAbstract indicates if the
* class declared as abstract
*/
ClassDesc(boolean aDeclaredAsFinal, boolean aDeclaredAsAbstract)
ClassDesc(boolean declaredAsFinal, boolean declaredAsAbstract)
{
mDeclaredAsFinal = aDeclaredAsFinal;
mDeclaredAsAbstract = aDeclaredAsAbstract;
this.declaredAsFinal = declaredAsFinal;
this.declaredAsAbstract = declaredAsAbstract;
}
/** adds private ctor. */
void reportPrivateCtor()
{
mHasPrivateCtor = true;
hasPrivateCtor = true;
}
/** adds non-private ctor. */
void reportNonPrivateCtor()
{
mHasNonPrivateCtor = true;
hasNonPrivateCtor = true;
}
/**
@ -139,7 +139,7 @@ public class FinalClassCheck
*/
boolean hasPrivateCtor()
{
return mHasPrivateCtor;
return hasPrivateCtor;
}
/**
@ -148,7 +148,7 @@ public class FinalClassCheck
*/
boolean hasNonPrivateCtor()
{
return mHasNonPrivateCtor;
return hasNonPrivateCtor;
}
/**
@ -157,7 +157,7 @@ public class FinalClassCheck
*/
boolean isDeclaredAsFinal()
{
return mDeclaredAsFinal;
return declaredAsFinal;
}
/**
@ -166,7 +166,7 @@ public class FinalClassCheck
*/
boolean isDeclaredAsAbstract()
{
return mDeclaredAsAbstract;
return declaredAsAbstract;
}
@Override
@ -174,10 +174,10 @@ public class FinalClassCheck
{
return this.getClass().getName()
+ "["
+ "final=" + mDeclaredAsFinal
+ " abstract=" + mDeclaredAsAbstract
+ " pctor=" + mHasPrivateCtor
+ " ctor=" + mHasNonPrivateCtor
+ "final=" + declaredAsFinal
+ " abstract=" + declaredAsAbstract
+ " pctor=" + hasPrivateCtor
+ " ctor=" + hasNonPrivateCtor
+ "]";
}
}

View File

@ -41,16 +41,16 @@ public class HideUtilityClassConstructorCheck extends Check
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
if (isAbstract(aAST)) {
if (isAbstract(ast)) {
// abstract class could not have private constructor
return;
}
final DetailAST objBlock = aAST.findFirstToken(TokenTypes.OBJBLOCK);
final DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK);
DetailAST child = objBlock.getFirstChild();
final boolean hasStaticModifier = isStatic(aAST);
final boolean hasStaticModifier = isStatic(ast);
boolean hasMethodOrField = false;
boolean hasNonStaticMethodOrField = false;
boolean hasNonPrivateStaticMethodOrField = false;
@ -100,33 +100,33 @@ public class HideUtilityClassConstructorCheck extends Check
// TODO: check for "extends java.lang.Object" and "extends Object"
// consider "import org.omg.CORBA.*"
final boolean extendsJLO = // J.Lo even made it into in our sources :-)
aAST.findFirstToken(TokenTypes.EXTENDS_CLAUSE) == null;
ast.findFirstToken(TokenTypes.EXTENDS_CLAUSE) == null;
final boolean isUtilClass = extendsJLO && hasMethodOrField
&& !hasNonStaticMethodOrField && hasNonPrivateStaticMethodOrField;
if (isUtilClass && (hasAccessibleCtor && !hasStaticModifier)) {
log(aAST.getLineNo(), aAST.getColumnNo(), "hide.utility.class");
log(ast.getLineNo(), ast.getColumnNo(), "hide.utility.class");
}
}
/**
* @param aAST class definition for check.
* @param ast class definition for check.
* @return true if a given class declared as abstract.
*/
private boolean isAbstract(DetailAST aAST)
private boolean isAbstract(DetailAST ast)
{
return aAST.findFirstToken(TokenTypes.MODIFIERS)
return ast.findFirstToken(TokenTypes.MODIFIERS)
.branchContains(TokenTypes.ABSTRACT);
}
/**
* @param aAST class definition for check.
* @param ast class definition for check.
* @return true if a given class declared as static.
*/
private boolean isStatic(DetailAST aAST)
private boolean isStatic(DetailAST ast)
{
return aAST.findFirstToken(TokenTypes.MODIFIERS)
return ast.findFirstToken(TokenTypes.MODIFIERS)
.branchContains(TokenTypes.LITERAL_STATIC);
}
}

View File

@ -40,19 +40,19 @@ public class InnerTypeLastCheck extends Check
}
/** Meet a root class. */
private boolean mRootClass = true;
private boolean rootClass = true;
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
/** First root class */
if (mRootClass) {
mRootClass = false;
if (rootClass) {
rootClass = false;
}
else {
DetailAST nextSibling = aAST.getNextSibling();
DetailAST nextSibling = ast.getNextSibling();
while (null != nextSibling) {
if (!ScopeUtils.inCodeBlock(aAST)
if (!ScopeUtils.inCodeBlock(ast)
&& (nextSibling.getType() == TokenTypes.VARIABLE_DEF
|| nextSibling.getType() == TokenTypes.METHOD_DEF))
{
@ -65,11 +65,11 @@ public class InnerTypeLastCheck extends Check
}
@Override
public void leaveToken(DetailAST aAST)
public void leaveToken(DetailAST ast)
{
/** Is this a root class */
if (null == aAST.getParent()) {
mRootClass = true;
if (null == ast.getParent()) {
rootClass = true;
}
}
}

View File

@ -44,7 +44,7 @@ public final class InterfaceIsTypeCheck
extends Check
{
/** flag to control whether marker interfaces are allowed. */
private boolean mAllowMarkerInterfaces = true;
private boolean allowMarkerInterfaces = true;
@Override
public int[] getDefaultTokens()
@ -59,29 +59,29 @@ public final class InterfaceIsTypeCheck
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
final DetailAST objBlock =
aAST.findFirstToken(TokenTypes.OBJBLOCK);
ast.findFirstToken(TokenTypes.OBJBLOCK);
final DetailAST methodDef =
objBlock.findFirstToken(TokenTypes.METHOD_DEF);
final DetailAST variableDef =
objBlock.findFirstToken(TokenTypes.VARIABLE_DEF);
final boolean methodRequired =
!mAllowMarkerInterfaces || (variableDef != null);
!allowMarkerInterfaces || (variableDef != null);
if ((methodDef == null) && methodRequired) {
log(aAST.getLineNo(), "interface.type");
log(ast.getLineNo(), "interface.type");
}
}
/**
* Controls whether marker interfaces like Serializable are allowed.
* @param aFlag whether to allow marker interfaces or not
* @param flag whether to allow marker interfaces or not
*/
public void setAllowMarkerInterfaces(boolean aFlag)
public void setAllowMarkerInterfaces(boolean flag)
{
mAllowMarkerInterfaces = aFlag;
allowMarkerInterfaces = flag;
}
}

View File

@ -41,11 +41,11 @@ public final class MutableExceptionCheck extends AbstractFormatCheck
/** Default value for format and extendedClassNameFormat properties. */
private static final String DEFAULT_FORMAT = "^.*Exception$|^.*Error$|^.*Throwable$";
/** Pattern for class name that is being extended */
private String mExtendedClassNameFormat;
private String extendedClassNameFormat;
/** Stack of checking information for classes. */
private final FastStack<Boolean> mCheckingStack = FastStack.newInstance();
private final FastStack<Boolean> checkingStack = FastStack.newInstance();
/** Should we check current class or not. */
private boolean mChecking;
private boolean checking;
/** Creates new instance of the check. */
public MutableExceptionCheck()
@ -56,11 +56,11 @@ public final class MutableExceptionCheck extends AbstractFormatCheck
/**
* Sets the format of extended class name to the specified regular expression.
* @param aExtendedClassNameFormat a <code>String</code> value
* @param extendedClassNameFormat a <code>String</code> value
*/
public void setExtendedClassNameFormat(String aExtendedClassNameFormat)
public void setExtendedClassNameFormat(String extendedClassNameFormat)
{
mExtendedClassNameFormat = aExtendedClassNameFormat;
this.extendedClassNameFormat = extendedClassNameFormat;
}
@Override
@ -76,24 +76,24 @@ public final class MutableExceptionCheck extends AbstractFormatCheck
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
switch (aAST.getType()) {
switch (ast.getType()) {
case TokenTypes.CLASS_DEF:
visitClassDef(aAST);
visitClassDef(ast);
break;
case TokenTypes.VARIABLE_DEF:
visitVariableDef(aAST);
visitVariableDef(ast);
break;
default:
throw new IllegalStateException(aAST.toString());
throw new IllegalStateException(ast.toString());
}
}
@Override
public void leaveToken(DetailAST aAST)
public void leaveToken(DetailAST ast)
{
switch (aAST.getType()) {
switch (ast.getType()) {
case TokenTypes.CLASS_DEF:
leaveClassDef();
break;
@ -104,59 +104,59 @@ public final class MutableExceptionCheck extends AbstractFormatCheck
/**
* Called when we start processing class definition.
* @param aAST class definition node
* @param ast class definition node
*/
private void visitClassDef(DetailAST aAST)
private void visitClassDef(DetailAST ast)
{
mCheckingStack.push(mChecking ? Boolean.TRUE : Boolean.FALSE);
mChecking = isNamedAsException(aAST) && isExtendedClassNamedAsException(aAST);
checkingStack.push(checking ? Boolean.TRUE : Boolean.FALSE);
checking = isNamedAsException(ast) && isExtendedClassNamedAsException(ast);
}
/** Called when we leave class definition. */
private void leaveClassDef()
{
mChecking = mCheckingStack.pop();
checking = checkingStack.pop();
}
/**
* Checks variable definition.
* @param aAST variable def node for check
* @param ast variable def node for check
*/
private void visitVariableDef(DetailAST aAST)
private void visitVariableDef(DetailAST ast)
{
if (mChecking && (aAST.getParent().getType() == TokenTypes.OBJBLOCK)) {
if (checking && (ast.getParent().getType() == TokenTypes.OBJBLOCK)) {
final DetailAST modifiersAST =
aAST.findFirstToken(TokenTypes.MODIFIERS);
ast.findFirstToken(TokenTypes.MODIFIERS);
if (modifiersAST.findFirstToken(TokenTypes.FINAL) == null) {
log(aAST.getLineNo(), aAST.getColumnNo(), "mutable.exception",
aAST.findFirstToken(TokenTypes.IDENT).getText());
log(ast.getLineNo(), ast.getColumnNo(), "mutable.exception",
ast.findFirstToken(TokenTypes.IDENT).getText());
}
}
}
/**
* @param aAST class definition node
* @param ast class definition node
* @return true if a class name conforms to specified format
*/
private boolean isNamedAsException(DetailAST aAST)
private boolean isNamedAsException(DetailAST ast)
{
final String className = aAST.findFirstToken(TokenTypes.IDENT).getText();
final String className = ast.findFirstToken(TokenTypes.IDENT).getText();
return getRegexp().matcher(className).find();
}
/**
* @param aAST class definition node
* @param ast class definition node
* @return true if extended class name conforms to specified format
*/
private boolean isExtendedClassNamedAsException(DetailAST aAST)
private boolean isExtendedClassNamedAsException(DetailAST ast)
{
final DetailAST extendsClause = aAST.findFirstToken(TokenTypes.EXTENDS_CLAUSE);
final DetailAST extendsClause = ast.findFirstToken(TokenTypes.EXTENDS_CLAUSE);
if (extendsClause != null) {
final DetailAST extendedClass = extendsClause.findFirstToken(TokenTypes.IDENT);
if (extendedClass != null) {
final String extendedClassName = extendedClass.getText();
return extendedClassName.matches(mExtendedClassNameFormat);
return extendedClassName.matches(extendedClassNameFormat);
}
}
return false;

View File

@ -84,10 +84,10 @@ public class OneTopLevelClassCheck extends Check
* True if a java source file contains a type
* with a public access level modifier.
*/
private boolean mPublicTypeFound;
private boolean publicTypeFound;
/** Mapping between type names and line numbers of the type declarations.*/
private TreeMap<Integer, String> mLineNumberTypeMap =
private TreeMap<Integer, String> lineNumberTypeMap =
new TreeMap<Integer, String>();
@Override
@ -97,22 +97,22 @@ public class OneTopLevelClassCheck extends Check
}
@Override
public void beginTree(DetailAST aRootAST)
public void beginTree(DetailAST rootAST)
{
DetailAST currentNode = aRootAST;
DetailAST currentNode = rootAST;
while (currentNode != null) {
if (currentNode.getType() == TokenTypes.CLASS_DEF
|| currentNode.getType() == TokenTypes.ENUM_DEF
|| currentNode.getType() == TokenTypes.INTERFACE_DEF)
{
if (isPublic(currentNode)) {
mPublicTypeFound = true;
publicTypeFound = true;
}
else {
final String typeName = currentNode.
findFirstToken(TokenTypes.IDENT).getText();
mLineNumberTypeMap.put(currentNode.getLineNo(), typeName);
lineNumberTypeMap.put(currentNode.getLineNo(), typeName);
}
}
currentNode = currentNode.getNextSibling();
@ -120,32 +120,32 @@ public class OneTopLevelClassCheck extends Check
}
@Override
public void finishTree(DetailAST aRootAST)
public void finishTree(DetailAST rootAST)
{
if (!mPublicTypeFound && !mLineNumberTypeMap.isEmpty()) {
if (!publicTypeFound && !lineNumberTypeMap.isEmpty()) {
// skip first top-level type.
mLineNumberTypeMap.remove(mLineNumberTypeMap.firstKey());
lineNumberTypeMap.remove(lineNumberTypeMap.firstKey());
}
for (Map.Entry<Integer, String> entry
: mLineNumberTypeMap.entrySet())
: lineNumberTypeMap.entrySet())
{
log(entry.getKey(), "one.top.level.class", entry.getValue());
}
mLineNumberTypeMap.clear();
mPublicTypeFound = false;
lineNumberTypeMap.clear();
publicTypeFound = false;
}
/**
* Checks if a type is public.
* @param aTypeDef type definition node.
* @param typeDef type definition node.
* @return true if a type has a public access level modifier.
*/
private boolean isPublic(DetailAST aTypeDef)
private boolean isPublic(DetailAST typeDef)
{
final DetailAST modifiers =
aTypeDef.findFirstToken(TokenTypes.MODIFIERS);
typeDef.findFirstToken(TokenTypes.MODIFIERS);
return modifiers.findFirstToken(TokenTypes.LITERAL_PUBLIC) != null;
}
}

View File

@ -46,7 +46,7 @@ public final class ThrowsCountCheck extends Check
private static final int DEFAULT_MAX = 1;
/** maximum allowed throws statements */
private int mMax;
private int max;
/** Creates new instance of the check. */
public ThrowsCountCheck()
@ -74,40 +74,40 @@ public final class ThrowsCountCheck extends Check
*/
public int getMax()
{
return mMax;
return max;
}
/**
* Setter for max property.
* @param aMax maximum allowed throws statements.
* @param max maximum allowed throws statements.
*/
public void setMax(int aMax)
public void setMax(int max)
{
mMax = aMax;
this.max = max;
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
switch (aAST.getType()) {
switch (ast.getType()) {
case TokenTypes.LITERAL_THROWS:
visitLiteralThrows(aAST);
visitLiteralThrows(ast);
break;
default:
throw new IllegalStateException(aAST.toString());
throw new IllegalStateException(ast.toString());
}
}
/**
* Checks number of throws statements.
* @param aAST throws for check.
* @param ast throws for check.
*/
private void visitLiteralThrows(DetailAST aAST)
private void visitLiteralThrows(DetailAST ast)
{
// Account for all the commas!
final int count = (aAST.getChildCount() + 1) / 2;
final int count = (ast.getChildCount() + 1) / 2;
if (count > getMax()) {
log(aAST.getLineNo(), aAST.getColumnNo(), "throws.count",
log(ast.getLineNo(), ast.getColumnNo(), "throws.count",
count, getMax());
}
}

View File

@ -46,10 +46,10 @@ public class VisibilityModifierCheck
extends Check
{
/** whether protected members are allowed */
private boolean mProtectedAllowed;
private boolean protectedAllowed;
/** whether package visible members are allowed */
private boolean mPackageAllowed;
private boolean packageAllowed;
/**
* pattern for public members that should be ignored. Note:
@ -58,59 +58,59 @@ public class VisibilityModifierCheck
* With EJB 2.0 it is not longer necessary to have public access
* for persistent fields.
*/
private String mPublicMemberFormat = "^serialVersionUID$";
private String publicMemberFormat = "^serialVersionUID$";
/** regexp for public members that should be ignored */
private Pattern mPublicMemberPattern;
private Pattern publicMemberPattern;
/** Create an instance. */
public VisibilityModifierCheck()
{
setPublicMemberPattern(mPublicMemberFormat);
setPublicMemberPattern(publicMemberFormat);
}
/** @return whether protected members are allowed */
public boolean isProtectedAllowed()
{
return mProtectedAllowed;
return protectedAllowed;
}
/**
* Set whether protected members are allowed.
* @param aProtectedAllowed whether protected members are allowed
* @param protectedAllowed whether protected members are allowed
*/
public void setProtectedAllowed(boolean aProtectedAllowed)
public void setProtectedAllowed(boolean protectedAllowed)
{
mProtectedAllowed = aProtectedAllowed;
this.protectedAllowed = protectedAllowed;
}
/** @return whether package visible members are allowed */
public boolean isPackageAllowed()
{
return mPackageAllowed;
return packageAllowed;
}
/**
* Set whether package visible members are allowed.
* @param aPackageAllowed whether package visible members are allowed
* @param packageAllowed whether package visible members are allowed
*/
public void setPackageAllowed(boolean aPackageAllowed)
public void setPackageAllowed(boolean packageAllowed)
{
mPackageAllowed = aPackageAllowed;
this.packageAllowed = packageAllowed;
}
/**
* Set the pattern for public members to ignore.
* @param aPattern pattern for public members to ignore.
* @param pattern pattern for public members to ignore.
*/
public void setPublicMemberPattern(String aPattern)
public void setPublicMemberPattern(String pattern)
{
try {
mPublicMemberPattern = Utils.getPattern(aPattern);
mPublicMemberFormat = aPattern;
publicMemberPattern = Utils.getPattern(pattern);
publicMemberFormat = pattern;
}
catch (final PatternSyntaxException e) {
throw new ConversionException("unable to parse " + aPattern, e);
throw new ConversionException("unable to parse " + pattern, e);
}
}
@ -119,7 +119,7 @@ public class VisibilityModifierCheck
*/
private Pattern getPublicMemberRegexp()
{
return mPublicMemberPattern;
return publicMemberPattern;
}
@Override
@ -129,19 +129,19 @@ public class VisibilityModifierCheck
}
@Override
public void visitToken(DetailAST aAST)
public void visitToken(DetailAST ast)
{
if ((aAST.getType() != TokenTypes.VARIABLE_DEF)
|| (aAST.getParent().getType() != TokenTypes.OBJBLOCK))
if ((ast.getType() != TokenTypes.VARIABLE_DEF)
|| (ast.getParent().getType() != TokenTypes.OBJBLOCK))
{
return;
}
final DetailAST varNameAST = getVarNameAST(aAST);
final DetailAST varNameAST = getVarNameAST(ast);
final String varName = varNameAST.getText();
final boolean inInterfaceOrAnnotationBlock =
ScopeUtils.inInterfaceOrAnnotationBlock(aAST);
final Set<String> mods = getModifiers(aAST);
ScopeUtils.inInterfaceOrAnnotationBlock(ast);
final Set<String> mods = getModifiers(ast);
final String declaredScope = getVisibilityScope(mods);
final String variableScope =
inInterfaceOrAnnotationBlock ? "public" : declaredScope;
@ -161,12 +161,12 @@ public class VisibilityModifierCheck
/**
* Returns the variable name in a VARIABLE_DEF AST.
* @param aVariableDefAST an AST where type == VARIABLE_DEF AST.
* @return the variable name in aVariableDefAST
* @param variableDefAST an AST where type == VARIABLE_DEF AST.
* @return the variable name in variableDefAST
*/
private DetailAST getVarNameAST(DetailAST aVariableDefAST)
private DetailAST getVarNameAST(DetailAST variableDefAST)
{
DetailAST ast = aVariableDefAST.getFirstChild();
DetailAST ast = variableDefAST.getFirstChild();
while (ast != null) {
final DetailAST nextSibling = ast.getNextSibling();
if (ast.getType() == TokenTypes.TYPE) {
@ -179,12 +179,12 @@ public class VisibilityModifierCheck
/**
* Returns the set of modifier Strings for a VARIABLE_DEF AST.
* @param aVariableDefAST AST for a vraiable definition
* @param variableDefAST AST for a vraiable definition
* @return the set of modifier Strings for variableDefAST
*/
private Set<String> getModifiers(DetailAST aVariableDefAST)
private Set<String> getModifiers(DetailAST variableDefAST)
{
final AST modifiersAST = aVariableDefAST.getFirstChild();
final AST modifiersAST = variableDefAST.getFirstChild();
if (modifiersAST.getType() != TokenTypes.MODIFIERS) {
throw new IllegalStateException("Strange parse tree");
}
@ -200,14 +200,14 @@ public class VisibilityModifierCheck
/**
* Returns the visibility scope specified with a set of modifiers.
* @param aModifiers the set of modifier Strings
* @param modifiers the set of modifier Strings
* @return one of "public", "private", "protected", "package"
*/
private String getVisibilityScope(Set<String> aModifiers)
private String getVisibilityScope(Set<String> modifiers)
{
final String[] explicitModifiers = {"public", "private", "protected"};
for (final String candidate : explicitModifiers) {
if (aModifiers.contains(candidate)) {
if (modifiers.contains(candidate)) {
return candidate;
}
}