1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*******************************************************************************
- * Copyright (c) Jonas Bonér, Alexandre Vasseur
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *******************************************************************************/
- package ataspectj;
-
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.aspectj.lang.annotation.Pointcut;
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.aspectj.lang.annotation.Before;
- import org.aspectj.lang.annotation.Pointcut;
- import org.aspectj.lang.JoinPoint;
- import org.aspectj.runtime.internal.CFlowCounter;
- import junit.framework.TestCase;
-
- /**
- * Test pointcut reference without binding
- *
- * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
- */
- public class PointcutReferenceTest extends TestCase {
-
- static StringBuffer s_log = new StringBuffer();
- static void log(String s) {
- s_log.append(s).append(" ");
- }
-
- public static void main(String[] args) {
- TestHelper.runAndThrowOnFailure(suite());
- }
-
- public static junit.framework.Test suite() {
- return new junit.framework.TestSuite(PointcutReferenceTest.class);
- }
-
- public void hello() {
- log("hello");
- }
-
- public void helloWithRef() {
- log("helloWithRef");
- }
-
- public void testPointcutReferenceNoBinding() {
- PointcutReferenceTest me = new PointcutReferenceTest();
- s_log = new StringBuffer();
- me.hello();
- assertEquals("before hello ", s_log.toString());
- }
-
- public void testPointcutReferenceBinding() {
- PointcutReferenceTest me = new PointcutReferenceTest();
- s_log = new StringBuffer();
- me.helloWithRef();
- assertEquals("beforeWithRef helloWithRef ", s_log.toString());
- }
-
-
- @Aspect
- public static class TestAspect {
-
- // order of pointcut in source code does not matter for pc refs
- @Pointcut("execution(* ataspectj.PointcutReferenceTest.hello(..))")
- void pcRef() {}
-
- @Pointcut("pcRef()")
- void pcRef2() {}
-
- @Before("pcRef2()")
- public void before(JoinPoint jp) {
- log("before");
- }
-
-
- // see here outer aspect reference
- @Pointcut("execution(* ataspectj.PointcutReferenceTest.helloWithRef(..))" +
- " && ataspectj.PointcutReferenceTest.RefAspect.pcRefObjectBinding(t)")
- void pcRefBinding(Object t) {}
-
- @Before("pcRefBinding(ttt)")
- public void before(Object ttt, JoinPoint jp) {
- log("beforeWithRef");
- }
- }
-
- @Aspect
- public static class RefAspect {
- @Pointcut("this(obj)")
- public void pcRefObjectBinding(PointcutReferenceTest obj) {}
-
- }
-
- }
|