Added a new class TokenTypes that contains all the type constants. This class

breaks the circular dependencies - the cost is needing to maintain this class
when a new grammar is introduced.
This commit is contained in:
Oliver Burn 2002-10-19 06:28:06 +00:00
parent 3f14872d33
commit 84eddc3673
25 changed files with 522 additions and 175 deletions

View File

@ -21,14 +21,14 @@ package com.puppycrawl.tools.checkstyle;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessages;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Set;
/**
* Responsible for walking an abstract syntax tree and notifying interested
@ -41,11 +41,6 @@ class TreeWalker
{
// TODO: really need to optimise the performance of this class.
/** maps from a token name to value */
private static final Map TOKEN_NAME_TO_VALUE = new HashMap();
/** maps from a token value to name */
private static final Map TOKEN_VALUE_TO_NAME = new HashMap();
/** maps from token name to checks */
private final Map mTokenToChecks = new HashMap();
/** all the registered checks */
@ -55,30 +50,6 @@ class TreeWalker
/** the tab width for error reporting */
private final int mTabWidth;
// initialise the constants
static {
final Field[] fields = Java14TokenTypes.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
final Field f = fields[i];
final String name = f.getName();
try {
// this should NEVER fail (famous last words)
final Integer value = new Integer(f.getInt(name));
TOKEN_NAME_TO_VALUE.put(name, value);
TOKEN_VALUE_TO_NAME.put(value, name);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
System.exit(1);
}
catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
}
}
}
/**
* Creates a new <code>TreeWalker</code> instance.
*
@ -91,20 +62,6 @@ class TreeWalker
mTabWidth = aTabWidth;
}
/**
* Returns the name of a token for a given ID.
* @param aID the ID of the token name to get
* @return a token name
*/
static String getTokenName(int aID)
{
final String name = (String) TOKEN_VALUE_TO_NAME.get(new Integer(aID));
if (name == null) {
throw new IllegalArgumentException("given id " + aID);
}
return name;
}
/**
* Register a check for a given configuration.
* @param aCheck the check to register
@ -136,7 +93,7 @@ class TreeWalker
*/
private void registerCheck(int aTokenID, Check aCheck)
{
registerCheck(getTokenName(aTokenID), aCheck);
registerCheck(TokenTypes.getTokenName(aTokenID), aCheck);
}
/**
@ -236,7 +193,8 @@ class TreeWalker
private void notifyVisit(DetailAST aAST)
{
final ArrayList visitors =
(ArrayList) mTokenToChecks.get(getTokenName(aAST.getType()));
(ArrayList) mTokenToChecks.get(TokenTypes.getTokenName(
aAST.getType()));
if (visitors != null) {
final Map ctx = new HashMap();
for (int i = 0; i < visitors.size(); i++) {
@ -254,7 +212,8 @@ class TreeWalker
private void notifyLeave(DetailAST aAST)
{
final ArrayList visitors =
(ArrayList) mTokenToChecks.get(getTokenName(aAST.getType()));
(ArrayList) mTokenToChecks.get(TokenTypes.getTokenName(
aAST.getType()));
if (visitors != null) {
for (int i = 0; i < visitors.size(); i++) {
final Check check = (Check) visitors.get(i);

View File

@ -0,0 +1,391 @@
////////////////////////////////////////////////////////////////////////////////
// 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.api;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Field;
/**
* Contains the constants for all the tokens contained in the Abstract Syntax
* Tree.
*
* Implementation detail: This class has been introduced to break the circular
* dependency being the packages.
*
* @author <a href="mailto:checkstyle@puppycrawl.com">Oliver Burn</a>
* @version 1.0
*/
public class TokenTypes
{
/** token representing a EOF */
public static final int EOF = 1;
/** token representing a NULL_TREE_LOOKAHEAD */
public static final int NULL_TREE_LOOKAHEAD = 3;
/** token representing a BLOCK */
public static final int BLOCK = 4;
/** token representing a MODIFIERS */
public static final int MODIFIERS = 5;
/** token representing a OBJBLOCK */
public static final int OBJBLOCK = 6;
/** token representing a SLIST */
public static final int SLIST = 7;
/** token representing a CTOR_DEF */
public static final int CTOR_DEF = 8;
/** token representing a METHOD_DEF */
public static final int METHOD_DEF = 9;
/** token representing a VARIABLE_DEF */
public static final int VARIABLE_DEF = 10;
/** token representing a INSTANCE_INIT */
public static final int INSTANCE_INIT = 11;
/** token representing a STATIC_INIT */
public static final int STATIC_INIT = 12;
/** token representing a TYPE */
public static final int TYPE = 13;
/** token representing a CLASS_DEF */
public static final int CLASS_DEF = 14;
/** token representing a INTERFACE_DEF */
public static final int INTERFACE_DEF = 15;
/** token representing a PACKAGE_DEF */
public static final int PACKAGE_DEF = 16;
/** token representing a ARRAY_DECLARATOR */
public static final int ARRAY_DECLARATOR = 17;
/** token representing a EXTENDS_CLAUSE */
public static final int EXTENDS_CLAUSE = 18;
/** token representing a IMPLEMENTS_CLAUSE */
public static final int IMPLEMENTS_CLAUSE = 19;
/** token representing a PARAMETERS */
public static final int PARAMETERS = 20;
/** token representing a PARAMETER_DEF */
public static final int PARAMETER_DEF = 21;
/** token representing a LABELED_STAT */
public static final int LABELED_STAT = 22;
/** token representing a TYPECAST */
public static final int TYPECAST = 23;
/** token representing a INDEX_OP */
public static final int INDEX_OP = 24;
/** token representing a POST_INC */
public static final int POST_INC = 25;
/** token representing a POST_DEC */
public static final int POST_DEC = 26;
/** token representing a METHOD_CALL */
public static final int METHOD_CALL = 27;
/** token representing a EXPR */
public static final int EXPR = 28;
/** token representing a ARRAY_INIT */
public static final int ARRAY_INIT = 29;
/** token representing a IMPORT */
public static final int IMPORT = 30;
/** token representing a UNARY_MINUS */
public static final int UNARY_MINUS = 31;
/** token representing a UNARY_PLUS */
public static final int UNARY_PLUS = 32;
/** token representing a CASE_GROUP */
public static final int CASE_GROUP = 33;
/** token representing a ELIST */
public static final int ELIST = 34;
/** token representing a FOR_INIT */
public static final int FOR_INIT = 35;
/** token representing a FOR_CONDITION */
public static final int FOR_CONDITION = 36;
/** token representing a FOR_ITERATOR */
public static final int FOR_ITERATOR = 37;
/** token representing a EMPTY_STAT */
public static final int EMPTY_STAT = 38;
/** token representing a FINAL */
public static final int FINAL = 39;
/** token representing a ABSTRACT */
public static final int ABSTRACT = 40;
/** token representing a STRICTFP */
public static final int STRICTFP = 41;
/** token representing a SUPER_CTOR_CALL */
public static final int SUPER_CTOR_CALL = 42;
/** token representing a CTOR_CALL */
public static final int CTOR_CALL = 43;
/** token representing a LITERAL_package */
public static final int LITERAL_PACKAGE = 44;
/** token representing a SEMI */
public static final int SEMI = 45;
/** token representing a LITERAL_import */
public static final int LITERAL_IMPORT = 46;
/** token representing a LBRACK */
public static final int LBRACK = 47;
/** token representing a RBRACK */
public static final int RBRACK = 48;
/** token representing a LITERAL_void */
public static final int LITERAL_VOID = 49;
/** token representing a LITERAL_boolean */
public static final int LITERAL_BOOLEAN = 50;
/** token representing a LITERAL_byte */
public static final int LITERAL_BYTE = 51;
/** token representing a LITERAL_char */
public static final int LITERAL_CHAR = 52;
/** token representing a LITERAL_short */
public static final int LITERAL_SHORT = 53;
/** token representing a LITERAL_int */
public static final int LITERAL_INT = 54;
/** token representing a LITERAL_float */
public static final int LITERAL_FLOAT = 55;
/** token representing a LITERAL_long */
public static final int LITERAL_LONG = 56;
/** token representing a LITERAL_double */
public static final int LITERAL_DOUBLE = 57;
/** token representing a IDENT */
public static final int IDENT = 58;
/** token representing a DOT */
public static final int DOT = 59;
/** token representing a STAR */
public static final int STAR = 60;
/** token representing a LITERAL_private */
public static final int LITERAL_PRIVATE = 61;
/** token representing a LITERAL_public */
public static final int LITERAL_PUBLIC = 62;
/** token representing a LITERAL_protected */
public static final int LITERAL_PROTECTED = 63;
/** token representing a LITERAL_static */
public static final int LITERAL_STATIC = 64;
/** token representing a LITERAL_transient */
public static final int LITERAL_TRANSIENT = 65;
/** token representing a LITERAL_native */
public static final int LITERAL_NATIVE = 66;
/** token representing a LITERAL_threadsafe */
public static final int LITERAL_THREADSAFE = 67;
/** token representing a LITERAL_synchronized */
public static final int LITERAL_SYNCHRONIZED = 68;
/** token representing a LITERAL_volatile */
public static final int LITERAL_VOLATILE = 69;
/** token representing a LITERAL_class */
public static final int LITERAL_CLASS = 70;
/** token representing a LITERAL_extends */
public static final int LITERAL_EXTENDS = 71;
/** token representing a LITERAL_interface */
public static final int LITERAL_INTERFACE = 72;
/** token representing a LCURLY */
public static final int LCURLY = 73;
/** token representing a RCURLY */
public static final int RCURLY = 74;
/** token representing a COMMA */
public static final int COMMA = 75;
/** token representing a LITERAL_implements */
public static final int LITERAL_IMPLEMENTS = 76;
/** token representing a LPAREN */
public static final int LPAREN = 77;
/** token representing a RPAREN */
public static final int RPAREN = 78;
/** token representing a LITERAL_this */
public static final int LITERAL_THIS = 79;
/** token representing a LITERAL_super */
public static final int LITERAL_SUPER = 80;
/** token representing a ASSIGN */
public static final int ASSIGN = 81;
/** token representing a LITERAL_throws */
public static final int LITERAL_THROWS = 82;
/** token representing a COLON */
public static final int COLON = 83;
/** token representing a LITERAL_if */
public static final int LITERAL_IF = 84;
/** token representing a LITERAL_for */
public static final int LITERAL_FOR = 85;
/** token representing a LITERAL_while */
public static final int LITERAL_WHILE = 86;
/** token representing a LITERAL_do */
public static final int LITERAL_DO = 87;
/** token representing a LITERAL_break */
public static final int LITERAL_BREAK = 88;
/** token representing a LITERAL_continue */
public static final int LITERAL_CONTINUE = 89;
/** token representing a LITERAL_return */
public static final int LITERAL_RETURN = 90;
/** token representing a LITERAL_switch */
public static final int LITERAL_SWITCH = 91;
/** token representing a LITERAL_throw */
public static final int LITERAL_THROW = 92;
/** token representing a LITERAL_else */
public static final int LITERAL_ELSE = 93;
/** token representing a LITERAL_case */
public static final int LITERAL_CASE = 94;
/** token representing a LITERAL_default */
public static final int LITERAL_DEFAULT = 95;
/** token representing a LITERAL_try */
public static final int LITERAL_TRY = 96;
/** token representing a LITERAL_catch */
public static final int LITERAL_CATCH = 97;
/** token representing a LITERAL_finally */
public static final int LITERAL_FINALLY = 98;
/** token representing a PLUS_ASSIGN */
public static final int PLUS_ASSIGN = 99;
/** token representing a MINUS_ASSIGN */
public static final int MINUS_ASSIGN = 100;
/** token representing a STAR_ASSIGN */
public static final int STAR_ASSIGN = 101;
/** token representing a DIV_ASSIGN */
public static final int DIV_ASSIGN = 102;
/** token representing a MOD_ASSIGN */
public static final int MOD_ASSIGN = 103;
/** token representing a SR_ASSIGN */
public static final int SR_ASSIGN = 104;
/** token representing a BSR_ASSIGN */
public static final int BSR_ASSIGN = 105;
/** token representing a SL_ASSIGN */
public static final int SL_ASSIGN = 106;
/** token representing a BAND_ASSIGN */
public static final int BAND_ASSIGN = 107;
/** token representing a BXOR_ASSIGN */
public static final int BXOR_ASSIGN = 108;
/** token representing a BOR_ASSIGN */
public static final int BOR_ASSIGN = 109;
/** token representing a QUESTION */
public static final int QUESTION = 110;
/** token representing a LOR */
public static final int LOR = 111;
/** token representing a LAND */
public static final int LAND = 112;
/** token representing a BOR */
public static final int BOR = 113;
/** token representing a BXOR */
public static final int BXOR = 114;
/** token representing a BAND */
public static final int BAND = 115;
/** token representing a NOT_EQUAL */
public static final int NOT_EQUAL = 116;
/** token representing a EQUAL */
public static final int EQUAL = 117;
/** token representing a LT */
public static final int LT = 118;
/** token representing a GT */
public static final int GT = 119;
/** token representing a LE */
public static final int LE = 120;
/** token representing a GE */
public static final int GE = 121;
/** token representing a LITERAL_instanceof */
public static final int LITERAL_INSTANCEOF = 122;
/** token representing a SL */
public static final int SL = 123;
/** token representing a SR */
public static final int SR = 124;
/** token representing a BSR */
public static final int BSR = 125;
/** token representing a PLUS */
public static final int PLUS = 126;
/** token representing a MINUS */
public static final int MINUS = 127;
/** token representing a DIV */
public static final int DIV = 128;
/** token representing a MOD */
public static final int MOD = 129;
/** token representing a INC */
public static final int INC = 130;
/** token representing a DEC */
public static final int DEC = 131;
/** token representing a BNOT */
public static final int BNOT = 132;
/** token representing a LNOT */
public static final int LNOT = 133;
/** token representing a LITERAL_true */
public static final int LITERAL_TRUE = 134;
/** token representing a LITERAL_false */
public static final int LITERAL_FALSE = 135;
/** token representing a LITERAL_null */
public static final int LITERAL_NULL = 136;
/** token representing a LITERAL_new */
public static final int LITERAL_NEW = 137;
/** token representing a NUM_INT */
public static final int NUM_INT = 138;
/** token representing a CHAR_LITERAL */
public static final int CHAR_LITERAL = 139;
/** token representing a STRING_LITERAL */
public static final int STRING_LITERAL = 140;
/** token representing a NUM_FLOAT */
public static final int NUM_FLOAT = 141;
/** token representing a NUM_LONG */
public static final int NUM_LONG = 142;
/** token representing a NUM_DOUBLE */
public static final int NUM_DOUBLE = 143;
/** token representing a WS */
public static final int WS = 144;
/** token representing a SL_COMMENT */
public static final int SL_COMMENT = 145;
/** token representing a ML_COMMENT */
public static final int ML_COMMENT = 146;
/** token representing a ESC */
public static final int ESC = 147;
/** token representing a HEX_DIGIT */
public static final int HEX_DIGIT = 148;
/** token representing a VOCAB */
public static final int VOCAB = 149;
/** token representing a EXPONENT */
public static final int EXPONENT = 150;
/** token representing a FLOAT_SUFFIX */
public static final int FLOAT_SUFFIX = 151;
/** token representing a ASSERT */
public static final int ASSERT = 152;
////////////////////////////////////////////////////////////////////////
// The interesting code goes here
////////////////////////////////////////////////////////////////////////
/** maps from a token name to value */
private static final Map TOKEN_NAME_TO_VALUE = new HashMap();
/** maps from a token value to name */
private static final Map TOKEN_VALUE_TO_NAME = new HashMap();
// initialise the constants
static {
final Field[] fields = TokenTypes.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
final Field f = fields[i];
// Only process the int declarations.
if (f.getType() != Integer.TYPE) {
continue;
}
final String name = f.getName();
try {
// this should NEVER fail (famous last words)
final Integer value = new Integer(f.getInt(name));
TOKEN_NAME_TO_VALUE.put(name, value);
TOKEN_VALUE_TO_NAME.put(value, name);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
System.exit(1);
}
catch (IllegalAccessException e) {
e.printStackTrace();
System.exit(1);
}
}
}
/**
* Returns the name of a token for a given ID.
* @param aID the ID of the token name to get
* @return a token name
*/
public static String getTokenName(int aID)
{
final String name = (String) TOKEN_VALUE_TO_NAME.get(new Integer(aID));
if (name == null) {
throw new IllegalArgumentException("given id " + aID);
}
return name;
}
}

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
@ -39,7 +39,7 @@ public class AvoidStarImport
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT};
return new int[] {TokenTypes.IMPORT};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -24,7 +24,7 @@ import java.util.HashSet;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Check that reports empty if/try/catch/finally blocks.
@ -52,14 +52,14 @@ public class EmptyBlockCheck extends Check
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.SLIST};
return new int[] {TokenTypes.SLIST};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
// defend against users that change the token set in the config file.
if (aAST.getType() != JavaTokenTypes.SLIST) {
if (aAST.getType() != TokenTypes.SLIST) {
return;
}

View File

@ -19,9 +19,9 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import java.util.Set;
import java.util.TreeSet;
@ -64,7 +64,7 @@ public class IllegalImportCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT};
return new int[] {TokenTypes.IMPORT};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -24,7 +24,7 @@ import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
@ -67,9 +67,9 @@ public class IllegalInstantiationCheck
public int[] getDefaultTokens()
{
return new int[] {
JavaTokenTypes.IMPORT,
JavaTokenTypes.LITERAL_new,
JavaTokenTypes.PACKAGE_DEF
TokenTypes.IMPORT,
TokenTypes.LITERAL_NEW,
TokenTypes.PACKAGE_DEF
};
}
@ -85,13 +85,13 @@ public class IllegalInstantiationCheck
public void visitToken(DetailAST aAST)
{
switch (aAST.getType()) {
case JavaTokenTypes.LITERAL_new:
case TokenTypes.LITERAL_NEW:
processLiteralNew(aAST);
break;
case JavaTokenTypes.PACKAGE_DEF:
case TokenTypes.PACKAGE_DEF:
processPackageDef(aAST);
break;
case JavaTokenTypes.IMPORT:
case TokenTypes.IMPORT:
processImport(aAST);
break;
}

View File

@ -23,7 +23,6 @@ import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.api.Utils;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
/**
* Abstract base class that provides functionality that is used in import

View File

@ -18,7 +18,7 @@
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -35,8 +35,8 @@ public class MethodLeftCurlyCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.CTOR_DEF,
JavaTokenTypes.METHOD_DEF};
return new int[] {TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
@ -45,7 +45,7 @@ public class MethodLeftCurlyCheck
final DetailAST brace = Utils.getLastSibling(aAST.getFirstChild());
// TODO: should check for modifiers
final DetailAST startToken;
if (aAST.getType() == JavaTokenTypes.CTOR_DEF) {
if (aAST.getType() == TokenTypes.CTOR_DEF) {
startToken = (DetailAST) aAST.getFirstChild().getNextSibling();
}
else {

View File

@ -2,7 +2,7 @@ package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks for long methods.
@ -23,13 +23,13 @@ public class MethodLengthCheck extends Check
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.METHOD_DEF};
return new int[] {TokenTypes.METHOD_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() != JavaTokenTypes.METHOD_DEF) {
if (aAST.getType() != TokenTypes.METHOD_DEF) {
return;
}

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that method names conform to a specified format.
@ -39,7 +39,7 @@ public class MethodNameCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.METHOD_DEF};
return new int[] {TokenTypes.METHOD_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -26,7 +26,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
/**
@ -56,7 +56,7 @@ public class ModifierCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.MODIFIERS};
return new int[] {TokenTypes.MODIFIERS};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -37,18 +37,18 @@ public class OtherLeftCurlyCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.LITERAL_while,
JavaTokenTypes.LITERAL_try,
JavaTokenTypes.LITERAL_catch,
JavaTokenTypes.LITERAL_finally,
JavaTokenTypes.LITERAL_synchronized,
JavaTokenTypes.LITERAL_switch,
JavaTokenTypes.LITERAL_do,
JavaTokenTypes.LITERAL_if,
JavaTokenTypes.LITERAL_else,
JavaTokenTypes.LITERAL_for,
return new int[] {TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_FOR,
// TODO: need to handle....
//JavaTokenTypes.STATIC_INIT,
//TokenTypes.STATIC_INIT,
};
}
@ -59,20 +59,20 @@ public class OtherLeftCurlyCheck
final DetailAST brace;
switch (aAST.getType()) {
case JavaTokenTypes.LITERAL_while:
case JavaTokenTypes.LITERAL_catch:
case JavaTokenTypes.LITERAL_synchronized:
case JavaTokenTypes.LITERAL_for:
case TokenTypes.LITERAL_WHILE:
case TokenTypes.LITERAL_CATCH:
case TokenTypes.LITERAL_SYNCHRONIZED:
case TokenTypes.LITERAL_FOR:
brace = Utils.getLastSibling(aAST.getFirstChild());
break;
case JavaTokenTypes.LITERAL_try:
case JavaTokenTypes.LITERAL_finally:
case JavaTokenTypes.LITERAL_do:
case TokenTypes.LITERAL_TRY:
case TokenTypes.LITERAL_FINALLY:
case TokenTypes.LITERAL_DO:
brace = (DetailAST) aAST.getFirstChild();
break;
case JavaTokenTypes.LITERAL_else:
case TokenTypes.LITERAL_ELSE:
final DetailAST candidate = (DetailAST) aAST.getFirstChild();
if (candidate.getType() == JavaTokenTypes.SLIST) {
if (candidate.getType() == TokenTypes.SLIST) {
brace = candidate;
}
else {
@ -80,8 +80,8 @@ public class OtherLeftCurlyCheck
brace = null;
}
break;
case JavaTokenTypes.LITERAL_switch:
case JavaTokenTypes.LITERAL_if:
case TokenTypes.LITERAL_SWITCH:
case TokenTypes.LITERAL_IF:
brace = (DetailAST) aAST.getFirstChild().getNextSibling()
.getNextSibling().getNextSibling();
break;

View File

@ -20,7 +20,7 @@ package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks the naming of packages.
@ -45,7 +45,7 @@ public class PackageNameCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.PACKAGE_DEF};
return new int[] {TokenTypes.PACKAGE_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that the header of the source file is correct.
@ -45,7 +45,7 @@ public class ParameterFormatCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.PARAMETER_DEF};
return new int[] {TokenTypes.PARAMETER_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -48,7 +48,7 @@ public class ParameterNumberCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.METHOD_DEF, JavaTokenTypes.CTOR_DEF};
return new int[] {TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
@ -56,12 +56,12 @@ public class ParameterNumberCheck
{
final DetailAST params =
Utils.findFirstToken(aAST.getFirstChild(),
JavaTokenTypes.PARAMETERS);
TokenTypes.PARAMETERS);
final int count = Utils.countTokens(params.getFirstChild(),
JavaTokenTypes.PARAMETER_DEF);
TokenTypes.PARAMETER_DEF);
if (count > mMax) {
final DetailAST name = Utils.findFirstToken(aAST.getFirstChild(),
JavaTokenTypes.IDENT);
TokenTypes.IDENT);
log(name.getLineNo(), name.getColumnNo(),
"maxParam", new Integer(mMax));
}

View File

@ -19,9 +19,9 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Utils;
import org.apache.commons.beanutils.ConversionException;
@ -40,19 +40,19 @@ public class ParenPadCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.RPAREN,
JavaTokenTypes.LPAREN,
JavaTokenTypes.CTOR_CALL,
JavaTokenTypes.SUPER_CTOR_CALL,
JavaTokenTypes.TYPECAST, // TODO: treat this?
JavaTokenTypes.METHOD_CALL,
return new int[] {TokenTypes.RPAREN,
TokenTypes.LPAREN,
TokenTypes.CTOR_CALL,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.TYPECAST, // TODO: treat this?
TokenTypes.METHOD_CALL,
};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() == JavaTokenTypes.RPAREN) {
if (aAST.getType() == TokenTypes.RPAREN) {
processRight(aAST);
}
else {

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
@ -51,13 +51,13 @@ public class RedundantImportCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT, JavaTokenTypes.PACKAGE_DEF};
return new int[] {TokenTypes.IMPORT, TokenTypes.PACKAGE_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() == JavaTokenTypes.PACKAGE_DEF) {
if (aAST.getType() == TokenTypes.PACKAGE_DEF) {
final DetailAST nameAST = (DetailAST) aAST.getFirstChild();
mPkgName = FullIdent.createFullIdent(nameAST).getText();
}

View File

@ -22,11 +22,10 @@ import java.util.Stack;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
// TODO: need to create a class to represent the constants in JavaTokenTypes.
// Needed to break circular dependencies
public class RedundantModifierCheck extends Check implements JavaTokenTypes
public class RedundantModifierCheck
extends Check
{
/** tracks if in an interface */
private final Stack mInInterface = new Stack();
@ -41,20 +40,22 @@ public class RedundantModifierCheck extends Check implements JavaTokenTypes
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {MODIFIERS, INTERFACE_DEF, CLASS_DEF};
return new int[] {TokenTypes.MODIFIERS,
TokenTypes.INTERFACE_DEF,
TokenTypes.CLASS_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
switch (aAST.getType()) {
case INTERFACE_DEF:
case TokenTypes.INTERFACE_DEF:
mInInterface.push(Boolean.TRUE);
break;
case CLASS_DEF:
case TokenTypes.CLASS_DEF:
mInInterface.push(Boolean.FALSE);
break;
case MODIFIERS:
case TokenTypes.MODIFIERS:
// modifiers of the interface itself (public interface X)
// will be below the INTERFACE_DEF node. Example:
@ -96,7 +97,7 @@ public class RedundantModifierCheck extends Check implements JavaTokenTypes
if (mInInterface.empty()) {
return false;
}
if (aAST.getParent().getType() == INTERFACE_DEF) {
if (aAST.getParent().getType() == TokenTypes.INTERFACE_DEF) {
int size = mInInterface.size();
return size > 1 && Boolean.TRUE.equals(mInInterface.get(size - 2));
}

View File

@ -18,7 +18,7 @@
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -39,9 +39,9 @@ public class RightCurlyCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.LITERAL_try,
JavaTokenTypes.LITERAL_catch,
JavaTokenTypes.LITERAL_else};
return new int[] {TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_ELSE};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
@ -50,18 +50,18 @@ public class RightCurlyCheck
// Attempt to locate the tokens to do the check
DetailAST rcurly = null;
DetailAST nextToken = null;
if (aAST.getType() == JavaTokenTypes.LITERAL_else) {
if (aAST.getType() == TokenTypes.LITERAL_ELSE) {
nextToken = aAST;
rcurly = Utils.getLastSibling(
aAST.getParent().getFirstChild().getNextSibling()
.getNextSibling().getNextSibling().getFirstChild());
}
else if (aAST.getType() == JavaTokenTypes.LITERAL_catch) {
else if (aAST.getType() == TokenTypes.LITERAL_CATCH) {
nextToken = (DetailAST) aAST.getNextSibling();
rcurly = Utils.getLastSibling(
Utils.getLastSibling(aAST.getFirstChild()).getFirstChild());
}
else if (aAST.getType() == JavaTokenTypes.LITERAL_try) {
else if (aAST.getType() == TokenTypes.LITERAL_TRY) {
nextToken = (DetailAST) aAST.getFirstChild().getNextSibling();
rcurly = Utils.getLastSibling(aAST.getFirstChild().getFirstChild());
}

View File

@ -21,7 +21,7 @@ package com.puppycrawl.tools.checkstyle.checks;
import antlr.collections.AST;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
@ -32,19 +32,20 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
*
* @author Lars Kühne
*/
public class SimplifyBooleanReturnCheck extends Check
public class SimplifyBooleanReturnCheck
extends Check
{
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.LITERAL_if};
return new int[] {TokenTypes.LITERAL_IF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
// paranoia - what an untrusting sole :-)
if (aAST.getType() != JavaTokenTypes.LITERAL_if) {
if (aAST.getType() != TokenTypes.LITERAL_IF) {
throw new IllegalArgumentException("not an if");
}
@ -108,7 +109,7 @@ public class SimplifyBooleanReturnCheck extends Check
*/
private boolean isBooleanLiteralReturnStatement(AST aAST)
{
if (aAST.getType() != JavaTokenTypes.LITERAL_return) {
if (aAST.getType() != TokenTypes.LITERAL_RETURN) {
return false;
}
@ -116,7 +117,7 @@ public class SimplifyBooleanReturnCheck extends Check
final AST value = expr.getFirstChild();
final int valueType = value.getType();
return ((valueType == JavaTokenTypes.LITERAL_true)
|| (valueType == JavaTokenTypes.LITERAL_false));
return ((valueType == TokenTypes.LITERAL_TRUE)
|| (valueType == TokenTypes.LITERAL_FALSE));
}
}

View File

@ -16,10 +16,9 @@
// 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.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -36,8 +35,8 @@ public class TypeLeftCurlyCheck
/** @see Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.INTERFACE_DEF,
JavaTokenTypes.CLASS_DEF};
return new int[] {TokenTypes.INTERFACE_DEF,
TokenTypes.CLASS_DEF};
}
/** @see Check */

View File

@ -19,7 +19,7 @@
package com.puppycrawl.tools.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that the header of the source file is correct.
@ -46,8 +46,8 @@ public class TypeNameCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.CLASS_DEF,
JavaTokenTypes.INTERFACE_DEF};
return new int[] {TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -16,10 +16,9 @@
// 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.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.FullIdent;
@ -72,25 +71,25 @@ public class UnusedImportsCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.IMPORT,
JavaTokenTypes.CLASS_DEF,
JavaTokenTypes.INTERFACE_DEF,
JavaTokenTypes.IDENT};
return new int[] {TokenTypes.IMPORT,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.IDENT};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() == JavaTokenTypes.IDENT) {
if (aAST.getType() == TokenTypes.IDENT) {
if (mCollect) {
processIdent(aAST);
}
}
else if (aAST.getType() == JavaTokenTypes.IMPORT) {
else if (aAST.getType() == TokenTypes.IMPORT) {
processImport(aAST);
}
else if ((aAST.getType() == JavaTokenTypes.CLASS_DEF)
|| (aAST.getType() == JavaTokenTypes.INTERFACE_DEF))
else if ((aAST.getType() == TokenTypes.CLASS_DEF)
|| (aAST.getType() == TokenTypes.INTERFACE_DEF))
{
mCollect = true;
}
@ -105,7 +104,7 @@ public class UnusedImportsCheck
// TODO: should be a lot smarter in selection. Currently use
// same algorithm as real checkstyle
final DetailAST parent = aAST.getParent();
if (parent.getType() == JavaTokenTypes.DOT) {
if (parent.getType() == TokenTypes.DOT) {
if (aAST.getNextSibling() != null) {
mReferenced.add(aAST.getText());
}

View File

@ -16,10 +16,9 @@
// 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.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Check;
@ -38,7 +37,7 @@ public class UpperEllCheck
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.NUM_LONG};
return new int[] {TokenTypes.NUM_LONG};
}
/** @see com.puppycrawl.tools.checkstyle.api.Check */

View File

@ -16,13 +16,12 @@
// 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 java.util.HashSet;
import java.util.Set;
import com.puppycrawl.tools.checkstyle.JavaTokenTypes;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.Utils;
@ -122,14 +121,14 @@ public class VisibilityModifierCheck
/** @see Check */
public int[] getDefaultTokens()
{
return new int[] {JavaTokenTypes.VARIABLE_DEF};
return new int[] {TokenTypes.VARIABLE_DEF};
}
/** @see Check */
public void visitToken(DetailAST aAST)
{
if (aAST.getType() != JavaTokenTypes.VARIABLE_DEF
|| aAST.getParent().getType() != JavaTokenTypes.OBJBLOCK)
if (aAST.getType() != TokenTypes.VARIABLE_DEF
|| aAST.getParent().getType() != TokenTypes.OBJBLOCK)
{
return;
}
@ -165,7 +164,7 @@ public class VisibilityModifierCheck
AST ast = aVariableDefAST.getFirstChild();
while (ast != null) {
AST nextSibling = ast.getNextSibling();
if (ast.getType() == JavaTokenTypes.TYPE) {
if (ast.getType() == TokenTypes.TYPE) {
return (DetailAST) nextSibling;
}
ast = nextSibling;
@ -183,9 +182,9 @@ public class VisibilityModifierCheck
DetailAST ast = aAST.getParent();
while (ast != null) {
switch (ast.getType()) {
case JavaTokenTypes.INTERFACE_DEF:
case TokenTypes.INTERFACE_DEF:
return true;
case JavaTokenTypes.CLASS_DEF:
case TokenTypes.CLASS_DEF:
return false;
default:
ast = ast.getParent();
@ -201,11 +200,11 @@ public class VisibilityModifierCheck
*/
private Set getModifiers(DetailAST variableDefAST)
{
AST modifiersAST = variableDefAST.getFirstChild();
if (modifiersAST.getType() != JavaTokenTypes.MODIFIERS) {
final AST modifiersAST = variableDefAST.getFirstChild();
if (modifiersAST.getType() != TokenTypes.MODIFIERS) {
throw new IllegalStateException("Strange parse tree");
}
Set retVal = new HashSet();
final Set retVal = new HashSet();
AST modifier = modifiersAST.getFirstChild();
while (modifier != null) {
retVal.add(modifier.getText());