View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2018 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   * @author Andrew Kuchev
27   * @noinspection SerializableHasSerializationMethods
28   */
29  public class ThreadModeSettings implements Serializable {
30  
31      /** A checker module name. */
32      public static final String CHECKER_MODULE_NAME = Checker.class.getSimpleName();
33  
34      /** A multi thread checker module name. */
35      public static final String MULTI_THREAD_CHECKER_MODULE_NAME =
36              Checker.class.getSimpleName();
37  
38      /** A three walker module name. */
39      public static final String TREE_WALKER_MODULE_NAME = TreeWalker.class.getSimpleName();
40  
41      /** A multi thread three walker module name. */
42      public static final String MULTI_THREAD_TREE_WALKER_MODULE_NAME =
43              TreeWalker.class.getSimpleName();
44  
45      /** A single thread mode settings instance. */
46      public static final ThreadModeSettings SINGLE_THREAD_MODE_INSTANCE =
47              new ThreadModeSettings(1, 1);
48  
49      private static final long serialVersionUID = 1L;
50  
51      /** The checker threads number. */
52      private final int checkerThreadsNumber;
53      /** The tree walker threads number. */
54      private final int treeWalkerThreadsNumber;
55  
56      /**
57       * Initializes the thread mode configuration.
58       * @param checkerThreadsNumber the Checker threads number
59       * @param treeWalkerThreadsNumber the TreeWalker threads number
60       */
61      public ThreadModeSettings(int checkerThreadsNumber, int treeWalkerThreadsNumber) {
62          this.checkerThreadsNumber = checkerThreadsNumber;
63          this.treeWalkerThreadsNumber = treeWalkerThreadsNumber;
64      }
65  
66      /**
67       * Gets the number of threads for the Checker module.
68       * @return the number of threads for the Checker module.
69       */
70      public int getCheckerThreadsNumber() {
71          return checkerThreadsNumber;
72      }
73  
74      /**
75       * Gets the number of threads for the TreeWalker module.
76       * @return the number of threads for the TreeWalker module.
77       */
78      public int getTreeWalkerThreadsNumber() {
79          return treeWalkerThreadsNumber;
80      }
81  
82      /**
83       * Resolves the module name according to the thread settings.
84       * @param name The original module name.
85       * @return resolved module name.
86       */
87      public final String resolveName(String name) {
88          if (checkerThreadsNumber > 1) {
89              if (CHECKER_MODULE_NAME.equals(name)) {
90                  throw new IllegalArgumentException(
91                          "Multi thread mode for Checker module is not implemented");
92              }
93              if (TREE_WALKER_MODULE_NAME.equals(name)) {
94                  throw new IllegalArgumentException(
95                          "Multi thread mode for TreeWalker module is not implemented");
96              }
97          }
98  
99          return name;
100     }
101 
102 }