1 package spoon.support.reflect.declaration; 2 3 import java.util.Set ; 4 import java.util.TreeSet ; 5 6 import spoon.reflect.declaration.CtPackage; 7 import spoon.reflect.declaration.CtSimpleType; 8 import spoon.reflect.reference.CtPackageReference; 9 import spoon.reflect.visitor.CtVisitor; 10 11 16 public class CtPackageImpl extends CtNamedElementImpl implements CtPackage { 17 private static final long serialVersionUID = 1L; 18 19 Set <CtPackage> packs = new TreeSet <CtPackage>(); 20 21 Set <CtSimpleType<?>> types = new TreeSet <CtSimpleType<?>>(); 22 23 public CtPackageImpl() { 24 super(); 25 } 26 27 public void accept(CtVisitor v) { 28 v.visitCtPackage(this); 29 } 30 31 public CtPackage getDeclaringPackage() { 32 if (parent == null) 33 return null; 34 return getParent(CtPackage.class); 35 } 36 37 public CtPackage getPackage(String name) { 38 for (CtPackage p : packs) { 39 if (p.getSimpleName().equals(name)) 40 return p; 41 } 42 return null; 43 } 44 45 public Set <CtPackage> getPackages() { 46 return packs; 47 } 48 49 public String getQualifiedName() { 50 if (getDeclaringPackage() == null) 51 return getSimpleName(); 52 return getDeclaringPackage().getQualifiedName() + "." + getSimpleName(); 53 } 54 55 public CtSimpleType<?> getType(String simpleName) { 56 for (CtSimpleType t : types) { 57 if (t.getSimpleName().equals(simpleName)) { 58 return t; 59 } 60 } 61 return null; 62 } 63 64 public Set <CtSimpleType<?>> getTypes() { 65 return types; 66 } 67 68 public void setPackages(Set <CtPackage> packs) { 69 this.packs = packs; 70 } 71 72 public void setTypes(Set <CtSimpleType<?>> types) { 73 this.types = types; 74 } 75 76 @Override 77 public CtPackageReference getReference() { 78 return getFactory().Package().createReference(this); 79 } 80 } 81 | Popular Tags |