001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2017 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.checks.metrics; 021 022import com.puppycrawl.tools.checkstyle.api.TokenTypes; 023 024/** 025 * This metric measures the number of instantiations of other classes 026 * within the given class. 027 * 028 * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a> 029 * @author o_sukhodolsky 030 */ 031public final class ClassDataAbstractionCouplingCheck 032 extends AbstractClassCouplingCheck { 033 034 /** 035 * A key is pointing to the warning message text in "messages.properties" 036 * file. 037 */ 038 public static final String MSG_KEY = "classDataAbstractionCoupling"; 039 040 /** Default allowed complexity. */ 041 private static final int DEFAULT_MAX = 7; 042 043 /** Creates bew instance of the check. */ 044 public ClassDataAbstractionCouplingCheck() { 045 super(DEFAULT_MAX); 046 setTokens("LITERAL_NEW"); 047 } 048 049 @Override 050 public int[] getRequiredTokens() { 051 return new int[] { 052 TokenTypes.PACKAGE_DEF, 053 TokenTypes.IMPORT, 054 TokenTypes.CLASS_DEF, 055 TokenTypes.INTERFACE_DEF, 056 TokenTypes.ENUM_DEF, 057 TokenTypes.LITERAL_NEW, 058 }; 059 } 060 061 @Override 062 public int[] getAcceptableTokens() { 063 return new int[] { 064 TokenTypes.PACKAGE_DEF, 065 TokenTypes.IMPORT, 066 TokenTypes.CLASS_DEF, 067 TokenTypes.INTERFACE_DEF, 068 TokenTypes.ENUM_DEF, 069 TokenTypes.LITERAL_NEW, 070 }; 071 } 072 073 // -@cs[SimpleAccessorNameNotation] Overrides method from the base class. 074 // Issue: https://github.com/sevntu-checkstyle/sevntu.checkstyle/issues/166 075 @Override 076 protected String getLogMessageId() { 077 return MSG_KEY; 078 } 079}