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.api;
021
022import java.util.Locale;
023
024/**
025 * Represents a Java visibility scope.
026 *
027 * @author Lars Kühne
028 * @author Travis Schneeberger
029 * @author Mehmet Can Cömert
030 */
031public enum Scope {
032    /** Nothing scope. */
033    NOTHING,
034    /** Public scope. */
035    PUBLIC,
036    /** Protected scope. */
037    PROTECTED,
038    /** Package or default scope. */
039    PACKAGE,
040    /** Private scope. */
041    PRIVATE,
042    /** Anonymous inner scope. */
043    ANONINNER;
044
045    @Override
046    public String toString() {
047        return getName();
048    }
049
050    /**
051     * Returns name of severity level.
052     * @return the name of this severity level.
053     */
054    public String getName() {
055        return name().toLowerCase(Locale.ENGLISH);
056    }
057
058    /**
059     * Checks if this scope is a subscope of another scope.
060     * Example: PUBLIC is a subscope of PRIVATE.
061     *
062     * @param scope a {@code Scope} value
063     * @return if {@code this} is a subscope of {@code scope}.
064     */
065    public boolean isIn(Scope scope) {
066        return compareTo(scope) <= 0;
067    }
068
069    /**
070     * Scope factory method.
071     *
072     * @param scopeName scope name, such as "nothing", "public", etc.
073     * @return the {@code Scope} associated with {@code scopeName}
074     */
075    public static Scope getInstance(String scopeName) {
076        return valueOf(Scope.class, scopeName.trim().toUpperCase(Locale.ENGLISH));
077    }
078}