1 package spoon.reflect.factory; 2 3 import spoon.reflect.Factory; 4 import spoon.reflect.declaration.CtEnum; 5 import spoon.reflect.declaration.CtPackage; 6 7 10 public class EnumFactory extends TypeFactory { 11 12 private static final long serialVersionUID = 1L; 13 14 18 public EnumFactory(Factory factory) { 19 super(factory); 20 } 21 22 30 public CtEnum create(CtPackage owner, String simpleName) { 31 CtEnum e = factory.Core().createEnum(); 32 e.setSimpleName(simpleName); 33 owner.getTypes().add(e); 34 e.setParent(owner); 35 return e; 36 } 37 38 41 public CtEnum create(String qualifiedName) { 42 return create(factory.Package().getOrCreate(getPackageName(qualifiedName)), 43 getSimpleName(qualifiedName)); 44 } 45 46 51 @SuppressWarnings ("unchecked") 52 public CtEnum get(String qualifiedName) { 53 try { 54 return (CtEnum) super.get(qualifiedName); 55 } catch (Exception e) { 56 return null; 57 } 58 } 59 60 68 public <T extends Enum > CtEnum<T> get(Class <T> cl) { 69 try { 70 return (CtEnum<T>) super.get(cl); 71 } catch (Exception e) { 72 return null; 73 } 74 } 75 76 } 77 | Popular Tags |