001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 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//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.api; 020 021/** 022 * Represents a Java visibility scope. 023 * 024 * @author Lars Kühne 025 * @author Travis Schneeberger 026 */ 027public enum Scope 028{ 029 /** nothing scope. */ 030 NOTHING, 031 /** public scope. */ 032 PUBLIC, 033 /** protected scope. */ 034 PROTECTED, 035 /** package or default scope. */ 036 PACKAGE, 037 /** private scope. */ 038 PRIVATE, 039 /** anonymous inner scope. */ 040 ANONINNER; 041 042 @Override 043 public String toString() 044 { 045 return getName(); 046 } 047 048 /** 049 * @return the name of this severity level. 050 */ 051 public String getName() 052 { 053 return name().toLowerCase(); 054 } 055 056 /** 057 * Checks if this scope is a subscope of another scope. 058 * Example: PUBLIC is a subscope of PRIVATE. 059 * 060 * @param scope a <code>Scope</code> value 061 * @return if <code>this</code> is a subscope of <code>scope</code>. 062 */ 063 public boolean isIn(Scope scope) 064 { 065 return (compareTo(scope) <= 0); 066 } 067 068 /** 069 * Scope factory method. 070 * 071 * @param scopeName scope name, such as "nothing", "public", etc. 072 * @return the <code>Scope</code> associated with <code>scopeName</code> 073 */ 074 public static Scope getInstance(String scopeName) 075 { 076 return valueOf(Scope.class, scopeName.trim().toUpperCase()); 077 } 078}