1 package org.apache.beehive.wsm.processor.apt; 2 3 20 21 import java.lang.annotation.Annotation ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 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 clazz; 40 41 public MirrorParameterInfo(ParameterDeclaration decl, AnnotationProcessorEnvironment env) { 42 if (null == decl) { 43 throw new IllegalArgumentException ("parameter declaration: <null>"); 44 } 45 this.decl = decl; 46 this.env = env; 47 48 try { 50 clazz = TypeMirrorUtil.classForName(decl.getType()); 51 } 52 catch (ClassNotFoundException e) { 53 logError("cannot find parameter type: " + decl.getType()); 54 } 55 } 56 57 public void logError(String 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 getName() { 68 return decl.getSimpleName(); 69 } 70 71 public Class getType() { 72 return clazz; 73 } 74 75 public <A extends Annotation > A getAnnotation(Class <A> annotationType) { 76 return decl.getAnnotation(annotationType); 77 } 78 79 public Collection <Annotation > getAnnotations() { 80 Collection <Annotation > annotations = new ArrayList <Annotation >(); 81 for (AnnotationMirror am : decl.getAnnotationMirrors()) { 82 AnnotationType at = am.getAnnotationType(); 83 try { 84 Class clazz = Class.forName(at.getDeclaration().getQualifiedName()); 85 Annotation a = decl.getAnnotation(clazz); 86 if (null != a) { 87 annotations.add(a); 88 } 89 } 90 catch (ClassNotFoundException e) { 91 } 92 } 93 return annotations; 94 } 95 } 96 | Popular Tags |