1 /* 2 * Copyright (C) 2007-2010 Júlio Vilmar Gesser. 3 * Copyright (C) 2011, 2013-2016 The JavaParser Team. 4 * 5 * This file is part of JavaParser. 6 * 7 * JavaParser can be used either under the terms of 8 * a) the GNU Lesser General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * b) the terms of the Apache License 12 * 13 * You should have received a copy of both licenses in LICENCE.LGPL and 14 * LICENCE.APACHE. Please refer to those files for details. 15 * 16 * JavaParser is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 */ 21 22 package com.github.javaparser.resolution.declarations; 23 24 import java.util.List; 25 26 /** 27 * Declaration of an Enum. 28 * 29 * @author Federico Tomassetti 30 */ 31 public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration, 32 HasAccessSpecifier { 33 34 @Override isEnum()35 default boolean isEnum() { 36 return true; 37 } 38 39 @Override asEnum()40 default ResolvedEnumDeclaration asEnum() { 41 return this; 42 } 43 getEnumConstants()44 List<ResolvedEnumConstantDeclaration> getEnumConstants(); 45 hasEnumConstant(String name)46 default boolean hasEnumConstant(String name) { 47 return getEnumConstants().stream().anyMatch(c -> c.getName().equals(name)); 48 } 49 getEnumConstant(final String name)50 default ResolvedEnumConstantDeclaration getEnumConstant(final String name) { 51 return getEnumConstants().stream().filter(c -> c.getName().equals(name)).findFirst() 52 .orElseThrow(() -> new IllegalArgumentException("No constant named " + name)); 53 } 54 } 55