KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > whitespace > TabCharacterCheck


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

20 package com.puppycrawl.tools.checkstyle.checks.whitespace;
21
22 import com.puppycrawl.tools.checkstyle.api.Check;
23 import com.puppycrawl.tools.checkstyle.api.DetailAST;
24
25 /**
26  * <p>
27  * Reports tab characters ('\t') in the source code.
28  * </p>
29  *
30  * <p>
31  * Rationale:
32  * <ul>
33  * <li>Developers should not need to configure the tab width of their
34  * text editors in order to be able to read source code.</li>
35  * <li>From the Apache jakarta coding standards:
36  * In a distributed development environment, when the
37  * cvs commit messages get sent to a mailing list, they are almost
38  * impossible to read if you use tabs.</li>
39  * </ul>
40  * </p>
41  * <p>
42  * An example of how to configure the check is:
43  * </p>
44  * <pre>
45  * &lt;module name="TabCharacter"/&gt;
46  * </pre>
47  * @author Lars Kühne
48  */

49 public class TabCharacterCheck
50         extends Check
51 {
52     /** {@inheritDoc} */
53     public int[] getDefaultTokens()
54     {
55         return new int[0];
56     }
57
58     /** {@inheritDoc} */
59     public void beginTree(DetailAST aRootAST)
60     {
61         final String JavaDoc[] lines = getLines();
62         for (int i = 0; i < lines.length; i++) {
63             final int tabPosition = lines[i].indexOf('\t');
64             if (tabPosition != -1) {
65                 log(i + 1, tabPosition, "containsTab");
66             }
67         }
68     }
69 }
70
Popular Tags