KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > wsm > processor > apt > MirrorParameterInfo


1 package org.apache.beehive.wsm.processor.apt;
2
3 /*
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * $Header:$Factory
19  */

20
21 import java.lang.annotation.Annotation JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import com.sun.mirror.declaration.AnnotationMirror;
26 import com.sun.mirror.declaration.Modifier;
27 import com.sun.mirror.declaration.ParameterDeclaration;
28
29 import com.sun.mirror.apt.AnnotationProcessorEnvironment;
30
31 import com.sun.mirror.type.AnnotationType;
32
33 import org.apache.beehive.wsm.model.java.JavaParameterInfo;
34
35 public class MirrorParameterInfo implements JavaParameterInfo {
36     
37     protected ParameterDeclaration decl;
38     protected AnnotationProcessorEnvironment env;
39     protected Class JavaDoc clazz;
40     
41     public MirrorParameterInfo(ParameterDeclaration decl, AnnotationProcessorEnvironment env) {
42         if (null == decl) {
43             throw new IllegalArgumentException JavaDoc("parameter declaration: <null>");
44         }
45         this.decl = decl;
46         this.env = env;
47         
48         // ensure required properties
49
try {
50             clazz = TypeMirrorUtil.classForName(decl.getType());
51         }
52         catch (ClassNotFoundException JavaDoc e) {
53             logError("cannot find parameter type: " + decl.getType());
54         }
55     }
56     
57     public void logError(String JavaDoc msg) {
58         if (null != env) {
59             env.getMessager().printError(decl.getPosition(), msg);
60         }
61     }
62
63     public boolean isFinal() {
64         return decl.getModifiers().contains(Modifier.FINAL);
65     }
66
67     public String JavaDoc getName() {
68         return decl.getSimpleName();
69     }
70     
71     public Class JavaDoc getType() {
72         return clazz;
73     }
74     
75     public <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> annotationType) {
76         return decl.getAnnotation(annotationType);
77     }
78     
79     public Collection JavaDoc<Annotation JavaDoc> getAnnotations() {
80         Collection JavaDoc<Annotation JavaDoc> annotations = new ArrayList JavaDoc<Annotation JavaDoc>();
81         for (AnnotationMirror am : decl.getAnnotationMirrors()) {
82             AnnotationType at = am.getAnnotationType();
83             try {
84                 Class JavaDoc clazz = Class.forName(at.getDeclaration().getQualifiedName());
85                 Annotation JavaDoc a = decl.getAnnotation(clazz);
86                 if (null != a) {
87                     annotations.add(a);
88                 }
89             }
90             catch (ClassNotFoundException JavaDoc e) {
91             }
92         }
93         return annotations;
94     }
95 }
96
Popular Tags