View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 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.Serial;
23  import java.io.Serializable;
24  
25  /**
26   * Thread mode settings for the checkstyle modules.
27   *
28   * @param checkerThreadsNumber the Checker threads number
29   * @param treeWalkerThreadsNumber the TreeWalker threads number
30   *
31   * @noinspectionreason SerializableHasSerializationMethods - we only need serialVersionUID
32   *      to differentiate between threads
33   */
34  public record ThreadModeSettings(int checkerThreadsNumber,
35                                   int treeWalkerThreadsNumber) implements Serializable {
36  
37      /** A checker module name. */
38      public static final String CHECKER_MODULE_NAME = Checker.class.getSimpleName();
39  
40      /** A multi thread checker module name. */
41      public static final String MULTI_THREAD_CHECKER_MODULE_NAME =
42              Checker.class.getSimpleName();
43  
44      /** A three walker module name. */
45      public static final String TREE_WALKER_MODULE_NAME = TreeWalker.class.getSimpleName();
46  
47      /** A multi thread three walker module name. */
48      public static final String MULTI_THREAD_TREE_WALKER_MODULE_NAME =
49              TreeWalker.class.getSimpleName();
50  
51      /** A single thread mode settings instance. */
52      public static final ThreadModeSettings SINGLE_THREAD_MODE_INSTANCE =
53              new ThreadModeSettings(1, 1);
54  
55      /** A unique serial version identifier. */
56      @Serial
57      private static final long serialVersionUID = 1L;
58  
59      /**
60       * Resolves the module name according to the thread settings.
61       *
62       * @param name The original module name.
63       * @return resolved module name.
64       * @throws IllegalArgumentException when name is Checker or TreeWalker
65       */
66      public String resolveName(String name) {
67          if (checkerThreadsNumber > 1) {
68              if (CHECKER_MODULE_NAME.equals(name)) {
69                  throw new IllegalArgumentException(
70                          "Multi thread mode for Checker module is not implemented");
71              }
72              if (TREE_WALKER_MODULE_NAME.equals(name)) {
73                  throw new IllegalArgumentException(
74                          "Multi thread mode for TreeWalker module is not implemented");
75              }
76          }
77  
78          return name;
79      }
80  }