KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > support > reflect > declaration > CtPackageImpl


1 package spoon.support.reflect.declaration;
2
3 import java.util.Set JavaDoc;
4 import java.util.TreeSet JavaDoc;
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 /**
12  * The implementation for {@link spoon.reflect.declaration.CtPackage}.
13  *
14  * @author Renaud Pawlak
15  */

16 public class CtPackageImpl extends CtNamedElementImpl implements CtPackage {
17     private static final long serialVersionUID = 1L;
18
19     Set JavaDoc<CtPackage> packs = new TreeSet JavaDoc<CtPackage>();
20
21     Set JavaDoc<CtSimpleType<?>> types = new TreeSet JavaDoc<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 JavaDoc name) {
38         for (CtPackage p : packs) {
39             if (p.getSimpleName().equals(name))
40                 return p;
41         }
42         return null;
43     }
44
45     public Set JavaDoc<CtPackage> getPackages() {
46         return packs;
47     }
48
49     public String JavaDoc getQualifiedName() {
50         if (getDeclaringPackage() == null)
51             return getSimpleName();
52         return getDeclaringPackage().getQualifiedName() + "." + getSimpleName();
53     }
54
55     public CtSimpleType<?> getType(String JavaDoc 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 JavaDoc<CtSimpleType<?>> getTypes() {
65         return types;
66     }
67
68     public void setPackages(Set JavaDoc<CtPackage> packs) {
69         this.packs = packs;
70     }
71
72     public void setTypes(Set JavaDoc<CtSimpleType<?>> types) {
73         this.types = types;
74     }
75
76     @Override JavaDoc
77     public CtPackageReference getReference() {
78         return getFactory().Package().createReference(this);
79     }
80 }
81
Popular Tags