From 9961155d58379dbcc3a442950d558d0ccd42430e Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 17 Jun 2005 09:24:30 +0000 Subject: [PATCH] updated reflection interfaces to represent a pointcut expression as a PointcutExpression rather than as a String. This abstraction is needed to support runtime creation and matching of pointcut expressions down the line. Note that the whole MAP support in this module is still a work in progress and is scheduled for completion in M4. -- AMC. --- .../internal/lang/reflect/AdviceImpl.java | 7 +++-- .../reflect/DeclareErrorOrWarningImpl.java | 7 +++-- .../internal/lang/reflect/PerClauseImpl.java | 7 +++-- .../lang/reflect/PointcutExpressionImpl.java | 30 +++++++++++++++++++ .../internal/lang/reflect/PointcutImpl.java | 7 +++-- .../org/aspectj/lang/reflect/Advice.java | 2 +- .../lang/reflect/DeclareErrorOrWarning.java | 2 +- .../org/aspectj/lang/reflect/PerClause.java | 2 +- .../org/aspectj/lang/reflect/Pointcut.java | 2 +- .../lang/reflect/PointcutExpression.java | 24 +++++++++++++++ .../lang/reflect/AjTypeTestsWithAspects.java | 26 ++++++++-------- 11 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutExpressionImpl.java create mode 100644 aspectj5rt/java5-src/org/aspectj/lang/reflect/PointcutExpression.java diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java index 895e4b4a4..d46b0bf61 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/AdviceImpl.java @@ -16,6 +16,7 @@ import java.lang.reflect.Method; import org.aspectj.lang.annotation.AdviceName; import org.aspectj.lang.reflect.Advice; import org.aspectj.lang.reflect.AdviceType; +import org.aspectj.lang.reflect.PointcutExpression; /** * @author colyer @@ -25,12 +26,12 @@ public class AdviceImpl implements Advice { private final AdviceType kind; private final Method adviceMethod; - private String pointcutExpression; + private PointcutExpression pointcutExpression; protected AdviceImpl(Method method, String pointcut, AdviceType type) { this.kind = type; this.adviceMethod = method; - this.pointcutExpression = pointcut; + this.pointcutExpression = new PointcutExpressionImpl(pointcut); } public AdviceType getKind() { @@ -47,7 +48,7 @@ public class AdviceImpl implements Advice { return adviceName; } - public String getPointcutExpression() { + public PointcutExpression getPointcutExpression() { return pointcutExpression; } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java index 826b36c19..03ea6d40c 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/DeclareErrorOrWarningImpl.java @@ -12,6 +12,7 @@ package org.aspectj.internal.lang.reflect; import org.aspectj.lang.reflect.DeclareErrorOrWarning; +import org.aspectj.lang.reflect.PointcutExpression; /** * @author colyer @@ -19,12 +20,12 @@ import org.aspectj.lang.reflect.DeclareErrorOrWarning; */ public class DeclareErrorOrWarningImpl implements DeclareErrorOrWarning { - private String pc; + private PointcutExpression pc; private String msg; private boolean isError; public DeclareErrorOrWarningImpl(String pointcut, String message, boolean isError) { - this.pc = pointcut; + this.pc = new PointcutExpressionImpl(pointcut); this.msg = message; this.isError = isError; } @@ -32,7 +33,7 @@ public class DeclareErrorOrWarningImpl implements DeclareErrorOrWarning { /* (non-Javadoc) * @see org.aspectj.lang.reflect.DeclareErrorOrWarning#getPointcutExpression() */ - public String getPointcutExpression() { + public PointcutExpression getPointcutExpression() { return pc; } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java index a589f79dc..819d044bf 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PerClauseImpl.java @@ -13,6 +13,7 @@ package org.aspectj.internal.lang.reflect; import org.aspectj.lang.reflect.PerClause; import org.aspectj.lang.reflect.PerClauseKind; +import org.aspectj.lang.reflect.PointcutExpression; /** * @author colyer @@ -21,11 +22,11 @@ import org.aspectj.lang.reflect.PerClauseKind; public class PerClauseImpl implements PerClause { private final PerClauseKind kind; - private final String pointcutExpression; + private final PointcutExpression pointcutExpression; protected PerClauseImpl(PerClauseKind kind, String pointcutExpression) { this.kind = kind; - this.pointcutExpression = pointcutExpression; + this.pointcutExpression = new PointcutExpressionImpl(pointcutExpression); } /* (non-Javadoc) @@ -38,7 +39,7 @@ public class PerClauseImpl implements PerClause { /* (non-Javadoc) * @see org.aspectj.lang.reflect.PerClause#getPointcutExpression() */ - public String getPointcutExpression() { + public PointcutExpression getPointcutExpression() { return pointcutExpression; } diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutExpressionImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutExpressionImpl.java new file mode 100644 index 000000000..e31bd1949 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutExpressionImpl.java @@ -0,0 +1,30 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.internal.lang.reflect; + +import org.aspectj.lang.reflect.PointcutExpression; + +/** + * @author colyer + * + */ +public class PointcutExpressionImpl implements PointcutExpression { + private String expression; + + public PointcutExpressionImpl(String aPointcutExpression) { + this.expression = aPointcutExpression; + } + + public String toString() { + return expression; + } +} diff --git a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java index adc1e9510..e0c102f2f 100644 --- a/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java +++ b/aspectj5rt/java5-src/org/aspectj/internal/lang/reflect/PointcutImpl.java @@ -15,6 +15,7 @@ import java.lang.reflect.Method; import org.aspectj.lang.reflect.AjType; import org.aspectj.lang.reflect.Pointcut; +import org.aspectj.lang.reflect.PointcutExpression; /** * @author colyer @@ -23,13 +24,13 @@ import org.aspectj.lang.reflect.Pointcut; public class PointcutImpl implements Pointcut { private final String name; - private final String pc; + private final PointcutExpression pc; private final Method baseMethod; private final AjType declaringType; protected PointcutImpl(String name, String pc, Method method, AjType declaringType) { this.name = name; - this.pc = pc; + this.pc = new PointcutExpressionImpl(pc); this.baseMethod = method; this.declaringType = declaringType; } @@ -37,7 +38,7 @@ public class PointcutImpl implements Pointcut { /* (non-Javadoc) * @see org.aspectj.lang.reflect.Pointcut#getPointcutExpression() */ - public String getPointcutExpression() { + public PointcutExpression getPointcutExpression() { return pc; } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java index 3fbc668cd..4792a3ba9 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Advice.java @@ -17,5 +17,5 @@ public interface Advice { String getName(); - String getPointcutExpression(); + PointcutExpression getPointcutExpression(); } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java index 4fa4783f0..c8539c166 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/DeclareErrorOrWarning.java @@ -16,7 +16,7 @@ package org.aspectj.lang.reflect; * */ public interface DeclareErrorOrWarning { - String getPointcutExpression(); + PointcutExpression getPointcutExpression(); String getMessage(); boolean isError(); diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/PerClause.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/PerClause.java index 7416ac09d..c3396c548 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/PerClause.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/PerClause.java @@ -17,5 +17,5 @@ package org.aspectj.lang.reflect; */ public interface PerClause { PerClauseKind getKind(); - String getPointcutExpression(); + PointcutExpression getPointcutExpression(); } diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Pointcut.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Pointcut.java index 0802db410..a82941306 100644 --- a/aspectj5rt/java5-src/org/aspectj/lang/reflect/Pointcut.java +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/Pointcut.java @@ -13,7 +13,7 @@ package org.aspectj.lang.reflect; public interface Pointcut { - String getPointcutExpression(); + PointcutExpression getPointcutExpression(); String getName(); diff --git a/aspectj5rt/java5-src/org/aspectj/lang/reflect/PointcutExpression.java b/aspectj5rt/java5-src/org/aspectj/lang/reflect/PointcutExpression.java new file mode 100644 index 000000000..b2ab44d7c --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/lang/reflect/PointcutExpression.java @@ -0,0 +1,24 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.lang.reflect; + +/** + * Represents an anonymous pointcut expression as used in pointcuts, advice declarations, + * declares, and per-clauses + */ +public interface PointcutExpression { + + /** + * Returns a String representation of the pointcut expression + */ + String toString(); +} diff --git a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java index 1ecd34516..8d0820ecc 100644 --- a/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java +++ b/aspectj5rt/java5-testsrc/org/aspectj/internal/lang/reflect/AjTypeTestsWithAspects.java @@ -56,23 +56,23 @@ public class AjTypeTestsWithAspects extends TestCase { PerClause pc = perThisA.getPerClause(); assertEquals(PerClauseKind.PERTHIS,pc.getKind()); - assertEquals("pc()",pc.getPointcutExpression()); + assertEquals("pc()",pc.getPointcutExpression().toString()); pc= perTargetA.getPerClause(); assertEquals(PerClauseKind.PERTARGET,pc.getKind()); - assertEquals("pc()",pc.getPointcutExpression()); + assertEquals("pc()",pc.getPointcutExpression().toString()); pc= perCflowA.getPerClause(); assertEquals(PerClauseKind.PERCFLOW,pc.getKind()); - assertEquals("pc()",pc.getPointcutExpression()); + assertEquals("pc()",pc.getPointcutExpression().toString()); pc= perCflowbelowA.getPerClause(); assertEquals(PerClauseKind.PERCFLOWBELOW,pc.getKind()); - assertEquals("pc()",pc.getPointcutExpression()); + assertEquals("pc()",pc.getPointcutExpression().toString()); pc= perTypeWithinA.getPerClause(); assertEquals(PerClauseKind.PERTYPEWITHIN,pc.getKind()); - assertEquals("org.aspectj..*",pc.getPointcutExpression()); + assertEquals("org.aspectj..*",pc.getPointcutExpression().toString()); } @@ -143,13 +143,13 @@ public class AjTypeTestsWithAspects extends TestCase { public void testGetDeclaredPointcut() throws Exception { Pointcut p1 = sa.getDeclaredPointcut("simpleAspectMethodExecution"); assertEquals("simpleAspectMethodExecution",p1.getName()); - assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression()); + assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression().toString()); assertEquals(sa,p1.getDeclaringType()); assertEquals(0,p1.getParameterTypes().length); assertTrue(Modifier.isPublic(p1.getModifiers())); Pointcut p2 = sa.getDeclaredPointcut("simpleAspectCall"); assertEquals("simpleAspectCall",p2.getName()); - assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression()); + assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression().toString()); assertEquals(sa,p2.getDeclaringType()); assertEquals(1,p2.getParameterTypes().length); assertTrue(Modifier.isPrivate(p2.getModifiers())); @@ -164,13 +164,13 @@ public class AjTypeTestsWithAspects extends TestCase { public void testGetPointcut() throws Exception { Pointcut p1 = sa.getPointcut("simpleAspectMethodExecution"); assertEquals("simpleAspectMethodExecution",p1.getName()); - assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression()); + assertEquals("execution(* SimpleAspect.*(..))",p1.getPointcutExpression().toString()); assertEquals(sa,p1.getDeclaringType()); assertEquals(0,p1.getParameterTypes().length); assertTrue(Modifier.isPublic(p1.getModifiers())); Pointcut p2 = sa.getPointcut("simpleAspectCall"); assertEquals("simpleAspectCall",p2.getName()); - assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression()); + assertEquals("call(* SimpleAspect.*(..))",p2.getPointcutExpression().toString()); assertEquals(sa,p2.getDeclaringType()); assertEquals(1,p2.getParameterTypes().length); assertTrue(Modifier.isPrivate(p2.getModifiers())); @@ -212,10 +212,10 @@ public class AjTypeTestsWithAspects extends TestCase { assertEquals(4,advice.length); advice = sa.getDeclaredAdvice(AdviceType.BEFORE); - assertEquals("execution(* SimpleAspect.*(..))",advice[0].getPointcutExpression()); + assertEquals("execution(* SimpleAspect.*(..))",advice[0].getPointcutExpression().toString()); assertEquals("logEntry",advice[0].getName()); assertEquals(AdviceType.BEFORE,advice[0].getKind()); - assertEquals("execution(* SimpleAspect.*(..))",advice[1].getPointcutExpression()); + assertEquals("execution(* SimpleAspect.*(..))",advice[1].getPointcutExpression().toString()); assertEquals("",advice[1].getName()); } @@ -304,11 +304,11 @@ public class AjTypeTestsWithAspects extends TestCase { if (deow.isError()) { if (deow.getMessage().equals("dont call this method code")) foundCodeError = true; if (deow.getMessage().equals("dont call this method ann")) foundAnnError = true; - assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression()); + assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression().toString()); } else { if (deow.getMessage().equals("dont call this method code")) foundCodeWarning = true; if (deow.getMessage().equals("dont call this method ann")) foundAnnWarning = true; - assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression()); + assertEquals("call(* DontDoIt.*(..))",deow.getPointcutExpression().toString()); } } assertTrue(foundCodeWarning && foundAnnWarning && foundCodeError && foundAnnError); -- 2.39.5