1 package spoon.reflect.factory; 2 3 import spoon.reflect.Factory; 4 import spoon.reflect.declaration.CtClass; 5 import spoon.reflect.declaration.CtPackage; 6 7 10 public class ClassFactory extends TypeFactory { 11 12 private static final long serialVersionUID = 1L; 13 14 20 public ClassFactory(Factory factory) { 21 super(factory); 22 } 23 24 32 public <T> CtClass<T> create(CtClass<?> declaringClass, String simpleName) { 33 CtClass<T> c = factory.Core().createClass(); 34 c.setSimpleName(simpleName); 35 c.setParent(declaringClass); 36 return c; 37 } 38 39 47 public <T> CtClass<T> create(CtPackage owner, String simpleName) { 48 CtClass<T> c = factory.Core().createClass(); 49 c.setSimpleName(simpleName); 50 if (owner.getTypes().contains(c)) 51 owner.getTypes().remove(c); 52 owner.getTypes().add(c); 53 c.setParent(owner); 54 return c; 55 } 56 57 66 public <T> CtClass<T> create(String qualifiedName) { 67 if (hasInnerType(qualifiedName) > 0) { 68 CtClass<?> declaringClass = create(getDeclaringTypeName(qualifiedName)); 69 return create(declaringClass, getSimpleName(qualifiedName)); 70 } else { 71 return create(factory.Package().getOrCreate(getPackageName(qualifiedName)), 72 getSimpleName(qualifiedName)); 73 } 74 } 75 76 84 public <T> CtClass<T> get(Class <T> cl) { 85 try { 86 return (CtClass<T>) super.get(cl); 87 } catch (Exception e) { 88 return null; 89 } 90 } 91 92 101 @SuppressWarnings ("unchecked") 102 public <T> CtClass<T> get(String qualifiedName) { 103 try { 104 return (CtClass<T>) super.get(qualifiedName); 105 } catch (Exception e) { 106 return null; 107 } 108 } 109 110 } | Popular Tags |