001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2018 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 033 /** Nothing scope. */ 034 NOTHING, 035 /** Public scope. */ 036 PUBLIC, 037 /** Protected scope. */ 038 PROTECTED, 039 /** Package or default scope. */ 040 PACKAGE, 041 /** Private scope. */ 042 PRIVATE, 043 /** Anonymous inner scope. */ 044 ANONINNER; 045 046 @Override 047 public String toString() { 048 return getName(); 049 } 050 051 /** 052 * Returns name of severity level. 053 * @return the name of this severity level. 054 */ 055 public String getName() { 056 return name().toLowerCase(Locale.ENGLISH); 057 } 058 059 /** 060 * Checks if this scope is a subscope of another scope. 061 * Example: PUBLIC is a subscope of PRIVATE. 062 * 063 * @param scope a {@code Scope} value 064 * @return if {@code this} is a subscope of {@code scope}. 065 */ 066 public boolean isIn(Scope scope) { 067 return compareTo(scope) <= 0; 068 } 069 070 /** 071 * Scope factory method. 072 * 073 * @param scopeName scope name, such as "nothing", "public", etc. 074 * @return the {@code Scope} associated with {@code scopeName} 075 */ 076 public static Scope getInstance(String scopeName) { 077 return valueOf(Scope.class, scopeName.trim().toUpperCase(Locale.ENGLISH)); 078 } 079 080}