1 package spoon.support.reflect.reference; 2 3 import java.io.Serializable ; 4 import java.lang.annotation.Annotation ; 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 { 13 14 String 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 current = pr.getSignature(); 26 pr.reset(); 27 pr.scan(o); 28 return current.compareTo(pr.getSignature()); 29 } 30 31 @Override 32 public int hashCode() { 33 return toString().hashCode(); 34 } 35 36 @Override 37 public boolean equals(Object object) { 38 if (object instanceof CtReference) 39 return compareTo((CtReference) object) == 0; 40 return false; 41 } 42 43 public <A extends Annotation > A getAnnotation(Class <A> annotationType) { 44 CtElement e = getDeclaration(); 45 if (e != null) { 46 return e.getAnnotation(annotationType); 47 } 48 return null; 49 } 50 51 public Annotation [] getAnnotations() { 52 CtElement e = getDeclaration(); 53 if (e != null) { 54 Annotation [] annotations = new Annotation [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 getSimpleName() { 65 return simplename; 66 } 67 68 public void setSimpleName(String simplename) { 69 if (simplename.contains("?")) 70 throw new RuntimeException ("argl"); 71 this.simplename = simplename; 72 } 73 74 @Override 75 public String 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 |