1 //////////////////////////////////////////////////////////////////////////////// 2 // checkstyle: Checks Java source code for adherence to a set of rules. 3 // Copyright (C) 2001-2019 the original author or authors. 4 // 5 // This library is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU Lesser General Public 7 // License as published by the Free Software Foundation; either 8 // version 2.1 of the License, or (at your option) any later version. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with this library; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 //////////////////////////////////////////////////////////////////////////////// 19 20 package com.puppycrawl.tools.checkstyle; 21 22 import java.io.Serializable; 23 24 /** 25 * Thread mode settings for the checkstyle modules. 26 * @noinspection SerializableHasSerializationMethods 27 */ 28 public class ThreadModeSettings implements Serializable { 29 30 /** A checker module name. */ 31 public static final String CHECKER_MODULE_NAME = Checker.class.getSimpleName(); 32 33 /** A multi thread checker module name. */ 34 public static final String MULTI_THREAD_CHECKER_MODULE_NAME = 35 Checker.class.getSimpleName(); 36 37 /** A three walker module name. */ 38 public static final String TREE_WALKER_MODULE_NAME = TreeWalker.class.getSimpleName(); 39 40 /** A multi thread three walker module name. */ 41 public static final String MULTI_THREAD_TREE_WALKER_MODULE_NAME = 42 TreeWalker.class.getSimpleName(); 43 44 /** A single thread mode settings instance. */ 45 public static final ThreadModeSettings SINGLE_THREAD_MODE_INSTANCE = 46 new ThreadModeSettings(1, 1); 47 48 private static final long serialVersionUID = 1L; 49 50 /** The checker threads number. */ 51 private final int checkerThreadsNumber; 52 /** The tree walker threads number. */ 53 private final int treeWalkerThreadsNumber; 54 55 /** 56 * Initializes the thread mode configuration. 57 * @param checkerThreadsNumber the Checker threads number 58 * @param treeWalkerThreadsNumber the TreeWalker threads number 59 */ 60 public ThreadModeSettings(int checkerThreadsNumber, int treeWalkerThreadsNumber) { 61 this.checkerThreadsNumber = checkerThreadsNumber; 62 this.treeWalkerThreadsNumber = treeWalkerThreadsNumber; 63 } 64 65 /** 66 * Gets the number of threads for the Checker module. 67 * @return the number of threads for the Checker module. 68 */ 69 public int getCheckerThreadsNumber() { 70 return checkerThreadsNumber; 71 } 72 73 /** 74 * Gets the number of threads for the TreeWalker module. 75 * @return the number of threads for the TreeWalker module. 76 */ 77 public int getTreeWalkerThreadsNumber() { 78 return treeWalkerThreadsNumber; 79 } 80 81 /** 82 * Resolves the module name according to the thread settings. 83 * @param name The original module name. 84 * @return resolved module name. 85 */ 86 public final String resolveName(String name) { 87 if (checkerThreadsNumber > 1) { 88 if (CHECKER_MODULE_NAME.equals(name)) { 89 throw new IllegalArgumentException( 90 "Multi thread mode for Checker module is not implemented"); 91 } 92 if (TREE_WALKER_MODULE_NAME.equals(name)) { 93 throw new IllegalArgumentException( 94 "Multi thread mode for TreeWalker module is not implemented"); 95 } 96 } 97 98 return name; 99 } 100 101 }