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   * This metric measures the number of instantiations of other classes
26   * within the given class.
27   *
28   * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a>
29   * @author o_sukhodolsky
30   */
31  public final class ClassDataAbstractionCouplingCheck
32      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 = "classDataAbstractionCoupling";
39  
40      /** Default allowed complexity. */
41      private static final int DEFAULT_MAX = 7;
42  
43      /** Creates bew instance of the check. */
44      public ClassDataAbstractionCouplingCheck() {
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.LITERAL_NEW,
57          };
58      }
59  
60      @Override
61      public int[] getAcceptableTokens() {
62          return getRequiredTokens();
63      }
64  
65      // -@cs[SimpleAccessorNameNotation] Overrides method from the base class.
66      // Issue: https://github.com/sevntu-checkstyle/sevntu.checkstyle/issues/166
67      @Override
68      protected String getLogMessageId() {
69          return MSG_KEY;
70      }
71  }