1 22 package org.jboss.aop.introduction; 23 24 import javassist.CtClass; 25 import javassist.CtConstructor; 26 import javassist.CtField; 27 import javassist.CtMethod; 28 import org.jboss.aop.Advisor; 29 import org.jboss.aop.annotation.factory.duplicate.ast.ASTAnnotation; 30 import org.jboss.aop.annotation.factory.duplicate.ast.AnnotationParser; 31 import org.jboss.aop.annotation.factory.duplicate.ast.ParseException; 32 import org.jboss.aop.pointcut.AnnotationMatcher; 33 import org.jboss.aop.pointcut.ast.ASTStart; 34 import org.jboss.aop.pointcut.ast.TypeExpressionParser; 35 36 import java.io.StringReader ; 37 import java.lang.reflect.Constructor ; 38 import java.lang.reflect.Field ; 39 import java.lang.reflect.Method ; 40 41 47 public class AnnotationIntroduction 48 { 49 public static AnnotationIntroduction createMethodAnnotationIntroduction(String methodExpr, String annotationExpr, boolean invisible) 50 { 51 String expr = "method(" + methodExpr + ")"; 52 return new AnnotationIntroduction(expr, annotationExpr, invisible); 53 } 54 55 public static AnnotationIntroduction createConstructorAnnotationIntroduction(String conExpr, String annotationExpr, boolean invisible) 56 { 57 String expr = "constructor(" + conExpr + ")"; 58 return new AnnotationIntroduction(expr, annotationExpr, invisible); 59 } 60 61 public static AnnotationIntroduction createFieldAnnotationIntroduction(String fieldExpr, String annotationExpr, boolean invisible) 62 { 63 String expr = "field(" + fieldExpr + ")"; 64 return new AnnotationIntroduction(expr, annotationExpr, invisible); 65 } 66 67 public static AnnotationIntroduction createClassAnnotationIntroduction(String classExpr, String annotationExpr, boolean invisible) 68 { 69 String expr = "class(" + classExpr + ")"; 70 return new AnnotationIntroduction(expr, annotationExpr, invisible); 71 } 72 73 public static AnnotationIntroduction createComplexAnnotationIntroduction(String expr, String annotationExpr, boolean invisible) 74 { 75 return new AnnotationIntroduction(expr, annotationExpr, invisible); 76 } 77 78 79 private String originalExpression; 80 private String originalAnnotationExpr; 81 private ASTStart target; 82 private ASTAnnotation annotation; 83 private boolean invisible; 84 85 private AnnotationIntroduction(String expr, String annotationExpr, boolean invisible) 86 { 87 this.invisible = invisible; 88 originalAnnotationExpr = annotationExpr; 89 originalExpression = expr; 90 try 91 { 92 AnnotationParser parser = new AnnotationParser(new StringReader (annotationExpr)); 93 org.jboss.aop.annotation.factory.duplicate.ast.ASTStart start = parser.Start(); 94 annotation = (ASTAnnotation) start.jjtGetChild(0); 95 } 96 catch (ParseException e) 97 { 98 throw new RuntimeException (annotationExpr, e); } 100 try 101 { 102 TypeExpressionParser parser = new TypeExpressionParser(new StringReader (expr)); 103 target = parser.Start(); 104 } 105 catch (org.jboss.aop.pointcut.ast.ParseException e) 106 { 107 throw new RuntimeException (expr, e); } 109 } 110 111 public boolean matches(Advisor advisor, CtClass clazz) 112 { 113 AnnotationMatcher matcher = new AnnotationMatcher(advisor, clazz); 114 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 115 } 116 117 public boolean matches(Advisor advisor, CtMethod method) 118 { 119 AnnotationMatcher matcher = new AnnotationMatcher(advisor, method); 120 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 121 } 122 123 public boolean matches(Advisor advisor, CtConstructor con) 124 { 125 AnnotationMatcher matcher = new AnnotationMatcher(advisor, con); 126 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 127 } 128 129 public boolean matches(Advisor advisor, CtField field) 130 { 131 AnnotationMatcher matcher = new AnnotationMatcher(advisor, field); 132 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 133 } 134 135 public boolean matches(Advisor advisor, Class clazz) 136 { 137 AnnotationMatcher matcher = new AnnotationMatcher(advisor, clazz); 138 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 139 } 140 141 public boolean matches(Advisor advisor, Method method) 142 { 143 AnnotationMatcher matcher = new AnnotationMatcher(advisor, method); 144 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 145 } 146 147 public boolean matches(Advisor advisor, Constructor con) 148 { 149 AnnotationMatcher matcher = new AnnotationMatcher(advisor, con); 150 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 151 } 152 153 public boolean matches(Advisor advisor, Field field) 154 { 155 AnnotationMatcher matcher = new AnnotationMatcher(advisor, field); 156 return ((Boolean ) target.jjtAccept(matcher, null)).booleanValue(); 157 } 158 159 public String getOriginalExpression() 160 { 161 return originalExpression; 162 } 163 164 public String getOriginalAnnotationExpr() 165 { 166 return originalAnnotationExpr; 167 } 168 169 public ASTAnnotation getAnnotation() 170 { 171 return annotation; 172 } 173 174 public boolean isInvisible() 175 { 176 return invisible; 177 } 178 179 public ASTStart getTarget() 180 { 181 return target; 182 } 183 184 } 185 | Popular Tags |