@@ -323,13 +323,13 @@ | |||
System.out.println("phew"); | |||
} | |||
@AfterReturning(value="call(Foo+.new(..))",returning="f") | |||
@AfterReturning(pointcut="call(Foo+.new(..))",returning="f") | |||
public void itsAFoo(Foo f) { | |||
System.out.println("It's a Foo: " + f); | |||
} | |||
]]></programlisting> | |||
<para>(Note the need for the "value=" prefix in front of the pointcut | |||
<para>(Note the use of the "pointcut=" prefix in front of the pointcut | |||
expression in the returning case).</para> | |||
<para>After throwing advice works in a similar fashion, using the |
@@ -0,0 +1,41 @@ | |||
/******************************************************************************* | |||
* 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: | |||
* Alexandre Vasseur initial implementation | |||
*******************************************************************************/ | |||
package ataspectj; | |||
import org.aspectj.lang.annotation.Aspect; | |||
import org.aspectj.lang.annotation.DeclareWarning; | |||
import org.aspectj.lang.annotation.DeclareError; | |||
/** | |||
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> | |||
*/ | |||
public class DeowTest { | |||
public void hello() {} | |||
public void hi() {} | |||
public void target() { | |||
hello(); | |||
hi(); | |||
} | |||
@Aspect | |||
public static class DeowAspect { | |||
@DeclareWarning("call(* hello()) && within(ataspectj.DeowTest)") | |||
final static String onHello = "call hello"; | |||
@DeclareError("call(* hi()) && within(ataspectj.DeowTest)") | |||
final static String onHi = "call hi"; | |||
} | |||
} |
@@ -87,4 +87,8 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase { | |||
public void testAroundInlineMunger2() { | |||
runTest("AroundInlineMunger2"); | |||
} | |||
public void testDeow() { | |||
runTest("Deow"); | |||
} | |||
} |
@@ -100,4 +100,11 @@ | |||
<compile files="ataspectj/AroundInlineMungerTest2.aj,ataspectj/AroundInlineMungerTestAspects2.aj,ataspectj/TestHelper.java" options="-1.5 -Xlint:ignore"/> | |||
<run class="ataspectj.AroundInlineMungerTest2"/> | |||
</ajc-test> | |||
<ajc-test dir="java5/ataspectj" title="Deow"> | |||
<compile files="ataspectj/DeowTest.java" options="-1.5"> | |||
<message kind="warning" line="28" text="call hello"/> | |||
<message kind="error" line="29" text="call hi"/> | |||
</compile> | |||
</ajc-test> | |||
</suite> |
@@ -13,6 +13,9 @@ | |||
package org.aspectj.weaver; | |||
import org.aspectj.lang.JoinPoint; | |||
import org.aspectj.lang.ProceedingJoinPoint; | |||
import java.lang.reflect.Modifier; | |||
//import org.aspectj.weaver.ResolvedTypeX.Name; | |||
@@ -692,4 +695,22 @@ public class AjcMemberMaker { | |||
"<init>", | |||
"()V"); | |||
} | |||
//-- common types we use. Note: Java 5 dependand types are refered to as String | |||
public final static TypeX ASPECT_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.Aspect"); | |||
public final static TypeX BEFORE_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.Before"); | |||
public final static TypeX AROUND_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.Around"); | |||
public final static TypeX AFTERRETURNING_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.AfterReturning"); | |||
public final static TypeX AFTERTHROWING_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.AfterThrowing"); | |||
public final static TypeX AFTER_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.After"); | |||
public final static TypeX POINTCUT_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.Pointcut"); | |||
public final static TypeX DECLAREERROR_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.DeclareError"); | |||
public final static TypeX DECLAREWARNING_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.DeclareWarning"); | |||
public final static TypeX DECLAREPRECEDENCE_ANNOTATION = TypeX.forName("org.aspectj.lang.annotation.DeclarePrecedence"); | |||
public final static TypeX TYPEX_JOINPOINT = TypeX.forName(JoinPoint.class.getName().replace('/','.')); | |||
public final static TypeX TYPEX_PROCEEDINGJOINPOINT = TypeX.forName(ProceedingJoinPoint.class.getName().replace('/','.')); | |||
public final static TypeX TYPEX_STATICJOINPOINT = TypeX.forName(JoinPoint.StaticPart.class.getName().replace('/','.')); | |||
public final static TypeX TYPEX_ENCLOSINGSTATICJOINPOINT = TypeX.forName(JoinPoint.EnclosingStaticPart.class.getName().replace('/','.')); | |||
} |
@@ -1,59 +0,0 @@ | |||
/******************************************************************************* | |||
* 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: | |||
* initial implementation Alexandre Vasseur | |||
*******************************************************************************/ | |||
package org.aspectj.weaver.ataspectj; | |||
import org.aspectj.weaver.ResolvedMember; | |||
import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.Member; | |||
import org.aspectj.weaver.ResolvedTypeX; | |||
import java.lang.reflect.Modifier; | |||
/** | |||
* Addition to AjcMemberMaker for @Aj aspect | |||
* Should end up there | |||
* | |||
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> | |||
*/ | |||
public class Ajc5MemberMaker { | |||
public final static TypeX ASPECT = TypeX.forName("org.aspectj.lang.annotation.Aspect"); | |||
/** | |||
* Returns true if the given aspect is an @AJ aspect | |||
* | |||
* @param aspectType | |||
* @return | |||
*/ | |||
public static boolean isAnnotationStyleAspect(ResolvedTypeX aspectType) { | |||
if (aspectType != null) { | |||
if (aspectType.isAspect()) { | |||
return aspectType.isAnnotationStyleAspect(); | |||
} | |||
} | |||
return false; | |||
} | |||
//temp proto code for aspectOf without pre-processing | |||
public static ResolvedMember perSingletonAspectOfMethod(TypeX declaringType) { | |||
return new ResolvedMember( | |||
Member.METHOD, | |||
TypeX.forName("alex.lang.Aspects"), | |||
Modifier.PUBLIC | Modifier.STATIC, | |||
"aspectOf$singleton", | |||
"(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object;" | |||
); | |||
} | |||
} |
@@ -37,7 +37,6 @@ import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.WeaverMessages; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.PerObjectInterfaceTypeMunger; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
import org.aspectj.weaver.ast.Literal; | |||
import org.aspectj.weaver.ast.Test; | |||
import org.aspectj.weaver.patterns.ExactTypePattern; | |||
@@ -362,7 +361,7 @@ public class BcelAdvice extends Advice { | |||
if (v == null) { | |||
// if not @AJ aspect, go on with the regular binding handling | |||
if (!Ajc5MemberMaker.isAnnotationStyleAspect(getConcreteAspect())) { | |||
if (!getConcreteAspect().isAnnotationStyleAspect()) { | |||
continue; | |||
} else { | |||
// ATAJ: for @AJ aspects, handle implicit binding of xxJoinPoint | |||
@@ -408,7 +407,7 @@ public class BcelAdvice extends Advice { | |||
// ATAJ: for code style aspect, handles the extraFlag as usual ie not | |||
// in the middle of the formal bindings but at the end, in a rock solid ordering | |||
if (!Ajc5MemberMaker.isAnnotationStyleAspect(getConcreteAspect())) { | |||
if (!getConcreteAspect().isAnnotationStyleAspect()) { | |||
if (getKind() == AdviceKind.Around) { | |||
il.append(closureInstantiation); | |||
} else if (hasExtraParameter()) { |
@@ -27,7 +27,6 @@ import org.aspectj.weaver.ResolvedMember; | |||
import org.aspectj.weaver.ResolvedTypeX; | |||
import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.ataspectj.Aj5Attributes; | |||
final class BcelField extends ResolvedMember { | |||
@@ -56,7 +55,7 @@ final class BcelField extends ResolvedMember { | |||
private void unpackAttributes(World world) { | |||
Attribute[] attrs = field.getAttributes(); | |||
List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),attrs, getSourceContext(world),world.getMessageHandler()); | |||
as.addAll(Aj5Attributes.readAj5FieldAttributes(field, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler())); | |||
as.addAll(AtAjAttributes.readAj5FieldAttributes(field, world.resolve(getDeclaringType()), getSourceContext(world), world.getMessageHandler())); | |||
for (Iterator iter = as.iterator(); iter.hasNext();) { | |||
AjAttribute a = (AjAttribute) iter.next(); |
@@ -34,7 +34,6 @@ import org.aspectj.weaver.ResolvedTypeX; | |||
import org.aspectj.weaver.ShadowMunger; | |||
import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.ataspectj.Aj5Attributes; | |||
final class BcelMethod extends ResolvedMember { | |||
@@ -101,7 +100,7 @@ final class BcelMethod extends ResolvedMember { | |||
associatedShadowMunger = null; | |||
List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),method.getAttributes(), getSourceContext(world),world.getMessageHandler()); | |||
processAttributes(world, as); | |||
as = Aj5Attributes.readAj5MethodAttributes(method, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler()); | |||
as = AtAjAttributes.readAj5MethodAttributes(method, world.resolve(getDeclaringType()), preResolvedPointcut,getSourceContext(world), world.getMessageHandler()); | |||
processAttributes(world,as); | |||
} | |||
@@ -36,9 +36,8 @@ import org.aspectj.weaver.ResolvedPointcutDefinition; | |||
import org.aspectj.weaver.ResolvedTypeX; | |||
import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.WeaverStateInfo; | |||
import org.aspectj.weaver.AjcMemberMaker; | |||
import org.aspectj.weaver.patterns.PerClause; | |||
import org.aspectj.weaver.ataspectj.Aj5Attributes; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
// ??? exposed for testing | |||
@@ -186,7 +185,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName { | |||
public boolean isAnnotationStyleAspect() { | |||
if (!discoveredWhetherAnnotationStyle) { | |||
discoveredWhetherAnnotationStyle = true; | |||
isAnnotationStyleAspect = !isCodeStyleAspect && hasAnnotation(Ajc5MemberMaker.ASPECT); | |||
isAnnotationStyleAspect = !isCodeStyleAspect && hasAnnotation(AjcMemberMaker.ASPECT_ANNOTATION); | |||
} | |||
return isAnnotationStyleAspect; | |||
} | |||
@@ -198,7 +197,7 @@ public class BcelObjectType extends ResolvedTypeX.ConcreteName { | |||
// Pass in empty list that can store things for readAj5 to process | |||
List l = BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass.getAttributes(), getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld().getMessageHandler()); | |||
processAttributes(l,pointcuts,false); | |||
l = Aj5Attributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler(),isCodeStyleAspect); | |||
l = AtAjAttributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler(),isCodeStyleAspect); | |||
processAttributes(l,pointcuts,true); | |||
this.pointcuts = (ResolvedPointcutDefinition[]) |
@@ -74,7 +74,6 @@ import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.WeaverMessages; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.ast.Var; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
/* | |||
@@ -2549,8 +2548,7 @@ public class BcelShadow extends Shadow { | |||
} | |||
// ATAJ for @AJ aspect we need to link the closure with the joinpoint instance | |||
if (Ajc5MemberMaker.isAnnotationStyleAspect(munger.getConcreteAspect())) { | |||
//advice.append(new POP()); | |||
if (munger.getConcreteAspect().isAnnotationStyleAspect()) { | |||
closureInstantiation.append(Utility.createInvoke( | |||
getFactory(), | |||
getWorld(), | |||
@@ -2563,12 +2561,9 @@ public class BcelShadow extends Shadow { | |||
) | |||
)); | |||
} | |||
//System.err.println(closureInstantiation); | |||
InstructionList advice = new InstructionList(); | |||
advice.append(munger.getAdviceArgSetup(this, null, closureInstantiation)); | |||
// advice.append(closureInstantiation); | |||
// invoke the advice | |||
advice.append(munger.getNonTestAdviceInstructions(this)); |
@@ -35,7 +35,6 @@ import org.aspectj.weaver.TypeX; | |||
import org.aspectj.weaver.VersionedDataInputStream; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
import org.aspectj.weaver.ast.Expr; | |||
import org.aspectj.weaver.ast.Test; | |||
@@ -106,7 +105,7 @@ public class PerCflow extends PerClause { | |||
} | |||
//ATAJ inline around advice support - don't use a late munger to allow around inling for itself | |||
if (Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) { | |||
if (inAspect.isAnnotationStyleAspect()) { | |||
inAspect.crosscuttingMembers.addTypeMunger(new BcelAccessForInlineMunger(inAspect)); | |||
} | |||
@@ -30,7 +30,6 @@ import org.aspectj.weaver.Shadow; | |||
import org.aspectj.weaver.VersionedDataInputStream; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
import org.aspectj.weaver.ast.Expr; | |||
import org.aspectj.weaver.ast.Test; | |||
import org.aspectj.weaver.ast.Var; | |||
@@ -119,7 +118,7 @@ public class PerObject extends PerClause { | |||
} | |||
//ATAJ inline around advice support - don't use a late munger to allow around inling for itself | |||
if (Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) { | |||
if (inAspect.isAnnotationStyleAspect()) { | |||
inAspect.crosscuttingMembers.addTypeMunger(new BcelAccessForInlineMunger(inAspect)); | |||
} | |||
@@ -27,7 +27,6 @@ import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; | |||
import org.aspectj.weaver.ast.Expr; | |||
import org.aspectj.weaver.ast.Literal; | |||
import org.aspectj.weaver.ast.Test; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
public class PerSingleton extends PerClause { | |||
public PerSingleton() { | |||
@@ -97,7 +96,7 @@ public class PerSingleton extends PerClause { | |||
ret.inAspect = inAspect; | |||
//ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects | |||
if (!inAspect.isAbstract() && Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) { | |||
if (!inAspect.isAbstract() && inAspect.isAnnotationStyleAspect()) { | |||
//TODO will those change be ok if we add a serializable aspect ? | |||
// dig: "can't be Serializable/Cloneable unless -XserializableAspects" | |||
inAspect.crosscuttingMembers.addLateTypeMunger( | |||
@@ -106,7 +105,7 @@ public class PerSingleton extends PerClause { | |||
} | |||
//ATAJ inline around advice support | |||
if (Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) { | |||
if (inAspect.isAnnotationStyleAspect()) { | |||
inAspect.crosscuttingMembers.addTypeMunger(new BcelAccessForInlineMunger(inAspect)); | |||
} | |||
@@ -33,7 +33,6 @@ import org.aspectj.weaver.Shadow; | |||
import org.aspectj.weaver.VersionedDataInputStream; | |||
import org.aspectj.weaver.World; | |||
import org.aspectj.weaver.bcel.BcelAccessForInlineMunger; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
import org.aspectj.weaver.ast.Expr; | |||
import org.aspectj.weaver.ast.Literal; | |||
import org.aspectj.weaver.ast.Test; | |||
@@ -156,7 +155,7 @@ public class PerTypeWithin extends PerClause { | |||
} | |||
//ATAJ inline around advice support - don't use a late munger to allow around inling for itself | |||
if (Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) { | |||
if (inAspect.isAnnotationStyleAspect()) { | |||
inAspect.crosscuttingMembers.addTypeMunger(new BcelAccessForInlineMunger(inAspect)); | |||
} | |||
@@ -37,7 +37,6 @@ import org.aspectj.util.FileUtil; | |||
import org.aspectj.weaver.IClassFileProvider; | |||
import org.aspectj.weaver.IWeaveRequestor; | |||
import org.aspectj.weaver.ResolvedTypeX; | |||
import org.aspectj.weaver.ataspectj.Ajc5MemberMaker; | |||
import org.aspectj.weaver.bcel.BcelWeaver; | |||
import org.aspectj.weaver.bcel.BcelWorld; | |||
import org.aspectj.weaver.bcel.UnwovenClassFile; | |||
@@ -209,7 +208,7 @@ public class WeavingAdaptor { | |||
*/ | |||
private boolean shouldWeaveAspect (String name) { | |||
ResolvedTypeX type = bcelWorld.resolve(name); | |||
return (type == null || !type.isAspect() || Ajc5MemberMaker.isAnnotationStyleAspect(type)); | |||
return (type == null || !type.isAspect() || type.isAnnotationStyleAspect()); | |||
} | |||
/** |