KickJava   Java API By Example, From Geeks To Geeks.

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


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.CtMethod;
9 import spoon.reflect.declaration.CtType;
10 import spoon.reflect.reference.CtTypeReference;
11
12 /**
13  * The implementation for {@link spoon.reflect.declaration.CtType}.
14  */

15 public abstract class CtTypeImpl<T> extends CtSimpleTypeImpl<T> implements
16         CtType<T> {
17
18     List JavaDoc<CtTypeReference<?>> formalTypeParameters = new ArrayList JavaDoc<CtTypeReference<?>>();
19
20     Set JavaDoc<CtTypeReference<?>> interfaces = new TreeSet JavaDoc<CtTypeReference<?>>();
21
22     Set JavaDoc<CtMethod<?>> methods = new TreeSet JavaDoc<CtMethod<?>>();
23
24     public CtTypeImpl() {
25         super();
26     }
27
28     public List JavaDoc<CtTypeReference<?>> getFormalTypeParameters() {
29         return formalTypeParameters;
30     }
31
32     @SuppressWarnings JavaDoc("unchecked")
33     public <R> CtMethod<R> getMethod(CtTypeReference<R> returnType,
34             String JavaDoc name, CtTypeReference<?>... parameterTypes) {
35         for (CtMethod mm : methods) {
36             CtMethod<R> m = (CtMethod<R>) mm;
37             if (m.getSimpleName().equals(name)) {
38                 if (!m.getType().equals(returnType))
39                     continue;
40                 boolean cont = m.getParameters().size() == parameterTypes.length;
41                 for (int i = 0; cont && i < m.getParameters().size()
42                         && i < parameterTypes.length; i++) {
43                     if (!m.getParameters().get(i).getType().getQualifiedName()
44                             .equals(parameterTypes[i].getQualifiedName())) {
45                         cont = false;
46                     }
47                 }
48                 if (cont) {
49                     return m;
50                 }
51             }
52         }
53         return null;
54     }
55
56     public CtMethod<?> getMethod(String JavaDoc name,
57             CtTypeReference<?>... parameterTypes) {
58         for (CtMethod<?> m : methods) {
59             if (m.getSimpleName().equals(name)) {
60                 boolean cont = m.getParameters().size() == parameterTypes.length;
61                 for (int i = 0; cont && i < m.getParameters().size()
62                         && i < parameterTypes.length; i++) {
63 // String s1=m.getParameters().get(i).getType().getQualifiedName();
64
// String s2=parameterTypes[i].getQualifiedName();
65
if (!m.getParameters().get(i).getType().equals(parameterTypes[i])) {
66                         cont = false;
67                     }
68                 }
69                 if (cont) {
70                     return m;
71                 }
72             }
73         }
74         return null;
75     }
76
77     public Set JavaDoc<CtMethod<?>> getMethods() {
78         return methods;
79     }
80
81     @Override JavaDoc
82     public String JavaDoc getQualifiedName() {
83         if (isTopLevel())
84             return super.getQualifiedName();
85         if (getDeclaringType() != null)
86             return getDeclaringType().getQualifiedName() + INNERTTYPE_SEPARATOR
87                     + getSimpleName();
88         else
89             return getSimpleName();
90     }
91
92     public Set JavaDoc<CtTypeReference<?>> getSuperInterfaces() {
93         return interfaces;
94     }
95
96     public void setFormalTypeParameters(
97             List JavaDoc<CtTypeReference<?>> formalTypeParameters) {
98         this.formalTypeParameters = formalTypeParameters;
99     }
100
101     public void setMethods(Set JavaDoc<CtMethod<?>> methods) {
102         this.methods = methods;
103     }
104
105     public void setSuperInterfaces(Set JavaDoc<CtTypeReference<?>> interfaces) {
106         this.interfaces = interfaces;
107     }
108
109 }
110
Popular Tags