001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2017 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle; 021 022import java.io.Serializable; 023 024/** 025 * Thread mode settings for the checkstyle modules. 026 * @author Andrew Kuchev 027 * @noinspection SerializableHasSerializationMethods 028 */ 029public class ThreadModeSettings implements Serializable { 030 /** A checker module name. */ 031 public static final String CHECKER_MODULE_NAME = Checker.class.getSimpleName(); 032 033 /** A multi thread checker module name. */ 034 public static final String MULTI_THREAD_CHECKER_MODULE_NAME = 035 Checker.class.getSimpleName(); 036 037 /** A three walker module name. */ 038 public static final String TREE_WALKER_MODULE_NAME = TreeWalker.class.getSimpleName(); 039 040 /** A multi thread three walker module name. */ 041 public static final String MULTI_THREAD_TREE_WALKER_MODULE_NAME = 042 TreeWalker.class.getSimpleName(); 043 044 /** A single thread mode settings instance. */ 045 public static final ThreadModeSettings SINGLE_THREAD_MODE_INSTANCE = 046 new ThreadModeSettings(1, 1); 047 048 private static final long serialVersionUID = 1L; 049 050 /** The checker threads number. */ 051 private final int checkerThreadsNumber; 052 /** The tree walker threads number. */ 053 private final int treeWalkerThreadsNumber; 054 055 /** 056 * Initializes the thread mode configuration. 057 * @param checkerThreadsNumber the Checker threads number 058 * @param treeWalkerThreadsNumber the TreeWalker threads number 059 */ 060 public ThreadModeSettings(int checkerThreadsNumber, int treeWalkerThreadsNumber) { 061 this.checkerThreadsNumber = checkerThreadsNumber; 062 this.treeWalkerThreadsNumber = treeWalkerThreadsNumber; 063 } 064 065 /** 066 * Gets the number of threads for the Checker module. 067 * @return the number of threads for the Checker module. 068 */ 069 public int getCheckerThreadsNumber() { 070 return checkerThreadsNumber; 071 } 072 073 /** 074 * Gets the number of threads for the TreeWalker module. 075 * @return the number of threads for the TreeWalker module. 076 */ 077 public int getTreeWalkerThreadsNumber() { 078 return treeWalkerThreadsNumber; 079 } 080 081 /** 082 * Resolves the module name according to the thread settings. 083 * @param name The original module name. 084 * @return resolved module name. 085 */ 086 public final String resolveName(String name) { 087 if (checkerThreadsNumber > 1) { 088 if (CHECKER_MODULE_NAME.equals(name)) { 089 throw new IllegalArgumentException( 090 "Multi thread mode for Checker module is not implemented"); 091 } 092 if (TREE_WALKER_MODULE_NAME.equals(name)) { 093 throw new IllegalArgumentException( 094 "Multi thread mode for TreeWalker module is not implemented"); 095 } 096 } 097 098 return name; 099 } 100}