001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2019 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 * The number of other classes a given class relies on. Also the square
026 * of this has been shown to indicate the amount of maintenance required
027 * in functional programs (on a file basis) at least.
028 *
029 */
030public final class ClassFanOutComplexityCheck extends AbstractClassCouplingCheck {
031
032    /**
033     * A key is pointing to the warning message text in "messages.properties"
034     * file.
035     */
036    public static final String MSG_KEY = "classFanOutComplexity";
037
038    /** Default value of max value. */
039    private static final int DEFAULT_MAX = 20;
040
041    /** Creates new instance of this check. */
042    public ClassFanOutComplexityCheck() {
043        super(DEFAULT_MAX);
044    }
045
046    @Override
047    public int[] getRequiredTokens() {
048        return new int[] {
049            TokenTypes.PACKAGE_DEF,
050            TokenTypes.IMPORT,
051            TokenTypes.CLASS_DEF,
052            TokenTypes.EXTENDS_CLAUSE,
053            TokenTypes.IMPLEMENTS_CLAUSE,
054            TokenTypes.ANNOTATION,
055            TokenTypes.INTERFACE_DEF,
056            TokenTypes.ENUM_DEF,
057            TokenTypes.TYPE,
058            TokenTypes.LITERAL_NEW,
059            TokenTypes.LITERAL_THROWS,
060            TokenTypes.ANNOTATION_DEF,
061        };
062    }
063
064    @Override
065    public int[] getAcceptableTokens() {
066        return getRequiredTokens();
067    }
068
069    // -@cs[SimpleAccessorNameNotation] Override methods from base class.
070    // Issue: https://github.com/sevntu-checkstyle/sevntu.checkstyle/issues/166
071    @Override
072    protected String getLogMessageId() {
073        return MSG_KEY;
074    }
075
076}