Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UpperEllCheck |
|
| 1.5;1.5 |
1 | //////////////////////////////////////////////////////////////////////////////// | |
2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
3 | // Copyright (C) 2001-2014 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; | |
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 | * <p>Checks that long constants are defined with an upper ell. | |
27 | * That is <span class="code">'L'</span> and not | |
28 | * <span class="code">'l'</span>. This is in accordance to the Java Language | |
29 | * Specification, <a href= | |
30 | "http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282" | |
31 | * >Section 3.10.1</a>. | |
32 | * </p> | |
33 | * <p> | |
34 | * Rationale: The letter <span class="code">l</span> looks a lot | |
35 | * like the number <span class="code">1</span>. | |
36 | * </p> | |
37 | * <h4>Examples</h4> | |
38 | * <p class="body"> | |
39 | * To configure the check: | |
40 | * | |
41 | * </p> | |
42 | * <pre class="body"> | |
43 | * <module name="UpperEll"/> | |
44 | * </pre> | |
45 | * | |
46 | * @author Oliver Burn | |
47 | * @version 1.0 | |
48 | */ | |
49 | 1 | public class UpperEllCheck extends Check |
50 | { | |
51 | @Override | |
52 | public int[] getDefaultTokens() | |
53 | { | |
54 | 1 | return new int[] {TokenTypes.NUM_LONG}; |
55 | } | |
56 | ||
57 | @Override | |
58 | public void visitToken(DetailAST aAST) | |
59 | { | |
60 | 2 | if (aAST.getText().endsWith("l")) { |
61 | 1 | log(aAST.getLineNo(), |
62 | aAST.getColumnNo() + aAST.getText().length() - 1, | |
63 | "upperEll"); | |
64 | } | |
65 | 2 | } |
66 | } |