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.Check;
12 import com.puppycrawl.tools.checkstyle.api.DetailAST;
13 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
15 public class LoggerFactoryClassParameterCheck extends Check {
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);
31 final String token = ast.findFirstToken(TokenTypes.ELIST).getFirstChild().getFirstChild()
32 .getFirstChild().getText();
33 if (!token.equals(className)) {
34 log(ast.getLineNo(), LOG_MESSAGE);
36 } catch (NullPointerException e) {
37 log(ast.getLineNo(), String.format("Invalid parameter in \"getLogger\" method call in class: %s",