KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > internal > lang > reflect > DeclareAnnotationImpl


1 /* *******************************************************************
2  * Copyright (c) 2005 Contributors.
3  * All rights reserved.
4  * This program and the accompanying materials are made available
5  * under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution and is available at
7  * http://eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Adrian Colyer Initial implementation
11  * ******************************************************************/

12 package org.aspectj.internal.lang.reflect;
13
14 import java.lang.annotation.Annotation JavaDoc;
15
16 import org.aspectj.lang.reflect.AjType;
17 import org.aspectj.lang.reflect.DeclareAnnotation;
18 import org.aspectj.lang.reflect.SignaturePattern;
19 import org.aspectj.lang.reflect.TypePattern;
20
21 /**
22  * @author colyer
23  *
24  */

25 public class DeclareAnnotationImpl implements DeclareAnnotation {
26
27     private Annotation JavaDoc theAnnotation;
28     private String JavaDoc annText;
29     private AjType<?> declaringType;
30     private DeclareAnnotation.Kind kind;
31     private TypePattern typePattern;
32     private SignaturePattern signaturePattern;
33     
34     public DeclareAnnotationImpl(AjType<?> declaring, String JavaDoc kindString, String JavaDoc pattern, Annotation JavaDoc ann, String JavaDoc annText) {
35         this.declaringType = declaring;
36         if (kindString.equals("at_type")) this.kind = DeclareAnnotation.Kind.Type;
37         else if (kindString.equals("at_field")) this.kind = DeclareAnnotation.Kind.Field;
38         else if (kindString.equals("at_method")) this.kind = DeclareAnnotation.Kind.Method;
39         else if (kindString.equals("at_constructor")) this.kind = DeclareAnnotation.Kind.Constructor;
40         else throw new IllegalStateException JavaDoc("Unknown declare annotation kind: " + kindString);
41         if (kind == DeclareAnnotation.Kind.Type) {
42             this.typePattern = new TypePatternImpl(pattern);
43         } else {
44             this.signaturePattern = new SignaturePatternImpl(pattern);
45         }
46         this.theAnnotation = ann;
47         this.annText = annText;
48     }
49
50     /* (non-Javadoc)
51      * @see org.aspectj.lang.reflect.DeclareAnnotation#getDeclaringType()
52      */

53     public AjType<?> getDeclaringType() {
54         return this.declaringType;
55     }
56
57     /* (non-Javadoc)
58      * @see org.aspectj.lang.reflect.DeclareAnnotation#getKind()
59      */

60     public Kind getKind() {
61         return this.kind;
62     }
63
64     /* (non-Javadoc)
65      * @see org.aspectj.lang.reflect.DeclareAnnotation#getSignaturePattern()
66      */

67     public SignaturePattern getSignaturePattern() {
68         return this.signaturePattern;
69     }
70
71     /* (non-Javadoc)
72      * @see org.aspectj.lang.reflect.DeclareAnnotation#getTypePattern()
73      */

74     public TypePattern getTypePattern() {
75         return this.typePattern;
76     }
77
78     /* (non-Javadoc)
79      * @see org.aspectj.lang.reflect.DeclareAnnotation#getAnnotation()
80      */

81     public Annotation JavaDoc getAnnotation() {
82         return this.theAnnotation;
83     }
84     
85     public String JavaDoc getAnnotationAsText() {
86         return this.annText;
87     }
88     
89     public String JavaDoc toString() {
90         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
91         sb.append("declare @");
92         switch(getKind()) {
93         case Type:
94             sb.append("type : ");
95             sb.append(getTypePattern().asString());
96             break;
97         case Method:
98             sb.append("method : ");
99             sb.append(getSignaturePattern().asString());
100             break;
101         case Field:
102             sb.append("field : ");
103             sb.append(getSignaturePattern().asString());
104             break;
105         case Constructor:
106             sb.append("constructor : ");
107             sb.append(getSignaturePattern().asString());
108             break;
109         }
110         sb.append(" : ");
111         sb.append(getAnnotationAsText());
112         return sb.toString();
113     }
114
115 }
116
Popular Tags