KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > j2ee > AbstractJ2eeCheck


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19
package com.puppycrawl.tools.checkstyle.checks.j2ee;
20
21 import com.puppycrawl.tools.checkstyle.api.Check;
22 import com.puppycrawl.tools.checkstyle.api.DetailAST;
23 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
24
25 /**
26  * Abstract class for J2ee component checking.
27  * @author Rick Giles
28  */

29 public abstract class AbstractJ2eeCheck
30     extends Check
31 {
32     /** checks method requirements */
33     private MethodChecker mMethodChecker;
34
35     /**
36      * Helper method to log a LocalizedMessage for an AST.
37      *
38      * @param aAST the AST for the message.
39      * @param aKey key to locale message format
40      * @param aArgs arguments for message
41      */

42     protected void log(DetailAST aAST, String JavaDoc aKey, Object JavaDoc[] aArgs)
43     {
44         final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
45         log(nameAST.getLineNo(), nameAST.getColumnNo(), aKey, aArgs);
46     }
47
48     /**
49      * Helper method to log a LocalizedMessage for an AST.
50      * Logs the name, line, and column of the AST.
51      *
52      * @param aAST the AST for the message.
53      * @param aKey key to locale message format
54      * @param aArgs arguments for message
55      */

56     protected void logName(DetailAST aAST, String JavaDoc aKey, Object JavaDoc[] aArgs)
57     {
58         final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
59         final String JavaDoc name = nameAST.getText();
60         final Object JavaDoc[] fullArgs = new Object JavaDoc[aArgs.length + 1];
61         System.arraycopy(aArgs, 0, fullArgs, 1, aArgs.length);
62         fullArgs[0] = name;
63         log(
64             nameAST.getLineNo(),
65             nameAST.getColumnNo(),
66             aKey,
67             fullArgs);
68     }
69
70     /**
71      * Gets the method checker for this component check.
72      * @return the method checker for this component check.
73      */

74     public MethodChecker getMethodChecker()
75     {
76         return mMethodChecker;
77     }
78
79     /**
80      * Sets the method checker for this component check.
81      * @param aMethodChecker the method checker for this component check.
82      */

83     public void setMethodChecker(MethodChecker aMethodChecker)
84     {
85         mMethodChecker = aMethodChecker;
86     }
87 }
88
Popular Tags