View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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.checks.metrics;
21  
22  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
23  
24  /**
25   * The number of other classes a given class relies on. Also the square
26   * of this has been shown to indicate the amount of maintenance required
27   * in functional programs (on a file basis) at least.
28   *
29   * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a>
30   * @author o_sukhodolsky
31   */
32  public final class ClassFanOutComplexityCheck extends AbstractClassCouplingCheck {
33  
34      /**
35       * A key is pointing to the warning message text in "messages.properties"
36       * file.
37       */
38      public static final String MSG_KEY = "classFanOutComplexity";
39  
40      /** Default value of max value. */
41      private static final int DEFAULT_MAX = 20;
42  
43      /** Creates new instance of this check. */
44      public ClassFanOutComplexityCheck() {
45          super(DEFAULT_MAX);
46      }
47  
48      @Override
49      public int[] getRequiredTokens() {
50          return new int[] {
51              TokenTypes.PACKAGE_DEF,
52              TokenTypes.IMPORT,
53              TokenTypes.CLASS_DEF,
54              TokenTypes.INTERFACE_DEF,
55              TokenTypes.ENUM_DEF,
56              TokenTypes.TYPE,
57              TokenTypes.LITERAL_NEW,
58              TokenTypes.LITERAL_THROWS,
59              TokenTypes.ANNOTATION_DEF,
60          };
61      }
62  
63      @Override
64      public int[] getAcceptableTokens() {
65          return getRequiredTokens();
66      }
67  
68      // -@cs[SimpleAccessorNameNotation] Override methods from base class.
69      // Issue: https://github.com/sevntu-checkstyle/sevntu.checkstyle/issues/166
70      @Override
71      protected String getLogMessageId() {
72          return MSG_KEY;
73      }
74  }