1 package spoon.reflect.factory; 2 3 import spoon.reflect.Factory; 4 import spoon.reflect.declaration.CtInterface; 5 import spoon.reflect.declaration.CtPackage; 6 import spoon.reflect.declaration.CtType; 7 8 11 public class InterfaceFactory extends TypeFactory { 12 13 private static final long serialVersionUID = 1L; 14 15 19 public InterfaceFactory(Factory factory) { 20 super(factory); 21 } 22 23 26 public <T> CtInterface<T> create(CtPackage owner, String simpleName) { 27 CtInterface<T> i = factory.Core().createInterface(); 28 i.setSimpleName(simpleName); 29 owner.getTypes().add(i); 30 i.setParent(owner); 31 return i; 32 } 33 34 37 public <T> CtInterface<T> create(CtType<T> owner, String simpleName) { 38 CtInterface<T> i = factory.Core().createInterface(); 39 i.setSimpleName(simpleName); 40 owner.getNestedTypes().add(i); 41 i.setParent(owner); 42 return i; 43 } 44 45 48 @SuppressWarnings ("unchecked") 49 public <T> CtInterface<T> create(String qualifiedName) { 50 if (hasInnerType(qualifiedName) > 0) { 51 return create( 52 (CtInterface<T>) create(getDeclaringTypeName(qualifiedName)), 53 getSimpleName(qualifiedName)); 54 } else { 55 return create(factory.Package().getOrCreate(getPackageName(qualifiedName)), 56 getSimpleName(qualifiedName)); 57 } 58 } 59 60 65 @SuppressWarnings ("unchecked") 66 public <T> CtInterface<T> get(String qualifiedName) { 67 try { 68 return (CtInterface<T>) super.get(qualifiedName); 69 } catch (Exception e) { 70 return null; 71 } 72 } 73 74 82 public <T> CtInterface<T> get(Class <T> cl) { 83 try { 84 return (CtInterface<T>) super.get(cl); 85 } catch (Exception e) { 86 return null; 87 } 88 } 89 90 91 } | Popular Tags |