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 LoggerVariableModifiersCheck extends Check {
17 private static final String LOG_MESSAGE = "Logger must be declared as private static final.";
20 public int[] getDefaultTokens() {
21 return new int[]{TokenTypes.VARIABLE_DEF};
25 public void visitToken(DetailAST aAST) {
26 if (CheckLoggingUtil.isAFieldVariable(aAST) && CheckLoggingUtil.isLoggerType(aAST)
27 && !hasPrivatStaticFinalModifier(aAST)) {
28 log(aAST.getLineNo(), LOG_MESSAGE);
32 private boolean hasPrivatStaticFinalModifier(DetailAST aAST) {
33 DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS);
34 if (modifiers != null && modifiers.branchContains(TokenTypes.LITERAL_PRIVATE) && modifiers.branchContains
35 (TokenTypes.LITERAL_STATIC) && modifiers.branchContains(TokenTypes.FINAL)) {