2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.checkstyle;
11 import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
12 import com.puppycrawl.tools.checkstyle.api.DetailAST;
13 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
15 public class LoggerFactoryClassParameterCheck extends AbstractCheck {
17 private static final String LOG_MESSAGE = "LoggerFactory.getLogger Class argument is incorrect.";
18 private static final String METHOD_NAME = "LoggerFactory.getLogger";
21 public int[] getDefaultTokens() {
22 return new int[] { TokenTypes.METHOD_CALL };
26 public void visitToken(DetailAST ast) {
27 final String methodName = CheckLoggingUtil.getMethodName(ast);
28 if (methodName.equals(METHOD_NAME)) {
29 final String className = CheckLoggingUtil.getClassName(ast);
30 DetailAST findFirstToken = ast.findFirstToken(TokenTypes.ELIST);
31 if (findFirstToken == null) {
32 logError(ast, className);
35 DetailAST childToken = findFirstToken.getFirstChild();
36 if (childToken == null) {
37 logError(ast, className);
40 childToken = childToken.getFirstChild();
41 if (childToken == null) {
42 logError(ast, className);
45 childToken = childToken.getFirstChild();
46 if (childToken == null) {
47 logError(ast, className);
50 final String token = childToken.getText();
51 if (!token.equals(className)) {
52 log(ast.getLineNo(), LOG_MESSAGE);
57 protected void logError(DetailAST ast, String className) {
58 log(ast.getLineNo(), String.format("Invalid parameter in \"getLogger\" method call in class: %s", className));