001: /*
002: * Spoon - http://spoon.gforge.inria.fr/
003: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004: *
005: * This software is governed by the CeCILL-C License under French law and
006: * abiding by the rules of distribution of free software. You can use, modify
007: * and/or redistribute the software under the terms of the CeCILL-C license as
008: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013: *
014: * The fact that you are presently reading this means that you have had
015: * knowledge of the CeCILL-C license and that you accept its terms.
016: */
017:
018: package spoon.support.reflect.reference;
019:
020: import java.io.Serializable;
021: import java.lang.annotation.Annotation;
022:
023: import spoon.reflect.Factory;
024: import spoon.reflect.declaration.CtAnnotation;
025: import spoon.reflect.declaration.CtElement;
026: import spoon.reflect.reference.CtReference;
027: import spoon.support.visitor.SignaturePrinter;
028:
029: public abstract class CtReferenceImpl implements CtReference,
030: Serializable {
031:
032: String simplename;
033:
034: transient Factory factory;
035:
036: public CtReferenceImpl() {
037: super ();
038: }
039:
040: public int compareTo(CtReference o) {
041: SignaturePrinter pr = new SignaturePrinter();
042: pr.scan(this );
043: String current = pr.getSignature();
044: pr.reset();
045: pr.scan(o);
046: return current.compareTo(pr.getSignature());
047: }
048:
049: @Override
050: public int hashCode() {
051: return toString().hashCode();
052: }
053:
054: @Override
055: public boolean equals(Object object) {
056: if (object instanceof CtReference)
057: return compareTo((CtReference) object) == 0;
058: return false;
059: }
060:
061: public <A extends Annotation> A getAnnotation(
062: Class<A> annotationType) {
063: CtElement e = getDeclaration();
064: if (e != null) {
065: return e.getAnnotation(annotationType);
066: }
067: return null;
068: }
069:
070: public Annotation[] getAnnotations() {
071: CtElement e = getDeclaration();
072: if (e != null) {
073: Annotation[] annotations = new Annotation[e
074: .getAnnotations().size()];
075: int i = 0;
076: for (CtAnnotation<?> a : e.getAnnotations()) {
077: annotations[i++] = a.getActualAnnotation();
078: }
079: return annotations;
080: }
081: return null;
082: }
083:
084: public String getSimpleName() {
085: return simplename;
086: }
087:
088: public void setSimpleName(String simplename) {
089: if (simplename.contains("?"))
090: throw new RuntimeException("argl");
091: this .simplename = simplename;
092: }
093:
094: @Override
095: public String toString() {
096: SignaturePrinter pr = new SignaturePrinter();
097: pr.scan(this );
098: return pr.getSignature();
099: }
100:
101: public Factory getFactory() {
102: return factory;
103: }
104:
105: public void setFactory(Factory factory) {
106: this.factory = factory;
107: }
108:
109: }
|