KickJava   Java API By Example, From Geeks To Geeks.

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


1 package spoon.support.reflect.reference;
2
3 import java.io.Serializable JavaDoc;
4 import java.lang.annotation.Annotation JavaDoc;
5
6 import spoon.reflect.Factory;
7 import spoon.reflect.declaration.CtAnnotation;
8 import spoon.reflect.declaration.CtElement;
9 import spoon.reflect.reference.CtReference;
10 import spoon.support.visitor.SignaturePrinter;
11
12 public abstract class CtReferenceImpl implements CtReference, Serializable JavaDoc {
13
14     String JavaDoc simplename;
15
16     transient Factory factory;
17
18     public CtReferenceImpl() {
19         super();
20     }
21
22     public int compareTo(CtReference o) {
23         SignaturePrinter pr = new SignaturePrinter();
24         pr.scan(this);
25         String JavaDoc current = pr.getSignature();
26         pr.reset();
27         pr.scan(o);
28         return current.compareTo(pr.getSignature());
29     }
30
31     @Override JavaDoc
32     public int hashCode() {
33         return toString().hashCode();
34     }
35
36     @Override JavaDoc
37     public boolean equals(Object JavaDoc object) {
38         if (object instanceof CtReference)
39             return compareTo((CtReference) object) == 0;
40         return false;
41     }
42
43     public <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> annotationType) {
44         CtElement e = getDeclaration();
45         if (e != null) {
46             return e.getAnnotation(annotationType);
47         }
48         return null;
49     }
50
51     public Annotation JavaDoc[] getAnnotations() {
52         CtElement e = getDeclaration();
53         if (e != null) {
54             Annotation JavaDoc[] annotations = new Annotation JavaDoc[e.getAnnotations().size()];
55             int i = 0;
56             for (CtAnnotation<?> a : e.getAnnotations()) {
57                 annotations[i++] = a.getActualAnnotation();
58             }
59             return annotations;
60         }
61         return null;
62     }
63
64     public String JavaDoc getSimpleName() {
65         return simplename;
66     }
67
68     public void setSimpleName(String JavaDoc simplename) {
69         if (simplename.contains("?"))
70             throw new RuntimeException JavaDoc("argl");
71         this.simplename = simplename;
72     }
73
74     @Override JavaDoc
75     public String JavaDoc toString() {
76         SignaturePrinter pr = new SignaturePrinter();
77         pr.scan(this);
78         return pr.getSignature();
79     }
80
81     public Factory getFactory() {
82         return factory;
83     }
84
85     public void setFactory(Factory factory) {
86         this.factory = factory;
87     }
88
89 }
90
Popular Tags