001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.intercept;
005:
006: import java.util.ArrayList;
007: import java.util.HashMap;
008: import java.util.Iterator;
009: import java.util.List;
010: import java.lang.reflect.Field;
011:
012: import com.tc.aspectwerkz.joinpoint.management.JoinPointType;
013: import com.tc.aspectwerkz.reflect.impl.asm.AsmClassInfo;
014: import com.tc.aspectwerkz.reflect.impl.java.JavaClassInfo;
015: import com.tc.aspectwerkz.reflect.ClassInfo;
016: import com.tc.aspectwerkz.reflect.ReflectionInfo;
017: import com.tc.aspectwerkz.transform.TransformationConstants;
018: import com.tc.aspectwerkz.transform.inlining.AsmHelper;
019: import com.tc.aspectwerkz.transform.inlining.EmittedJoinPoint;
020: import com.tc.aspectwerkz.expression.PointcutType;
021: import com.tc.aspectwerkz.expression.ExpressionInfo;
022: import com.tc.aspectwerkz.expression.ExpressionContext;
023:
024: /**
025: * Implementation of the <code>Advisable</code> mixin.
026: *
027: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
028: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
029: */
030: public class AdvisableImpl implements Advisable {
031:
032: private static final String EXPRESSION_NAMESPACE = "___AW_ADVISABLE_AW___";
033:
034: public static final ClassInfo CLASS_INFO;
035: public static final String ADD_ADVICE_METHOD_NAME = "aw_addAdvice";
036: public static final String ADD_ADVICE_METHOD_DESC = "(Ljava/lang/String;Lcom/tc/aspectwerkz/intercept/Advice;)V";
037: public static final String REMOVE_ADVICE_METHOD_NAME = "aw_removeAdvice";
038: public static final String REMOVE_ADVICE_METHOD_DESC = "(Ljava/lang/String;Ljava/lang/Class;)V";
039: public static final AroundAdvice[] EMPTY_AROUND_ADVICE_ARRAY = new AroundAdvice[0];
040: public static final BeforeAdvice[] EMPTY_BEFORE_ADVICE_ARRAY = new BeforeAdvice[0];
041: public static final AfterAdvice[] EMPTY_AFTER_ADVICE_ARRAY = new AfterAdvice[0];
042: public static final AfterReturningAdvice[] EMPTY_AFTER_RETURNING_ADVICE_ARRAY = new AfterReturningAdvice[0];
043: public static final AfterThrowingAdvice[] EMPTY_AFTER_THROWING_ADVICE_ARRAY = new AfterThrowingAdvice[0];
044:
045: static {
046: final Class clazz = AdvisableImpl.class;
047: try {
048: CLASS_INFO = AsmClassInfo.getClassInfo(clazz.getName(),
049: clazz.getClassLoader());
050: } catch (Exception e) {
051: throw new Error("could not create class info for ["
052: + clazz.getName() + ']');
053: }
054: }
055:
056: private final Advisable m_targetInstance;
057: private final HashMap m_emittedJoinPoints;
058:
059: private final HashMap m_aroundAdvice = new HashMap();
060: private final HashMap m_beforeAdvice = new HashMap();
061: private final HashMap m_afterAdvice = new HashMap();
062: private final HashMap m_afterReturningAdvice = new HashMap();
063: private final HashMap m_afterThrowingAdvice = new HashMap();
064:
065: /**
066: * Creates a new mixin impl.
067: *
068: * @param targetInstance the target for this mixin instance (perInstance deployed)
069: */
070: public AdvisableImpl(final Object targetInstance) {
071: if (!(targetInstance instanceof Advisable)) {
072: throw new RuntimeException(
073: "advisable mixin applied to target class that does not implement the Advisable interface");
074: }
075: m_targetInstance = (Advisable) targetInstance;
076:
077: try {
078: Field f = targetInstance.getClass().getDeclaredField(
079: "aw$emittedJoinPoints");
080: f.setAccessible(true);
081: m_emittedJoinPoints = (HashMap) f.get(null);
082: } catch (Exception e) {
083: throw new RuntimeException(
084: "advisable mixin applied to target class cannot access reflective information: "
085: + e.toString());
086: }
087: }
088:
089: /**
090: * @param pointcut
091: * @param advice
092: */
093: public void aw_addAdvice(final String pointcut, final Advice advice) {
094: addAdvice(pointcut, advice);
095: }
096:
097: /**
098: * @param pointcut
099: * @param adviceClass
100: */
101: public void aw_removeAdvice(final String pointcut,
102: final Class adviceClass) {
103: removeAdvice(pointcut, adviceClass);
104: }
105:
106: /**
107: * @param joinPointIndex
108: * @return
109: */
110: public AroundAdvice[] aw$getAroundAdvice(final int joinPointHash) {
111: Object advice = m_aroundAdvice.get(new Integer(joinPointHash));
112: if (advice == null) {
113: return EMPTY_AROUND_ADVICE_ARRAY;
114: } else {
115: return (AroundAdvice[]) advice;
116: }
117: }
118:
119: /**
120: * @param joinPointIndex
121: * @return
122: */
123: public BeforeAdvice[] aw$getBeforeAdvice(final int joinPointHash) {
124: Object advice = m_beforeAdvice.get(new Integer(joinPointHash));
125: if (advice == null) {
126: return EMPTY_BEFORE_ADVICE_ARRAY;
127: } else {
128: return (BeforeAdvice[]) advice;
129: }
130: }
131:
132: /**
133: * @param joinPointIndex
134: * @return
135: */
136: public AfterAdvice[] aw$getAfterAdvice(final int joinPointHash) {
137: Object advice = m_afterAdvice.get(new Integer(joinPointHash));
138: if (advice == null) {
139: return EMPTY_AFTER_ADVICE_ARRAY;
140: } else {
141: return (AfterAdvice[]) advice;
142: }
143: }
144:
145: /**
146: * @param joinPointHash
147: * @return
148: */
149: public AfterReturningAdvice[] aw$getAfterReturningAdvice(
150: final int joinPointHash) {
151: Object advice = m_afterReturningAdvice.get(new Integer(
152: joinPointHash));
153: if (advice == null) {
154: return EMPTY_AFTER_RETURNING_ADVICE_ARRAY;
155: } else {
156: return (AfterReturningAdvice[]) advice;
157: }
158: }
159:
160: /**
161: * @param joinPointIndex
162: * @return
163: */
164: public AfterThrowingAdvice[] aw$getAfterThrowingAdvice(
165: final int joinPointIndex) {
166: Object advice = m_afterThrowingAdvice.get(new Integer(
167: joinPointIndex));
168: if (advice == null) {
169: return EMPTY_AFTER_THROWING_ADVICE_ARRAY;
170: } else {
171: return (AfterThrowingAdvice[]) advice;
172: }
173: }
174:
175: /**
176: * @param pointcut
177: * @param advice
178: */
179: private void addAdvice(final String pointcut, final Advice advice) {
180: ExpressionInfo expressionInfo = new ExpressionInfo(pointcut,
181: EXPRESSION_NAMESPACE);
182: // Object[] emittedJoinPoints = m_emittedJoinPoints.getValues();
183: // for (int i = 0; i < emittedJoinPoints.length; i++) {
184: // EmittedJoinPoint emittedJoinPoint = (EmittedJoinPoint) emittedJoinPoints[i];
185: for (Iterator it = m_emittedJoinPoints.values().iterator(); it
186: .hasNext();) {
187: EmittedJoinPoint emittedJoinPoint = (EmittedJoinPoint) it
188: .next();
189: if (match(expressionInfo, PointcutType.EXECUTION,
190: emittedJoinPoint)
191: || match(expressionInfo, PointcutType.CALL,
192: emittedJoinPoint)
193: || match(expressionInfo, PointcutType.HANDLER,
194: emittedJoinPoint)
195: || match(expressionInfo, PointcutType.GET,
196: emittedJoinPoint)
197: || match(expressionInfo, PointcutType.SET,
198: emittedJoinPoint)
199: //note: STATIC INIT is useless since the class is already loaded to manipulate the instance
200: ) {
201: int hash = emittedJoinPoint.getJoinPointClassName()
202: .hashCode();
203: addAroundAdvice(advice, hash);
204: addBeforeAdvice(advice, hash);
205: addAfterAdvice(advice, hash);
206: addAfterReturningAdvice(advice, hash);
207: addAfterThrowingAdvice(advice, hash);
208: }
209: }
210: }
211:
212: /**
213: * @param pointcut
214: * @param adviceClass
215: */
216: private void removeAdvice(final String pointcut,
217: final Class adviceClass) {
218: ExpressionInfo expressionInfo = new ExpressionInfo(pointcut,
219: EXPRESSION_NAMESPACE);
220: // Object[] emittedJoinPoints = m_emittedJoinPoints.getValues();
221: // for (int i = 0; i < emittedJoinPoints.length; i++) {
222: // EmittedJoinPoint emittedJoinPoint = (EmittedJoinPoint) emittedJoinPoints[i];
223: for (Iterator it = m_emittedJoinPoints.values().iterator(); it
224: .hasNext();) {
225: EmittedJoinPoint emittedJoinPoint = (EmittedJoinPoint) it
226: .next();
227: if (match(expressionInfo, PointcutType.EXECUTION,
228: emittedJoinPoint)
229: || match(expressionInfo, PointcutType.CALL,
230: emittedJoinPoint)
231: || match(expressionInfo, PointcutType.HANDLER,
232: emittedJoinPoint)
233: || match(expressionInfo, PointcutType.GET,
234: emittedJoinPoint)
235: || match(expressionInfo, PointcutType.SET,
236: emittedJoinPoint)
237: //note: STATIC INIT is useless since the class is already loaded to manipulate the instance
238: ) {
239: int hash = emittedJoinPoint.getJoinPointClassName()
240: .hashCode();
241: removeAroundAdvice(adviceClass, hash);
242: removeBeforeAdvice(adviceClass, hash);
243: removeAfterAdvice(adviceClass, hash);
244: removeAfterReturningAdvice(adviceClass, hash);
245: removeAfterThrowingAdvice(adviceClass, hash);
246: }
247: }
248: }
249:
250: /**
251: * @param advice
252: * @param joinPointHash
253: */
254: private void addAroundAdvice(final Advice advice, int joinPointHash) {
255: if (advice instanceof AroundAdvice) {
256: AroundAdvice aroundAdvice = (AroundAdvice) advice;
257: AroundAdvice[] advices;
258: AroundAdvice[] olds = aw$getAroundAdvice(joinPointHash);
259: if (olds != null) {
260: advices = new AroundAdvice[olds.length + 1];
261: System.arraycopy(olds, 0, advices, 0, olds.length);
262: advices[advices.length - 1] = aroundAdvice;
263: } else {
264: advices = new AroundAdvice[] { aroundAdvice };
265: }
266: m_aroundAdvice.put(new Integer(joinPointHash), advices);
267: }
268: }
269:
270: /**
271: * @param advice
272: * @param joinPointHash
273: */
274: private void addBeforeAdvice(final Advice advice, int joinPointHash) {
275: if (advice instanceof BeforeAdvice) {
276: BeforeAdvice beforeAdvice = (BeforeAdvice) advice;
277: BeforeAdvice[] advices;
278: BeforeAdvice[] olds = aw$getBeforeAdvice(joinPointHash);
279: if (olds != null) {
280: advices = new BeforeAdvice[olds.length + 1];
281: System.arraycopy(olds, 0, advices, 0, olds.length);
282: advices[advices.length - 1] = beforeAdvice;
283: } else {
284: advices = new BeforeAdvice[] { beforeAdvice };
285: }
286: m_beforeAdvice.put(new Integer(joinPointHash), advices);
287: }
288: }
289:
290: /**
291: * @param advice
292: * @param joinPointHash
293: */
294: private void addAfterAdvice(final Advice advice, int joinPointHash) {
295: if (advice instanceof AfterAdvice) {
296: AfterAdvice afterFinallyAdvice = (AfterAdvice) advice;
297: AfterAdvice[] advices;
298: AfterAdvice[] olds = aw$getAfterAdvice(joinPointHash);
299: if (olds != null) {
300: advices = new AfterAdvice[olds.length + 1];
301: System.arraycopy(olds, 0, advices, 0, olds.length);
302: advices[advices.length - 1] = afterFinallyAdvice;
303: } else {
304: advices = new AfterAdvice[] { afterFinallyAdvice };
305: }
306: m_afterAdvice.put(new Integer(joinPointHash), advices);
307: }
308: }
309:
310: /**
311: * @param advice
312: * @param joinPointHash
313: */
314: private void addAfterReturningAdvice(final Advice advice,
315: int joinPointHash) {
316: if (advice instanceof AfterReturningAdvice) {
317: AfterReturningAdvice afterReturningAdvice = (AfterReturningAdvice) advice;
318: AfterReturningAdvice[] advices;
319: AfterReturningAdvice[] olds = aw$getAfterReturningAdvice(joinPointHash);
320: if (olds != null) {
321: advices = new AfterReturningAdvice[olds.length + 1];
322: System.arraycopy(olds, 0, advices, 0, olds.length);
323: advices[advices.length - 1] = afterReturningAdvice;
324: } else {
325: advices = new AfterReturningAdvice[] { afterReturningAdvice };
326: }
327: m_afterReturningAdvice.put(new Integer(joinPointHash),
328: advices);
329: }
330: }
331:
332: /**
333: * @param advice
334: * @param joinPointHash
335: */
336: private void addAfterThrowingAdvice(final Advice advice,
337: int joinPointHash) {
338: if (advice instanceof AfterThrowingAdvice) {
339: AfterThrowingAdvice afterThrowingAdvice = (AfterThrowingAdvice) advice;
340: AfterThrowingAdvice[] advices;
341: AfterThrowingAdvice[] olds = aw$getAfterThrowingAdvice(joinPointHash);
342: if (olds != null) {
343: advices = new AfterThrowingAdvice[olds.length + 1];
344: System.arraycopy(olds, 0, advices, 0, olds.length);
345: advices[advices.length - 1] = afterThrowingAdvice;
346: } else {
347: advices = new AfterThrowingAdvice[] { afterThrowingAdvice };
348: }
349: m_afterThrowingAdvice.put(new Integer(joinPointHash),
350: advices);
351: }
352: }
353:
354: /**
355: * @param adviceClass
356: * @param joinPointHash
357: */
358: private void removeAroundAdvice(final Class adviceClass,
359: int joinPointHash) {
360: if (isAroundAdvice(adviceClass)) {
361: AroundAdvice[] oldArray = aw$getAroundAdvice(joinPointHash);
362: if (oldArray.length == 0) {
363: //
364: } else if (oldArray.length == 1) {
365: m_aroundAdvice.put(new Integer(joinPointHash),
366: EMPTY_AROUND_ADVICE_ARRAY);
367: } else {
368: List newArrayList = new ArrayList();
369: for (int i = 0; i < oldArray.length; i++) {
370: AroundAdvice aroundAdvice = oldArray[i];
371: if (!aroundAdvice.getClass().equals(adviceClass)) {
372: newArrayList.add(aroundAdvice);
373: }
374: }
375: m_aroundAdvice.put(new Integer(joinPointHash),
376: newArrayList
377: .toArray(new AroundAdvice[newArrayList
378: .size()]));
379: }
380: }
381: }
382:
383: /**
384: * @param adviceClass
385: * @param joinPointHash
386: */
387: private void removeBeforeAdvice(final Class adviceClass,
388: int joinPointHash) {
389: if (isBeforeAdvice(adviceClass)) {
390: BeforeAdvice[] oldArray = aw$getBeforeAdvice(joinPointHash);
391: if (oldArray.length == 0) {
392: //
393: } else if (oldArray.length == 1) {
394: m_beforeAdvice.put(new Integer(joinPointHash),
395: EMPTY_BEFORE_ADVICE_ARRAY);
396: } else {
397: List newArrayList = new ArrayList();
398: for (int i = 0; i < oldArray.length; i++) {
399: BeforeAdvice beforeAdvice = oldArray[i];
400: if (!beforeAdvice.getClass().equals(adviceClass)) {
401: newArrayList.add(beforeAdvice);
402: }
403: }
404: m_beforeAdvice.put(new Integer(joinPointHash),
405: newArrayList
406: .toArray(new BeforeAdvice[newArrayList
407: .size()]));
408: }
409: }
410: }
411:
412: /**
413: * @param adviceClass
414: * @param joinPointHash
415: */
416: private void removeAfterAdvice(final Class adviceClass,
417: int joinPointHash) {
418: if (isAfterAdvice(adviceClass)) {
419: AfterAdvice[] oldArray = aw$getAfterAdvice(joinPointHash);
420: if (oldArray.length == 0) {
421: //
422: } else if (oldArray.length == 1) {
423: m_afterAdvice.put(new Integer(joinPointHash),
424: EMPTY_AFTER_ADVICE_ARRAY);
425: } else {
426: List newArrayList = new ArrayList();
427: for (int i = 0; i < oldArray.length; i++) {
428: AfterAdvice afterAdvice = oldArray[i];
429: if (!afterAdvice.getClass().equals(adviceClass)) {
430: newArrayList.add(afterAdvice);
431: }
432: }
433: m_afterAdvice.put(new Integer(joinPointHash),
434: newArrayList
435: .toArray(new AfterAdvice[newArrayList
436: .size()]));
437: }
438: }
439: }
440:
441: /**
442: * @param adviceClass
443: * @param joinPointHash
444: */
445: private void removeAfterReturningAdvice(final Class adviceClass,
446: int joinPointHash) {
447: if (isAfterReturningAdvice(adviceClass)) {
448: AfterReturningAdvice[] oldArray = aw$getAfterReturningAdvice(joinPointHash);
449: if (oldArray.length == 0) {
450: //
451: } else if (oldArray.length == 1) {
452: m_afterReturningAdvice.put(new Integer(joinPointHash),
453: EMPTY_AFTER_RETURNING_ADVICE_ARRAY);
454: } else {
455: List newArrayList = new ArrayList();
456: for (int i = 0; i < oldArray.length; i++) {
457: AfterReturningAdvice afterReturningAdvice = oldArray[i];
458: if (!afterReturningAdvice.getClass().equals(
459: adviceClass)) {
460: newArrayList.add(afterReturningAdvice);
461: }
462: }
463: m_afterReturningAdvice
464: .put(
465: new Integer(joinPointHash),
466: newArrayList
467: .toArray(new AfterReturningAdvice[newArrayList
468: .size()]));
469: }
470: }
471: }
472:
473: /**
474: * @param adviceClass
475: * @param joinPointHash
476: */
477: private void removeAfterThrowingAdvice(final Class adviceClass,
478: int joinPointHash) {
479: if (isAfterThrowingAdvice(adviceClass)) {
480: AfterThrowingAdvice[] oldArray = aw$getAfterThrowingAdvice(joinPointHash);
481: if (oldArray.length == 0) {
482: //
483: } else if (oldArray.length == 1) {
484: m_afterThrowingAdvice.put(new Integer(joinPointHash),
485: EMPTY_AFTER_THROWING_ADVICE_ARRAY);
486: } else {
487: List newArrayList = new ArrayList();
488: for (int i = 0; i < oldArray.length; i++) {
489: AfterThrowingAdvice advice = oldArray[i];
490: if (!advice.getClass().equals(adviceClass)) {
491: newArrayList.add(advice);
492: }
493: }
494: m_afterThrowingAdvice
495: .put(
496: new Integer(joinPointHash),
497: newArrayList
498: .toArray(new AfterThrowingAdvice[newArrayList
499: .size()]));
500: }
501: }
502: }
503:
504: private boolean isAroundAdvice(final Class adviceClass) {
505: if (adviceClass == AroundAdvice.class) {
506: return true;
507: }
508: Class[] interfaces = adviceClass.getInterfaces();
509: for (int i = 0; i < interfaces.length; i++) {
510: Class anInterface = interfaces[i];
511: if (anInterface == AroundAdvice.class) {
512: return true;
513: }
514: }
515: return false;
516: }
517:
518: private boolean isBeforeAdvice(final Class adviceClass) {
519: if (adviceClass == BeforeAdvice.class) {
520: return true;
521: }
522: Class[] interfaces = adviceClass.getInterfaces();
523: for (int i = 0; i < interfaces.length; i++) {
524: Class anInterface = interfaces[i];
525: if (anInterface == BeforeAdvice.class) {
526: return true;
527: }
528: }
529: return false;
530: }
531:
532: private boolean isAfterAdvice(final Class adviceClass) {
533: if (adviceClass == AfterAdvice.class) {
534: return true;
535: }
536: Class[] interfaces = adviceClass.getInterfaces();
537: for (int i = 0; i < interfaces.length; i++) {
538: Class anInterface = interfaces[i];
539: if (anInterface == AfterAdvice.class) {
540: return true;
541: }
542: }
543: return false;
544: }
545:
546: private boolean isAfterReturningAdvice(final Class adviceClass) {
547: if (adviceClass == AfterReturningAdvice.class) {
548: return true;
549: }
550: Class[] interfaces = adviceClass.getInterfaces();
551: for (int i = 0; i < interfaces.length; i++) {
552: Class anInterface = interfaces[i];
553: if (anInterface == AfterReturningAdvice.class) {
554: return true;
555: }
556: }
557: return false;
558: }
559:
560: private boolean isAfterThrowingAdvice(final Class adviceClass) {
561: if (adviceClass == AfterThrowingAdvice.class) {
562: return true;
563: }
564: Class[] interfaces = adviceClass.getInterfaces();
565: for (int i = 0; i < interfaces.length; i++) {
566: Class anInterface = interfaces[i];
567: if (anInterface == AfterThrowingAdvice.class) {
568: return true;
569: }
570: }
571: return false;
572: }
573:
574: /**
575: * Match the given expression for the given pointcut type against the given emittedJoinPoint
576: *
577: * @param expression
578: * @param pointcutType
579: * @param emittedJoinPoint
580: * @return
581: */
582: private boolean match(ExpressionInfo expression,
583: PointcutType pointcutType, EmittedJoinPoint emittedJoinPoint) {
584: ClassInfo callerClassInfo = JavaClassInfo
585: .getClassInfo(m_targetInstance.getClass());
586: ClassInfo calleeClassInfo = AsmClassInfo.getClassInfo(
587: emittedJoinPoint.getCalleeClassName(), m_targetInstance
588: .getClass().getClassLoader());
589:
590: // early match
591: if (!expression.getAdvisedClassFilterExpression().match(
592: new ExpressionContext(pointcutType, calleeClassInfo,
593: callerClassInfo))) {
594: return false;
595: }
596:
597: // create the callee info
598: final ReflectionInfo reflectionInfo;
599: final PointcutType joinPointType;
600: switch (emittedJoinPoint.getJoinPointType()) {
601: case JoinPointType.STATIC_INITIALIZATION_INT:
602: reflectionInfo = calleeClassInfo.staticInitializer();
603: joinPointType = PointcutType.STATIC_INITIALIZATION;
604: break;
605: case JoinPointType.METHOD_EXECUTION_INT:
606: reflectionInfo = calleeClassInfo.getMethod(emittedJoinPoint
607: .getJoinPointHash());
608: joinPointType = PointcutType.EXECUTION;
609: break;
610: case JoinPointType.METHOD_CALL_INT:
611: reflectionInfo = calleeClassInfo.getMethod(emittedJoinPoint
612: .getJoinPointHash());
613: joinPointType = PointcutType.CALL;
614: break;
615: case JoinPointType.FIELD_GET_INT:
616: reflectionInfo = calleeClassInfo.getField(emittedJoinPoint
617: .getJoinPointHash());
618: joinPointType = PointcutType.GET;
619: break;
620: case JoinPointType.FIELD_SET_INT:
621: reflectionInfo = calleeClassInfo.getField(emittedJoinPoint
622: .getJoinPointHash());
623: joinPointType = PointcutType.SET;
624: break;
625: case JoinPointType.CONSTRUCTOR_EXECUTION_INT:
626: reflectionInfo = calleeClassInfo
627: .getConstructor(emittedJoinPoint.getJoinPointHash());
628: joinPointType = PointcutType.EXECUTION;
629: break;
630: case JoinPointType.CONSTRUCTOR_CALL_INT:
631: reflectionInfo = calleeClassInfo
632: .getConstructor(emittedJoinPoint.getJoinPointHash());
633: joinPointType = PointcutType.CALL;
634: break;
635: case JoinPointType.HANDLER_INT:
636: reflectionInfo = calleeClassInfo;
637: joinPointType = PointcutType.HANDLER;
638: break;
639: default:
640: throw new RuntimeException("Joinpoint type not supported: "
641: + emittedJoinPoint.getJoinPointType());
642: }
643:
644: // create the caller info
645: final ReflectionInfo withinInfo;
646: if (TransformationConstants.CLINIT_METHOD_NAME
647: .equals(emittedJoinPoint.getCallerMethodName())) {
648: withinInfo = callerClassInfo.staticInitializer();
649: } else if (TransformationConstants.INIT_METHOD_NAME
650: .equals(emittedJoinPoint.getCallerMethodName())) {
651: withinInfo = callerClassInfo.getConstructor(AsmHelper
652: .calculateConstructorHash(emittedJoinPoint
653: .getCallerMethodDesc()));
654: } else {
655: withinInfo = callerClassInfo.getMethod(AsmHelper
656: .calculateMethodHash(emittedJoinPoint
657: .getCallerMethodName(), emittedJoinPoint
658: .getCallerMethodDesc()));
659: }
660:
661: // check pointcutType vs joinPointType
662: if (pointcutType != PointcutType.WITHIN
663: && pointcutType != joinPointType) {
664: return false;
665: }
666:
667: return expression.getExpression().match(
668: new ExpressionContext(pointcutType, reflectionInfo,
669: withinInfo));
670: }
671: }
|