KickJava   Java API By Example, From Geeks To Geeks.

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


1 package spoon.support.reflect.declaration;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Set JavaDoc;
6 import java.util.TreeSet JavaDoc;
7
8 import spoon.reflect.declaration.CtField;
9 import spoon.reflect.declaration.CtPackage;
10 import spoon.reflect.declaration.CtSimpleType;
11 import spoon.reflect.reference.CtTypeReference;
12
13 public abstract class CtSimpleTypeImpl<T> extends CtNamedElementImpl implements
14         CtSimpleType<T> {
15
16     List JavaDoc<CtField<?>> fields = new ArrayList JavaDoc<CtField<?>>();
17
18     Set JavaDoc<CtSimpleType<?>> nestedTypes = new TreeSet JavaDoc<CtSimpleType<?>>();
19
20     public Class JavaDoc<T> getActualClass() {
21         return getFactory().Type().createReference(this).getActualClass();
22     }
23
24     public List JavaDoc<CtField<?>> getAllFields() {
25         return getFields();
26     }
27
28     public CtSimpleType<?> getDeclaringType() {
29         if (parent instanceof CtSimpleType) {
30             return (CtSimpleType) parent;
31         } else {
32             return null;
33         }
34     }
35
36     public CtField<?> getField(String JavaDoc name) {
37         for (CtField<?> f : fields) {
38             if (f.getSimpleName().equals(name)) {
39                 return f;
40             }
41         }
42         return null;
43     }
44
45     public List JavaDoc<CtField<?>> getFields() {
46         return fields;
47     }
48
49     public CtSimpleType<?> getNestedType(String JavaDoc name) {
50         for (CtSimpleType<?> t : nestedTypes) {
51             if (t.getSimpleName().equals(name)) {
52                 return t;
53             }
54         }
55         return null;
56     }
57
58     public Set JavaDoc<CtSimpleType<?>> getNestedTypes() {
59         return nestedTypes;
60     }
61
62     public CtPackage getPackage() {
63         if (parent instanceof CtPackage) {
64             return (CtPackage) parent;
65         } else if (parent instanceof CtSimpleType) {
66             return ((CtSimpleType<?>) parent).getPackage();
67         } else {
68             return null;
69         }
70     }
71
72     public String JavaDoc getQualifiedName() {
73         if (getPackage() != null
74                 && !getPackage().getSimpleName().equals(
75                         CtPackage.TOP_LEVEL_PACKAGE_NAME)) {
76             return getPackage().getQualifiedName() + "." + getSimpleName();
77         }
78         return getSimpleName();
79     }
80
81     @Override JavaDoc
82     public CtTypeReference<T> getReference() {
83         return getFactory().Type().createReference(this);
84     }
85
86     public boolean isTopLevel() {
87         return getDeclaringType() == null && getPackage() != null;
88     }
89
90     public void setFields(List JavaDoc<CtField<?>> fields) {
91         this.fields = fields;
92     }
93
94     public void setNestedTypes(Set JavaDoc<CtSimpleType<?>> nestedTypes) {
95         this.nestedTypes = nestedTypes;
96     }
97 }
98
Popular Tags