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 static org.opendaylight.yangtools.checkstyle.CheckLoggingUtil.isAFieldVariable;
13 import com.puppycrawl.tools.checkstyle.api.Check;
14 import com.puppycrawl.tools.checkstyle.api.DetailAST;
15 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
17 public class LoggerDeclarationsCountCheck extends Check {
19 private static final String LOG_MESSAGE = "Logger might be declared only once.";
20 private String prevClassName = "";
23 public int[] getDefaultTokens() {
24 return new int[]{TokenTypes.VARIABLE_DEF};
28 public void visitToken(DetailAST ast) {
29 if (CheckLoggingUtil.isLoggerType(ast) && isAFieldVariable(ast)) {
30 final String className = CheckLoggingUtil.getClassName(ast);
31 if (this.prevClassName.equals(className)) {
32 log(ast.getLineNo(), LOG_MESSAGE);
34 this.prevClassName = className;
39 public void finishTree(DetailAST rootAST) {
40 super.finishTree(rootAST);
41 this.prevClassName = "";