From 7314d8a35171c7c6a44fbcde50e793e3fbd6910c Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 3 Feb 2005 11:36:54 +0000 Subject: [PATCH] Support for @this, @args --- .../org/aspectj/weaver/bcel/BcelShadow.java | 17 +++++++--- .../weaver/bcel/TypeAnnotationAccessVar.java | 32 ++++++------------- .../patterns/ArgsAnnotationPointcut.java | 16 +++++++--- .../BindingAnnotationTypePattern.java | 10 ++++-- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 7e4b93135..9427e1c3e 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -889,8 +889,12 @@ public class BcelShadow extends Shadow { if (!hasThis()) { throw new IllegalStateException("no this"); } - initializeThisAnnotationVars(); - return (Var) thisAnnotationVars.get(forAnnotationType); + initializeThisAnnotationVars(); // FIXME ASC Why bother with this if we always return one? + // Even if we can't find one, we have to return one as we might have this annotation at runtime + Var v = (Var) thisAnnotationVars.get(forAnnotationType); + if (v==null) + v = new TypeAnnotationAccessVar(forAnnotationType.resolve(world),(BcelVar)getThisVar()); + return v; } public Var getTargetVar() { if (!hasTarget()) { @@ -903,7 +907,7 @@ public class BcelShadow extends Shadow { if (!hasTarget()) { throw new IllegalStateException("no target"); } - initializeTargetAnnotationVars(); + initializeTargetAnnotationVars(); // FIXME ASC why bother with this if we always return one? Var v =(Var) targetAnnotationVars.get(forAnnotationType); // Even if we can't find one, we have to return one as we might have this annotation at runtime if (v==null) @@ -916,7 +920,11 @@ public class BcelShadow extends Shadow { } public Var getArgAnnotationVar(int i,TypeX forAnnotationType) { initializeArgAnnotationVars(); - return (Var) argAnnotationVars[i].get(forAnnotationType); + + Var v= (Var) argAnnotationVars[i].get(forAnnotationType); + if (v==null) + v = new TypeAnnotationAccessVar(forAnnotationType.resolve(world),(BcelVar)getArgVar(i)); + return v; } public Var getKindedAnnotationVar(TypeX forAnnotationType) { initializeKindedAnnotationVars(); @@ -1296,6 +1304,7 @@ public class BcelShadow extends Shadow { argAnnotationVars = new Map[numArgs]; for (int i = 0; i < argAnnotationVars.length; i++) { argAnnotationVars[i] = new HashMap(); + //FIXME ASC Fill this in // populate } } diff --git a/weaver/src/org/aspectj/weaver/bcel/TypeAnnotationAccessVar.java b/weaver/src/org/aspectj/weaver/bcel/TypeAnnotationAccessVar.java index fed60896b..c30e4ba58 100644 --- a/weaver/src/org/aspectj/weaver/bcel/TypeAnnotationAccessVar.java +++ b/weaver/src/org/aspectj/weaver/bcel/TypeAnnotationAccessVar.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2005 * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -7,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * PARC initial implementation + * Andy Clement initial implementation * ******************************************************************/ @@ -19,37 +19,25 @@ import org.aspectj.apache.bcel.generic.InstructionFactory; import org.aspectj.apache.bcel.generic.InstructionList; import org.aspectj.apache.bcel.generic.ObjectType; import org.aspectj.apache.bcel.generic.Type; -import org.aspectj.weaver.Member; import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.TypeX; /** + * Used for @this() @target() @args() - represents accessing an annotated + * 'thing'. Main use is to create the instructions that retrieve the + * annotation from the 'thing' - see createLoadInstructions() */ public class TypeAnnotationAccessVar extends BcelVar { - - private Member stackField; - private int index; - BcelVar target; - - /** - * @param type The type to convert to from Object - * @param stackField the member containing the CFLOW_STACK_TYPE - * @param index yeah yeah - */ - public TypeAnnotationAccessVar(ResolvedTypeX type, Member stackField, int index) { - super(type, 0); - this.stackField = stackField; - this.index = index; - } + private BcelVar target; - public TypeAnnotationAccessVar(ResolvedTypeX type,BcelVar theTargetIsStoredHere) { + public TypeAnnotationAccessVar(ResolvedTypeX type,BcelVar theAnnotatedTargetIsStoredHere) { super(type,0); - target = theTargetIsStoredHere; + target = theAnnotatedTargetIsStoredHere; } public String toString() { - return "TypeAnnotationAccessVar(" + getType() + " " + stackField + "." + index + ")"; + return "TypeAnnotationAccessVar(" + getType() + ")"; } public Instruction createLoad(InstructionFactory fact) { @@ -71,7 +59,7 @@ public class TypeAnnotationAccessVar extends BcelVar { InstructionList il = new InstructionList(); Type jlClass = BcelWorld.makeBcelType(TypeX.JAVA_LANG_CLASS); Type jlaAnnotation = BcelWorld.makeBcelType(TypeX.forSignature("Ljava.lang.annotation.Annotation;")); - il.append(target.createLoad(fact)); + il.append(target.createLoad(fact)); il.append(fact.createInvoke("java/lang/Object","getClass",jlClass,new Type[]{},Constants.INVOKEVIRTUAL)); il.append(fact.createConstant(new ObjectType(toType.getClassName()))); il.append(fact.createInvoke("java/lang/Class","getAnnotation",jlaAnnotation,new Type[]{jlClass},Constants.INVOKEVIRTUAL)); diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java index ff3336d62..5ba432e81 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java @@ -29,6 +29,7 @@ import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; +import org.aspectj.weaver.ast.Var; /** * @author colyer @@ -136,15 +137,22 @@ public class ArgsAnnotationPointcut extends NameBindingPointcut { WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_ARG_TYPE,argType.getName()), "",IMessage.ERROR,shadow.getSourceLocation(),null,new ISourceLocation[]{getSourceLocation()}); } - if (ap.matches(rArgType).alwaysTrue()) { + if (ap.matches(rArgType).alwaysTrue()) { // !!! ASC Can we ever take this branch? argsIndex++; continue; } else { // we need a test... - // TODO: binding ResolvedTypeX rAnnType = ap.annotationType.resolve(shadow.getIWorld()); - ret = Test.makeAnd(ret,Test.makeHasAnnotation(shadow.getArgVar(argsIndex),rAnnType)); - argsIndex++; + if (ap instanceof BindingAnnotationTypePattern) { + BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern)ap; + Var annvar = shadow.getArgAnnotationVar(argsIndex,rAnnType); + state.set(argsIndex,annvar); + ret = Test.makeAnd(ret,Test.makeHasAnnotation(shadow.getArgVar(argsIndex),rAnnType)); + argsIndex++; + } else { + ret = Test.makeAnd(ret,Test.makeHasAnnotation(shadow.getArgVar(argsIndex),rAnnType)); + argsIndex++; + } } } } diff --git a/weaver/src/org/aspectj/weaver/patterns/BindingAnnotationTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/BindingAnnotationTypePattern.java index e59907592..e4040819e 100644 --- a/weaver/src/org/aspectj/weaver/patterns/BindingAnnotationTypePattern.java +++ b/weaver/src/org/aspectj/weaver/patterns/BindingAnnotationTypePattern.java @@ -58,8 +58,14 @@ public class BindingAnnotationTypePattern extends ExactAnnotationTypePattern imp world.getMessageHandler().handleMessage(m); resolved = false; } else { - // TO DO... get the retention policy annotation, and check the value is - // RetentionPolicy.RUNTIME; + // Get the retention policy annotation, and check the value is RetentionPolicy.RUNTIME; + // FIXME invention required, implement this ! +// if (!annotationType.hasRuntimeRetention()) { +// ResolvedTypeX[] allAs = annotationType.getAnnotationTypes(); +// for (int i = 0; i < allAs.length; i++) { +// ResolvedTypeX ann = allAs[i]; +// if () +// } } } -- 2.39.5