001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2025 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.Serial; 023import java.io.Serializable; 024 025/** 026 * Thread mode settings for the checkstyle modules. 027 * 028 * @noinspection SerializableHasSerializationMethods 029 * @noinspectionreason SerializableHasSerializationMethods - we only need serialVersionUID 030 * to differentiate between threads 031 */ 032public class ThreadModeSettings implements Serializable { 033 034 /** A checker module name. */ 035 public static final String CHECKER_MODULE_NAME = Checker.class.getSimpleName(); 036 037 /** A multi thread checker module name. */ 038 public static final String MULTI_THREAD_CHECKER_MODULE_NAME = 039 Checker.class.getSimpleName(); 040 041 /** A three walker module name. */ 042 public static final String TREE_WALKER_MODULE_NAME = TreeWalker.class.getSimpleName(); 043 044 /** A multi thread three walker module name. */ 045 public static final String MULTI_THREAD_TREE_WALKER_MODULE_NAME = 046 TreeWalker.class.getSimpleName(); 047 048 /** A single thread mode settings instance. */ 049 public static final ThreadModeSettings SINGLE_THREAD_MODE_INSTANCE = 050 new ThreadModeSettings(1, 1); 051 052 /** A unique serial version identifier. */ 053 @Serial 054 private static final long serialVersionUID = 1L; 055 056 /** The checker threads number. */ 057 private final int checkerThreadsNumber; 058 /** The tree walker threads number. */ 059 private final int treeWalkerThreadsNumber; 060 061 /** 062 * Initializes the thread mode configuration. 063 * 064 * @param checkerThreadsNumber the Checker threads number 065 * @param treeWalkerThreadsNumber the TreeWalker threads number 066 */ 067 public ThreadModeSettings(int checkerThreadsNumber, int treeWalkerThreadsNumber) { 068 this.checkerThreadsNumber = checkerThreadsNumber; 069 this.treeWalkerThreadsNumber = treeWalkerThreadsNumber; 070 } 071 072 /** 073 * Gets the number of threads for the Checker module. 074 * 075 * @return the number of threads for the Checker module. 076 */ 077 public int getCheckerThreadsNumber() { 078 return checkerThreadsNumber; 079 } 080 081 /** 082 * Gets the number of threads for the TreeWalker module. 083 * 084 * @return the number of threads for the TreeWalker module. 085 */ 086 public int getTreeWalkerThreadsNumber() { 087 return treeWalkerThreadsNumber; 088 } 089 090 /** 091 * Resolves the module name according to the thread settings. 092 * 093 * @param name The original module name. 094 * @return resolved module name. 095 * @throws IllegalArgumentException when name is Checker or TreeWalker 096 */ 097 public final String resolveName(String name) { 098 if (checkerThreadsNumber > 1) { 099 if (CHECKER_MODULE_NAME.equals(name)) { 100 throw new IllegalArgumentException( 101 "Multi thread mode for Checker module is not implemented"); 102 } 103 if (TREE_WALKER_MODULE_NAME.equals(name)) { 104 throw new IllegalArgumentException( 105 "Multi thread mode for TreeWalker module is not implemented"); 106 } 107 } 108 109 return name; 110 } 111 112}