1 12 package org.aspectj.internal.lang.reflect; 13 14 import java.lang.annotation.Annotation ; 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 25 public class DeclareAnnotationImpl implements DeclareAnnotation { 26 27 private Annotation theAnnotation; 28 private String 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 kindString, String pattern, Annotation ann, String 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 ("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 53 public AjType<?> getDeclaringType() { 54 return this.declaringType; 55 } 56 57 60 public Kind getKind() { 61 return this.kind; 62 } 63 64 67 public SignaturePattern getSignaturePattern() { 68 return this.signaturePattern; 69 } 70 71 74 public TypePattern getTypePattern() { 75 return this.typePattern; 76 } 77 78 81 public Annotation getAnnotation() { 82 return this.theAnnotation; 83 } 84 85 public String getAnnotationAsText() { 86 return this.annText; 87 } 88 89 public String toString() { 90 StringBuffer sb = new StringBuffer (); 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 |