KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > support > reflect > reference > CtParameterReferenceImpl


1 package spoon.support.reflect.reference;
2
3 import java.util.List JavaDoc;
4
5 import spoon.reflect.declaration.CtExecutable;
6 import spoon.reflect.declaration.CtParameter;
7 import spoon.reflect.reference.CtExecutableReference;
8 import spoon.reflect.reference.CtParameterReference;
9 import spoon.reflect.visitor.CtVisitor;
10
11 public class CtParameterReferenceImpl<T> extends CtVariableReferenceImpl<T>
12         implements CtParameterReference<T> {
13     private static final long serialVersionUID = 1L;
14
15     CtExecutableReference<?> executable;
16
17     public CtParameterReferenceImpl() {
18         super();
19     }
20
21     @SuppressWarnings JavaDoc("unchecked")
22     public CtParameter<T> getDeclaration() {
23         CtExecutable exec = executable.getDeclaration();
24         if (exec == null)
25             return null;
26         List JavaDoc<CtParameter<?>> params = exec.getParameters();
27         for (CtParameter<?> p : params) {
28             if (this.getSimpleName().equals(p.getSimpleName())) {
29                 return (CtParameter<T>) p;
30             }
31         }
32         throw new IllegalStateException JavaDoc(
33                 "Could not found declaration for parameter " + getSimpleName());
34     }
35
36     public CtExecutableReference<?> getDeclaringExecutable() {
37         return executable;
38     }
39
40     public void setDeclaringExecutable(CtExecutableReference<?> executable) {
41         this.executable = executable;
42     }
43
44     public void accept(CtVisitor visitor) {
45         visitor.visitCtParameterReference(this);
46     }
47
48 }
49
Popular Tags