Bump odlparent to 3.0.0-SNAPSHOT and fix breakages
[yangtools.git] / common / checkstyle-logging / src / main / java / org / opendaylight / yangtools / checkstyle / LoggerVariableNameCheck.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.yangtools.checkstyle;
10
11 import static org.opendaylight.yangtools.checkstyle.CheckLoggingUtil.LOGGER_VAR_NAME;
12
13 import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
14 import com.puppycrawl.tools.checkstyle.api.DetailAST;
15 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
16
17 public class LoggerVariableNameCheck extends AbstractCheck {
18
19     private static final String LOG_MESSAGE = "Logger name should be LOG.";
20     private static final int[] TOKENS = { TokenTypes.VARIABLE_DEF };
21
22     @Override
23     public int[] getDefaultTokens() {
24         return TOKENS;
25     }
26
27     @Override
28     public int[] getAcceptableTokens() {
29         return TOKENS;
30     }
31
32     @Override
33     public int[] getRequiredTokens() {
34         return TOKENS;
35     }
36
37     @Override
38     public void visitToken(final DetailAST ast) {
39         if (CheckLoggingUtil.isAFieldVariable(ast) && CheckLoggingUtil.isLoggerType(ast)
40                 && !LOGGER_VAR_NAME.equals(CheckLoggingUtil.getVariableName(ast))) {
41             log(ast.getLineNo(), LOG_MESSAGE);
42         }
43     }
44 }