001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.checks; 020 021import com.puppycrawl.tools.checkstyle.api.Check; 022import com.puppycrawl.tools.checkstyle.api.DetailAST; 023import com.puppycrawl.tools.checkstyle.api.TokenTypes; 024 025/** 026 * <p>Checks that long constants are defined with an upper ell. 027 * That is <span class="code">'L'</span> and not 028 * <span class="code">'l'</span>. This is in accordance to the Java Language 029 * Specification, <a href= 030"http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282" 031 * >Section 3.10.1</a>. 032 * </p> 033 * <p> 034 * Rationale: The letter <span class="code">l</span> looks a lot 035 * like the number <span class="code">1</span>. 036 * </p> 037 * 038 * Examples 039 * <p class="body"> 040 * To configure the check: 041 * 042 * </p> 043 * <pre class="body"> 044 * <module name="UpperEll"/> 045 * </pre> 046 * 047 * @author Oliver Burn 048 * @version 1.0 049 */ 050public class UpperEllCheck extends Check 051{ 052 @Override 053 public int[] getDefaultTokens() 054 { 055 return new int[] {TokenTypes.NUM_LONG}; 056 } 057 058 @Override 059 public void visitToken(DetailAST ast) 060 { 061 if (ast.getText().endsWith("l")) { 062 log(ast.getLineNo(), 063 ast.getColumnNo() + ast.getText().length() - 1, 064 "upperEll"); 065 } 066 } 067}