From eb5a3b19f342142e1ee5d5543de59b273fa17de5 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 12 Aug 2011 17:53:05 +0000 Subject: [PATCH] 239649 and primitives no longer all resolved by default --- .../weaver/bcel/AspectInstanceVar.java | 119 +++++++ .../org/aspectj/weaver/bcel/BcelAdvice.java | 1 + .../aspectj/weaver/bcel/BcelClassWeaver.java | 2 +- .../org/aspectj/weaver/bcel/BcelRenderer.java | 11 +- .../org/aspectj/weaver/bcel/BcelShadow.java | 24 +- .../org/aspectj/weaver/bcel/BcelWeaver.java | 7 +- .../org/aspectj/weaver/bcel/BcelWorld.java | 10 +- .../org/aspectj/weaver/bcel/LazyClassGen.java | 4 +- .../aspectj/weaver/bcel/LazyMethodGen.java | 3 +- .../src/org/aspectj/weaver/bcel/Utility.java | 4 +- .../loadtime/definition/LightXMLParser.java | 40 +-- .../aspectj/weaver/tools/WeavingAdaptor.java | 5 +- .../org/aspectj/weaver/MemberTestCase.java | 306 ++++++++--------- .../org/aspectj/weaver/TestShadow.java | 78 +++-- .../aspectj/weaver/bcel/MegaZipTestCase.java | 5 +- .../weaver/bcel/PointcutResidueTestCase.java | 5 +- .../aspectj/weaver/bcel/TjpWeaveTestCase.java | 3 +- .../aspectj/weaver/bcel/WeaveTestCase.java | 26 +- .../AnnotationPatternMatchingTestCase.java | 252 +++++++------- .../patterns/ConcretizationTestCase.java | 215 +++++------- ...lectionBasedReferenceTypeDelegateTest.java | 313 +++++++++--------- 21 files changed, 759 insertions(+), 674 deletions(-) create mode 100644 weaver/src/org/aspectj/weaver/bcel/AspectInstanceVar.java diff --git a/weaver/src/org/aspectj/weaver/bcel/AspectInstanceVar.java b/weaver/src/org/aspectj/weaver/bcel/AspectInstanceVar.java new file mode 100644 index 000000000..37633b71f --- /dev/null +++ b/weaver/src/org/aspectj/weaver/bcel/AspectInstanceVar.java @@ -0,0 +1,119 @@ +/* ******************************************************************* + * Copyright (c) 2011 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - SpringSource/vmware + * ******************************************************************/ +package org.aspectj.weaver.bcel; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.generic.Instruction; +import org.aspectj.apache.bcel.generic.InstructionFactory; +import org.aspectj.apache.bcel.generic.InstructionList; +import org.aspectj.weaver.ResolvedType; + +/** + * Used to represent a variable reference to an aspect instance. This is used to support the if pointcut usage of + * 'thisAspectInstance'. This variable does not have a slot, instead on requesting a reference we call aspectOf() on the aspect in + * question to retrieve it. For now it only works with singleton aspects. + */ +public class AspectInstanceVar extends BcelVar { + + public AspectInstanceVar(ResolvedType type) { + super(type, -1); + } + + // fact is used in the subtypes + public Instruction createLoad(InstructionFactory fact) { + + throw new IllegalStateException(); + // return InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), slot); + } + + public Instruction createStore(InstructionFactory fact) { + throw new IllegalStateException(); + // return InstructionFactory.createStore(BcelWorld.makeBcelType(getType()), slot); + } + + public void appendStore(InstructionList il, InstructionFactory fact) { + throw new IllegalStateException(); + // il.append(createStore(fact)); + } + + public void appendLoad(InstructionList il, InstructionFactory fact) { + throw new IllegalStateException(); + // il.append(createLoad(fact)); + } + + public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedType toType) { + throw new IllegalStateException(); + // il.append(createLoad(fact)); + // Utility.appendConversion(il, fact, getType(), toType); + } + + public void insertLoad(InstructionList il, InstructionFactory fact) { + InstructionList loadInstructions = new InstructionList(); + loadInstructions.append(fact.createInvoke(getType().getName(), "aspectOf", "()" + getType().getSignature(), + Constants.INVOKESTATIC)); + il.insert(loadInstructions); + // throw new IllegalStateException(); + // il.insert(createLoad(fact)); + } + + public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) { + throw new IllegalStateException(); + // InstructionList il = new InstructionList(); + // il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), oldSlot)); + // il.append(createStore(fact)); + // return il; + } + + // this is an array var + void appendConvertableArrayLoad(InstructionList il, InstructionFactory fact, int index, ResolvedType convertTo) { + throw new IllegalStateException(); + // ResolvedType convertFromType = getType().getResolvedComponentType(); + // appendLoad(il, fact); + // il.append(Utility.createConstant(fact, index)); + // il.append(InstructionFactory.createArrayLoad(BcelWorld.makeBcelType(convertFromType))); + // Utility.appendConversion(il, fact, convertFromType, convertTo); + } + + void appendConvertableArrayStore(InstructionList il, InstructionFactory fact, int index, BcelVar storee) { + throw new IllegalStateException(); + // ResolvedType convertToType = getType().getResolvedComponentType(); + // appendLoad(il, fact); + // il.append(Utility.createConstant(fact, index)); + // storee.appendLoad(il, fact); + // Utility.appendConversion(il, fact, storee.getType(), convertToType); + // il.append(InstructionFactory.createArrayStore(BcelWorld.makeBcelType(convertToType))); + } + + InstructionList createConvertableArrayStore(InstructionFactory fact, int index, BcelVar storee) { + throw new IllegalStateException(); + // InstructionList il = new InstructionList(); + // appendConvertableArrayStore(il, fact, index, storee); + // return il; + } + + InstructionList createConvertableArrayLoad(InstructionFactory fact, int index, ResolvedType convertTo) { + throw new IllegalStateException(); + // InstructionList il = new InstructionList(); + // appendConvertableArrayLoad(il, fact, index, convertTo); + // return il; + } + + public int getPositionInAroundState() { + throw new IllegalStateException(); + // return positionInAroundState; + } + + public void setPositionInAroundState(int positionInAroundState) { + throw new IllegalStateException(); + // this.positionInAroundState = positionInAroundState; + } +} diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index f8d48c7bc..4d2e9bb85 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -178,6 +178,7 @@ class BcelAdvice extends Advice { if (!world.areAllLintIgnored()) { suppressLintWarnings(world); } + exposedState.setConcreteAspect(concreteAspect); runtimeTest = getPointcut().findResidue(shadow, exposedState); if (!world.areAllLintIgnored()) { clearLintSuppressions(world, this.suppressedLintKinds); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index 8b0ec5ecf..8e6f0deff 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -3063,7 +3063,7 @@ class BcelClassWeaver implements IClassWeaver { if (declaredSig.getKind() == Member.FIELD) { Shadow.Kind kind; - if (jpSig.getReturnType().equals(ResolvedType.VOID)) { + if (jpSig.getReturnType().equals(UnresolvedType.VOID)) { kind = Shadow.FieldSet; } else { kind = Shadow.FieldGet; diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java b/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java index 345d725b8..e1f99439f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java @@ -12,6 +12,8 @@ package org.aspectj.weaver.bcel; +import java.lang.reflect.Modifier; + import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.generic.InstructionFactory; import org.aspectj.apache.bcel.generic.InstructionHandle; @@ -22,7 +24,6 @@ import org.aspectj.apache.bcel.generic.Type; import org.aspectj.weaver.BCException; import org.aspectj.weaver.Member; import org.aspectj.weaver.MemberImpl; -import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.ast.And; import org.aspectj.weaver.ast.Call; @@ -155,15 +156,14 @@ public final class BcelRenderer implements ITestVisitor, IExprVisitor { // Load up the var again il.append(((BcelVar) hasAnnotation.getVar()).createLoad(fact)); - Member getClass = MemberImpl.method(UnresolvedType.OBJECT, 0, UnresolvedType.JL_CLASS, "getClass", - UnresolvedType.NONE); + Member getClass = MemberImpl.method(UnresolvedType.OBJECT, 0, UnresolvedType.JL_CLASS, "getClass", UnresolvedType.NONE); il.append(Utility.createInvoke(fact, world, getClass)); // aload annotationClass il.append(fact.createConstant(new ObjectType(hasAnnotation.getAnnotationType().getName()))); // int annClassIndex = fact.getConstantPool().addClass(hasAnnotation.getAnnotationType().getSignature()); // il.append(new LDC_W(annClassIndex)); - Member isAnnotationPresent = MemberImpl.method(UnresolvedType.JL_CLASS, 0, ResolvedType.BOOLEAN, - "isAnnotationPresent", new UnresolvedType[] { UnresolvedType.JL_CLASS }); + Member isAnnotationPresent = MemberImpl.method(UnresolvedType.JL_CLASS, 0, UnresolvedType.BOOLEAN, "isAnnotationPresent", + new UnresolvedType[] { UnresolvedType.JL_CLASS }); il.append(Utility.createInvoke(fact, world, isAnnotationPresent)); il.append(createJumpBasedOnBooleanOnStack()); instructions.insert(il); @@ -210,7 +210,6 @@ public final class BcelRenderer implements ITestVisitor, IExprVisitor { Member method = call.getMethod(); // assert method.isStatic() Expr[] args = call.getArgs(); - // System.out.println("args: " + Arrays.asList(args)); InstructionList callIl = new InstructionList(); for (int i = 0, len = args.length; i < len; i++) { // XXX only correct for static method calls diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index f5ba8b8b3..897277699 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -1125,15 +1125,14 @@ public class BcelShadow extends Shadow { return il; } - /** - * Get the Var for the jpStaticPart - * - * @return - */ public BcelVar getThisJoinPointStaticPartBcelVar() { return getThisJoinPointStaticPartBcelVar(false); } + public BcelVar getThisAspectInstanceVar(ResolvedType aspectType) { + return new AspectInstanceVar(aspectType); + } + /** * Get the Var for the xxxxJpStaticPart, xxx = this or enclosing * @@ -1406,7 +1405,7 @@ public class BcelShadow extends Shadow { argVars[i] = tmp; tmp.setPositionInAroundState(i + positionOffset); } - index += type.getSize(); + index += type.resolve(world).getSize(); } } allArgVarsInitialized = true; @@ -1790,7 +1789,7 @@ public class BcelShadow extends Shadow { * @return true, iff this shadow returns a value */ private boolean hasANonVoidReturnType() { - return this.getReturnType() != ResolvedType.VOID; + return !this.getReturnType().equals(UnresolvedType.VOID); } /** @@ -1821,7 +1820,7 @@ public class BcelShadow extends Shadow { private BcelVar insertAdviceInstructionsForBindingReturningParameter(InstructionList advice) { BcelVar tempVar; UnresolvedType tempVarType = getReturnType(); - if (tempVarType.equals(ResolvedType.VOID)) { + if (tempVarType.equals(UnresolvedType.VOID)) { tempVar = genTempVar(UnresolvedType.OBJECT); advice.append(InstructionConstants.ACONST_NULL); tempVar.appendStore(advice, getFactory()); @@ -2026,7 +2025,7 @@ public class BcelShadow extends Shadow { final Type objectArrayType = new ArrayType(Type.OBJECT, 1); final InstructionFactory fact = getFactory(); - final BcelVar testResult = genTempVar(ResolvedType.BOOLEAN); + final BcelVar testResult = genTempVar(UnresolvedType.BOOLEAN); InstructionList entryInstructions = new InstructionList(); { @@ -3297,7 +3296,7 @@ public class BcelShadow extends Shadow { if (getKind() == ConstructorCall) { returnType = getSignature().getDeclaringType(); } else if (getKind() == FieldSet) { - returnType = ResolvedType.VOID; + returnType = UnresolvedType.VOID; } else { returnType = getSignature().getReturnType().resolve(world); // returnType = getReturnType(); // for this and above lines, see pr137496 @@ -3333,8 +3332,9 @@ public class BcelShadow extends Shadow { return ret; } - public BcelVar genTempVar(UnresolvedType typeX) { - return new BcelVar(typeX.resolve(world), genTempVarIndex(typeX.getSize())); + public BcelVar genTempVar(UnresolvedType utype) { + ResolvedType rtype = utype.resolve(world); + return new BcelVar(rtype, genTempVarIndex(rtype.getSize())); } // public static final boolean CREATE_TEMP_NAMES = true; diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 2aa359182..b3fa7f259 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -1722,7 +1722,12 @@ public class BcelWeaver { String classDebugInfo = null; try { classDebugInfo = clazz.toLongString(); - } catch (Exception e) { + } catch (OutOfMemoryError oome) { + System.err.println("Ran out of memory creating debug info for an error"); + re.printStackTrace(System.err); + // recover from crash whilst producing debug string + classDebugInfo = clazz.getClassName(); + } catch (Throwable e) { // recover from crash whilst producing debug string classDebugInfo = clazz.getClassName(); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index 21981e298..fd1cffc54 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -577,7 +577,7 @@ public class BcelWorld extends World implements Repository { Type ot = i.getType(cpg); UnresolvedType ut = fromBcel(ot); ut = UnresolvedType.makeArray(ut, 1); - retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "", new ResolvedType[] { ResolvedType.INT }); + retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "", new ResolvedType[] { INT }); } else if (i instanceof MULTIANEWARRAY) { MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY) i; UnresolvedType ut = null; @@ -592,15 +592,15 @@ public class BcelWorld extends World implements Repository { } ResolvedType[] parms = new ResolvedType[dimensions]; for (int ii = 0; ii < dimensions; ii++) { - parms[ii] = ResolvedType.INT; + parms[ii] = INT; } - retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "", parms); + retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "", parms); } else if (i.opcode == Constants.NEWARRAY) { // NEWARRAY arrayInstruction = (NEWARRAY)i; Type ot = i.getType(); UnresolvedType ut = fromBcel(ot); - retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "", new ResolvedType[] { ResolvedType.INT }); + retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "", new ResolvedType[] { INT }); } else { throw new BCException("Cannot create array construction signature for this non-array instruction:" + i); } @@ -682,7 +682,7 @@ public class BcelWorld extends World implements Repository { classPath.closeArchives(); typeMap.report(); typeMap.demote(true); - ResolvedType.resetPrimitives(); + // ResolvedType.resetPrimitives(); } // / The repository interface methods diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java index 53f585651..e87b92a51 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java @@ -268,7 +268,7 @@ public final class LazyClassGen { // for (int i = 0; i < fields.length; i++) { // ResolvedMember field = fields[i]; // if (field.getName().equals("serialVersionUID") - // && field.isStatic() && field.getType().equals(ResolvedType.LONG)) + // && field.isStatic() && field.getType().equals(UnresolvedType.LONG)) // { // hasSerialVersionUIDField = true; // } @@ -324,7 +324,7 @@ public final class LazyClassGen { for (int i = 0; i < fields.length; i++) { ResolvedMember field = fields[i]; if (field.getName().equals("serialVersionUID") && Modifier.isStatic(field.getModifiers()) - && field.getType().equals(ResolvedType.LONG)) { + && field.getType().equals(UnresolvedType.LONG)) { return true; } } diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index 284f91ce9..ae5f47c42 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -333,7 +333,6 @@ public final class LazyMethodGen implements Traceable { if (returnType != null) { return; } - MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPool(), true); this.returnType = gen.getReturnType(); @@ -1260,7 +1259,7 @@ public final class LazyMethodGen implements Traceable { // due to insertion of advice like cflow entry) int paramSlots = gen.isStatic() ? 0 : 1; Type[] argTypes = gen.getArgumentTypes(); - if (argTypes!=null) { + if (argTypes != null) { for (int i = 0; i < argTypes.length; i++) { if (argTypes[i].getSize() == 2) { paramSlots += 2; diff --git a/weaver/src/org/aspectj/weaver/bcel/Utility.java b/weaver/src/org/aspectj/weaver/bcel/Utility.java index 19bad05b2..20ec45ad0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/org/aspectj/weaver/bcel/Utility.java @@ -281,10 +281,10 @@ public class Utility { return; } } - if (toType.equals(ResolvedType.VOID)) { + if (toType.equals(UnresolvedType.VOID)) { // assert fromType.equals(UnresolvedType.OBJECT) il.append(InstructionFactory.createPop(fromType.getSize())); - } else if (fromType.equals(ResolvedType.VOID)) { + } else if (fromType.equals(UnresolvedType.VOID)) { // assert toType.equals(UnresolvedType.OBJECT) il.append(InstructionFactory.createNull(Type.OBJECT)); return; diff --git a/weaver/src/org/aspectj/weaver/loadtime/definition/LightXMLParser.java b/weaver/src/org/aspectj/weaver/loadtime/definition/LightXMLParser.java index d93a6bd62..09a9df96f 100644 --- a/weaver/src/org/aspectj/weaver/loadtime/definition/LightXMLParser.java +++ b/weaver/src/org/aspectj/weaver/loadtime/definition/LightXMLParser.java @@ -11,24 +11,23 @@ *******************************************************************************/ package org.aspectj.weaver.loadtime.definition; +import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.io.Reader; public class LightXMLParser { private final static char NULL_CHAR = '\0'; - private Map attributes; + private Map attributes; private ArrayList children; private String name; private char pushedBackChar; private Reader reader; - private static Map entities = new HashMap(); - + private static Map entities = new HashMap(); - static{ + static { entities.put("amp", new char[] { '&' }); entities.put("quot", new char[] { '"' }); entities.put("apos", new char[] { '\'' }); @@ -38,7 +37,7 @@ public class LightXMLParser { public LightXMLParser() { this.name = null; - this.attributes = new HashMap(); + this.attributes = new HashMap(); this.children = new ArrayList(); } @@ -52,7 +51,7 @@ public class LightXMLParser { public void parseFromReader(Reader reader) throws Exception { this.pushedBackChar = NULL_CHAR; - this.attributes = new HashMap(); + this.attributes = new HashMap(); this.name = null; this.children = new ArrayList(); this.reader = reader; @@ -64,8 +63,7 @@ public class LightXMLParser { // All xml should start by 'z')) && ((c > 'Z') || (c < 'A')) - && ((c > '9') || (c < '0')) && (c != '_') && (c != '-') + if (((c < 'a') || (c > 'z')) && ((c > 'Z') || (c < 'A')) && ((c > '9') || (c < '0')) && (c != '_') && (c != '-') && (c != '.') && (c != ':')) { this.pushBackChar(c); return; @@ -135,12 +132,10 @@ public class LightXMLParser { private void getString(StringBuffer string) throws Exception { char delimiter = this.getNextChar(); if ((delimiter != '\'') && (delimiter != '"')) { - throw new Exception("Parsing error. Expected ' or \" but got: " - + delimiter); + throw new Exception("Parsing error. Expected ' or \" but got: " + delimiter); } - while (true) { char c = this.getNextChar(); if (c == delimiter) { @@ -339,8 +334,7 @@ public class LightXMLParser { for (int i = 0; i < 2; i++) { c = this.getNextChar(); if (c != '-') { - throw new Exception( - "Parsing error. Expected element or comment"); + throw new Exception("Parsing error. Expected element or comment"); } } this.skipComment(); @@ -353,8 +347,7 @@ public class LightXMLParser { } c = this.skipBlanks(); if (c != '<') { - throw new Exception("Parsing error. Expected <, but got: " - + c); + throw new Exception("Parsing error. Expected <, but got: " + c); } c = this.getNextChar(); } @@ -387,8 +380,7 @@ public class LightXMLParser { char nextChar = this.getNextChar(); if (nextChar != '>') { - throw new Exception("Parsing error. Expected > but got: " - + nextChar); + throw new Exception("Parsing error. Expected > but got: " + nextChar); } } @@ -417,10 +409,7 @@ public class LightXMLParser { } } - - private void mapEntity(StringBuffer buf) - throws Exception - { + private void mapEntity(StringBuffer buf) throws Exception { char c = this.NULL_CHAR; StringBuffer keyBuf = new StringBuffer(); while (true) { @@ -450,6 +439,7 @@ public class LightXMLParser { buf.append(value); } } + private void pushBackChar(char c) { this.pushedBackChar = c; } @@ -462,7 +452,7 @@ public class LightXMLParser { this.attributes.put(name, value.toString()); } - public Map getAttributes() { + public Map getAttributes() { return this.attributes; } diff --git a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java index 63b748044..1ebb14b1a 100644 --- a/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java +++ b/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java @@ -48,7 +48,6 @@ import org.aspectj.util.LangUtil; import org.aspectj.weaver.IClassFileProvider; import org.aspectj.weaver.IUnwovenClassFile; import org.aspectj.weaver.IWeaveRequestor; -import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.BcelObjectType; import org.aspectj.weaver.bcel.BcelWeaver; @@ -844,11 +843,11 @@ public class WeavingAdaptor implements IMessageContext { } public void weaveCompleted() { - ResolvedType.resetPrimitives(); + // ResolvedType.resetPrimitives(); if (delegateForCurrentClass != null) { delegateForCurrentClass.weavingCompleted(); } - ResolvedType.resetPrimitives(); + // ResolvedType.resetPrimitives(); // bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress } }; diff --git a/weaver/testsrc/org/aspectj/weaver/MemberTestCase.java b/weaver/testsrc/org/aspectj/weaver/MemberTestCase.java index 962f2cad7..c4755a3db 100644 --- a/weaver/testsrc/org/aspectj/weaver/MemberTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/MemberTestCase.java @@ -12,7 +12,6 @@ * Adrian Colyer, canBeParameterized tests * ******************************************************************/ - package org.aspectj.weaver; import java.lang.reflect.Modifier; @@ -26,154 +25,159 @@ import org.aspectj.testing.util.TestUtil; */ public class MemberTestCase extends TestCase { - public MemberTestCase(String name) { - super(name); - } - - public void testMethodConstruction() { - Member s = TestUtils.methodFromString("void Foo.goo(int)"); - Member t = MemberImpl.method(UnresolvedType.forName("Foo"), 0, "goo", "(I)V"); - Member u = TestUtils.methodFromString("void Foo1.goo(int)"); - Member v = TestUtils.methodFromString("int Foo.goo(int)"); - - TestUtil.assertCommutativeEquals(s, s, true); - TestUtil.assertCommutativeEquals(t, t, true); - TestUtil.assertCommutativeEquals(u, u, true); - TestUtil.assertCommutativeEquals(v, v, true); - TestUtil.assertCommutativeEquals(s, t, true); - TestUtil.assertCommutativeEquals(s, u, false); - TestUtil.assertCommutativeEquals(s, v, false); - TestUtil.assertCommutativeEquals(t, u, false); - TestUtil.assertCommutativeEquals(t, v, false); - TestUtil.assertCommutativeEquals(u, v, false); - - s = TestUtils.fieldFromString("int Foo.goo"); - t = MemberImpl.field("Foo", 0, "goo", "I"); - u = TestUtils.fieldFromString("int Foo.goo1"); - v = TestUtils.fieldFromString("long Foo.goo"); - - TestUtil.assertCommutativeEquals(s, s, true); - TestUtil.assertCommutativeEquals(t, t, true); - TestUtil.assertCommutativeEquals(u, u, true); - TestUtil.assertCommutativeEquals(v, v, true); - TestUtil.assertCommutativeEquals(s, t, true); - TestUtil.assertCommutativeEquals(s, u, false); - TestUtil.assertCommutativeEquals(s, v, false); - TestUtil.assertCommutativeEquals(t, u, false); - TestUtil.assertCommutativeEquals(t, v, false); - TestUtil.assertCommutativeEquals(u, v, false); - } - - - public void testMethodContents() { - Member m = TestUtils.methodFromString("void Foo.goo(int)"); - kindTest(m, Member.METHOD); - declaringTypeTest(m, "Foo"); - nameTest(m, "goo"); - parameterTypesTest(m, new UnresolvedType[] { ResolvedType.INT }); - returnTypeTest(m, ResolvedType.VOID); - isInterfaceTest(m, false); - isPrivateTest(m, false); - isConstructorTest(m, false); - isStaticTest(m, false); - - m = TestUtils.methodFromString("interface java.lang.Object java.util.Iterator.next()"); - kindTest(m, Member.METHOD); - declaringTypeTest(m, "java.util.Iterator"); - nameTest(m, "next"); - parameterTypesTest(m, UnresolvedType.NONE); - returnTypeTest(m, UnresolvedType.OBJECT); - isInterfaceTest(m, true); - isPrivateTest(m, false); - isConstructorTest(m, false); - isStaticTest(m, false); - - m = TestUtils.methodFromString("void Foo.(int, java.lang.Object)"); - kindTest(m, Member.CONSTRUCTOR); - declaringTypeTest(m, "Foo"); - nameTest(m, ""); - parameterTypesTest(m, new UnresolvedType[] { ResolvedType.INT, UnresolvedType.OBJECT } ); - returnTypeTest(m, ResolvedType.VOID); - isInterfaceTest(m, false); - isPrivateTest(m, false); - isConstructorTest(m, true); - isStaticTest(m, false); - - m = TestUtils.methodFromString("private double Foo.sqrt(double)"); - kindTest(m, Member.METHOD); - declaringTypeTest(m, "Foo"); - nameTest(m, "sqrt"); - parameterTypesTest(m, new UnresolvedType[] { ResolvedType.DOUBLE } ); - returnTypeTest(m, ResolvedType.DOUBLE); - isInterfaceTest(m, false); - isPrivateTest(m, true); - isConstructorTest(m, false); - isStaticTest(m, false); - - m = TestUtils.methodFromString("static int java.lang.Math.max(int, int)"); - kindTest(m, Member.METHOD); - declaringTypeTest(m, "java.lang.Math"); - nameTest(m, "max"); - parameterTypesTest(m, new UnresolvedType[] { ResolvedType.INT, ResolvedType.INT } ); - returnTypeTest(m, ResolvedType.INT); - isInterfaceTest(m, false); - isPrivateTest(m, false); - isConstructorTest(m, false); - isStaticTest(m, true); - } - - public void testFieldContents() { - Member m = TestUtils.fieldFromString("int Foo.goo"); - kindTest(m, Member.FIELD); - declaringTypeTest(m, "Foo"); - nameTest(m, "goo"); - parameterTypesTest(m, UnresolvedType.NONE); - returnTypeTest(m, ResolvedType.INT); - isInterfaceTest(m, false); - isPrivateTest(m, false); - isConstructorTest(m, false); - isStaticTest(m, false); - - m = TestUtils.fieldFromString("static java.util.Iterator goo.Bar.i"); - kindTest(m, Member.FIELD); - declaringTypeTest(m, "goo.Bar"); - nameTest(m, "i"); - parameterTypesTest(m, UnresolvedType.NONE); - returnTypeTest(m, UnresolvedType.forName("java.util.Iterator")); - isInterfaceTest(m, false); - isPrivateTest(m, false); - isConstructorTest(m, false); - isStaticTest(m, true); - } - - private void isStaticTest(Member m, boolean b) { - assertEquals(m + " is static", b, Modifier.isStatic(m.getModifiers())); - } - private void isConstructorTest(Member m, boolean b) { - assertEquals(m + " is constructor", b, m.getKind() == Member.CONSTRUCTOR); - } - private void isPrivateTest(Member m, boolean b) { - assertEquals(m + " is private", b, Modifier.isPrivate(m.getModifiers())); - } - private void isInterfaceTest(Member m, boolean b) { - assertEquals(m + " is interface", b, Modifier.isInterface(m.getModifiers())); - } - private void returnTypeTest(Member m, UnresolvedType returnType) { - assertEquals(m + " return type", returnType, m.getReturnType()); - } - private void parameterTypesTest(Member m, UnresolvedType[] paramTypes) { - TestUtil.assertArrayEquals(m + " parameters", paramTypes, m.getParameterTypes()); - } - private void nameTest(Member m, String name) { - assertEquals(m + " name", name, m.getName()); - } - private void declaringTypeTest(Member m, String declaringName) { - assertEquals(m + " declared in", UnresolvedType.forName(declaringName), m.getDeclaringType()); - } - private void kindTest(Member m, MemberKind kind) { - assertEquals(m + " kind", kind, m.getKind()); - } - - - + public MemberTestCase(String name) { + super(name); + } + + public void testMethodConstruction() { + Member s = TestUtils.methodFromString("void Foo.goo(int)"); + Member t = MemberImpl.method(UnresolvedType.forName("Foo"), 0, "goo", "(I)V"); + Member u = TestUtils.methodFromString("void Foo1.goo(int)"); + Member v = TestUtils.methodFromString("int Foo.goo(int)"); + + TestUtil.assertCommutativeEquals(s, s, true); + TestUtil.assertCommutativeEquals(t, t, true); + TestUtil.assertCommutativeEquals(u, u, true); + TestUtil.assertCommutativeEquals(v, v, true); + TestUtil.assertCommutativeEquals(s, t, true); + TestUtil.assertCommutativeEquals(s, u, false); + TestUtil.assertCommutativeEquals(s, v, false); + TestUtil.assertCommutativeEquals(t, u, false); + TestUtil.assertCommutativeEquals(t, v, false); + TestUtil.assertCommutativeEquals(u, v, false); + + s = TestUtils.fieldFromString("int Foo.goo"); + t = MemberImpl.field("Foo", 0, "goo", "I"); + u = TestUtils.fieldFromString("int Foo.goo1"); + v = TestUtils.fieldFromString("long Foo.goo"); + + TestUtil.assertCommutativeEquals(s, s, true); + TestUtil.assertCommutativeEquals(t, t, true); + TestUtil.assertCommutativeEquals(u, u, true); + TestUtil.assertCommutativeEquals(v, v, true); + TestUtil.assertCommutativeEquals(s, t, true); + TestUtil.assertCommutativeEquals(s, u, false); + TestUtil.assertCommutativeEquals(s, v, false); + TestUtil.assertCommutativeEquals(t, u, false); + TestUtil.assertCommutativeEquals(t, v, false); + TestUtil.assertCommutativeEquals(u, v, false); + } + + public void testMethodContents() { + Member m = TestUtils.methodFromString("void Foo.goo(int)"); + kindTest(m, Member.METHOD); + declaringTypeTest(m, "Foo"); + nameTest(m, "goo"); + parameterTypesTest(m, new UnresolvedType[] { UnresolvedType.INT }); + returnTypeTest(m, UnresolvedType.VOID); + isInterfaceTest(m, false); + isPrivateTest(m, false); + isConstructorTest(m, false); + isStaticTest(m, false); + + m = TestUtils.methodFromString("interface java.lang.Object java.util.Iterator.next()"); + kindTest(m, Member.METHOD); + declaringTypeTest(m, "java.util.Iterator"); + nameTest(m, "next"); + parameterTypesTest(m, UnresolvedType.NONE); + returnTypeTest(m, UnresolvedType.OBJECT); + isInterfaceTest(m, true); + isPrivateTest(m, false); + isConstructorTest(m, false); + isStaticTest(m, false); + + m = TestUtils.methodFromString("void Foo.(int, java.lang.Object)"); + kindTest(m, Member.CONSTRUCTOR); + declaringTypeTest(m, "Foo"); + nameTest(m, ""); + parameterTypesTest(m, new UnresolvedType[] { UnresolvedType.INT, UnresolvedType.OBJECT }); + returnTypeTest(m, UnresolvedType.VOID); + isInterfaceTest(m, false); + isPrivateTest(m, false); + isConstructorTest(m, true); + isStaticTest(m, false); + + m = TestUtils.methodFromString("private double Foo.sqrt(double)"); + kindTest(m, Member.METHOD); + declaringTypeTest(m, "Foo"); + nameTest(m, "sqrt"); + parameterTypesTest(m, new UnresolvedType[] { UnresolvedType.DOUBLE }); + returnTypeTest(m, UnresolvedType.DOUBLE); + isInterfaceTest(m, false); + isPrivateTest(m, true); + isConstructorTest(m, false); + isStaticTest(m, false); + + m = TestUtils.methodFromString("static int java.lang.Math.max(int, int)"); + kindTest(m, Member.METHOD); + declaringTypeTest(m, "java.lang.Math"); + nameTest(m, "max"); + parameterTypesTest(m, new UnresolvedType[] { UnresolvedType.INT, UnresolvedType.INT }); + returnTypeTest(m, UnresolvedType.INT); + isInterfaceTest(m, false); + isPrivateTest(m, false); + isConstructorTest(m, false); + isStaticTest(m, true); + } + + public void testFieldContents() { + Member m = TestUtils.fieldFromString("int Foo.goo"); + kindTest(m, Member.FIELD); + declaringTypeTest(m, "Foo"); + nameTest(m, "goo"); + parameterTypesTest(m, UnresolvedType.NONE); + returnTypeTest(m, UnresolvedType.INT); + isInterfaceTest(m, false); + isPrivateTest(m, false); + isConstructorTest(m, false); + isStaticTest(m, false); + + m = TestUtils.fieldFromString("static java.util.Iterator goo.Bar.i"); + kindTest(m, Member.FIELD); + declaringTypeTest(m, "goo.Bar"); + nameTest(m, "i"); + parameterTypesTest(m, UnresolvedType.NONE); + returnTypeTest(m, UnresolvedType.forName("java.util.Iterator")); + isInterfaceTest(m, false); + isPrivateTest(m, false); + isConstructorTest(m, false); + isStaticTest(m, true); + } + + private void isStaticTest(Member m, boolean b) { + assertEquals(m + " is static", b, Modifier.isStatic(m.getModifiers())); + } + + private void isConstructorTest(Member m, boolean b) { + assertEquals(m + " is constructor", b, m.getKind() == Member.CONSTRUCTOR); + } + + private void isPrivateTest(Member m, boolean b) { + assertEquals(m + " is private", b, Modifier.isPrivate(m.getModifiers())); + } + + private void isInterfaceTest(Member m, boolean b) { + assertEquals(m + " is interface", b, Modifier.isInterface(m.getModifiers())); + } + + private void returnTypeTest(Member m, UnresolvedType returnType) { + assertEquals(m + " return type", returnType, m.getReturnType()); + } + + private void parameterTypesTest(Member m, UnresolvedType[] paramTypes) { + TestUtil.assertArrayEquals(m + " parameters", paramTypes, m.getParameterTypes()); + } + + private void nameTest(Member m, String name) { + assertEquals(m + " name", name, m.getName()); + } + + private void declaringTypeTest(Member m, String declaringName) { + assertEquals(m + " declared in", UnresolvedType.forName(declaringName), m.getDeclaringType()); + } + + private void kindTest(Member m, MemberKind kind) { + assertEquals(m + " kind", kind, m.getKind()); + } + } diff --git a/weaver/testsrc/org/aspectj/weaver/TestShadow.java b/weaver/testsrc/org/aspectj/weaver/TestShadow.java index 761281a48..2cdfd84bf 100644 --- a/weaver/testsrc/org/aspectj/weaver/TestShadow.java +++ b/weaver/testsrc/org/aspectj/weaver/TestShadow.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver; import org.aspectj.bridge.ISourceLocation; @@ -21,34 +20,35 @@ public class TestShadow extends Shadow { private final World world; private final UnresolvedType thisType; - public TestShadow(Kind kind, Member signature, UnresolvedType thisType, World world) { - super(kind, signature, null); - this.world = world; - this.thisType = thisType; - } + public TestShadow(Kind kind, Member signature, UnresolvedType thisType, World world) { + super(kind, signature, null); + this.world = world; + this.thisType = thisType; + } - public World getIWorld() { - return world; - } + public World getIWorld() { + return world; + } - /** this is subtly wrong. ha ha */ - public UnresolvedType getEnclosingType() { - return thisType; - } + /** this is subtly wrong. ha ha */ + public UnresolvedType getEnclosingType() { + return thisType; + } - public Var getThisVar() { - // we should thorw if we don't have a this - return new Var(getThisType().resolve(world)); - } + public Var getThisVar() { + // we should thorw if we don't have a this + return new Var(getThisType().resolve(world)); + } - public Var getTargetVar() { - if (! hasTarget()) throw new RuntimeException("bad"); - return new Var(getTargetType().resolve(world)); - } + public Var getTargetVar() { + if (!hasTarget()) + throw new RuntimeException("bad"); + return new Var(getTargetType().resolve(world)); + } - public Var getArgVar(int i) { - return new Var(getArgType(i).resolve(world)); - } + public Var getArgVar(int i) { + return new Var(getArgType(i).resolve(world)); + } public Var getThisEnclosingJoinPointStaticPartVar() { throw new RuntimeException("unimplemented"); @@ -58,6 +58,10 @@ public class TestShadow extends Shadow { throw new RuntimeException("unimplemented"); } + public Var getThisAspectInstanceVar(ResolvedType aspectType) { + throw new RuntimeException("unimplemented"); + } + public Var getThisJoinPointVar() { throw new RuntimeException("unimplemented"); } @@ -70,45 +74,57 @@ public class TestShadow extends Shadow { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getKindedAnnotationVar() */ public Var getKindedAnnotationVar(UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getWithinAnnotationVar() */ public Var getWithinAnnotationVar(UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getWithinCodeAnnotationVar() */ public Var getWithinCodeAnnotationVar(UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getThisAnnotationVar() */ public Var getThisAnnotationVar(UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getTargetAnnotationVar() */ public Var getTargetAnnotationVar(UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.aspectj.weaver.Shadow#getArgAnnotationVar(int) */ - public Var getArgAnnotationVar(int i,UnresolvedType annotationType) { + public Var getArgAnnotationVar(int i, UnresolvedType annotationType) { throw new RuntimeException("unimplemented"); } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java index ce1b07348..797c153d5 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/MegaZipTestCase.java @@ -23,6 +23,7 @@ import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.Member; import org.aspectj.weaver.MemberImpl; import org.aspectj.weaver.Shadow; +import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.UnresolvedType; public class MegaZipTestCase extends WeaveTestCase { @@ -58,8 +59,8 @@ public class MegaZipTestCase extends WeaveTestCase { }; } - public List getShadowMungers() { - List ret = new ArrayList(); + public List getShadowMungers() { + List ret = new ArrayList(); ret.add(makeConcreteAdvice("before" + "(): call(* *.println(..)) -> static void fluffy.Aspect.before_method_call()")); ret.add(makeConcreteAdvice("afterReturning" + "(): call(* *.println(..)) -> static void fluffy.Aspect.afterReturning_method_call()")); diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/PointcutResidueTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/PointcutResidueTestCase.java index 99083a92e..7f6f5f163 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/PointcutResidueTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/PointcutResidueTestCase.java @@ -145,8 +145,9 @@ public class PointcutResidueTestCase extends WeaveTestCase { formalNames))); ShadowMunger pp = new BcelAdvice(AdviceKind.Before, rp, MemberImpl.method(UnresolvedType.forName("Aspect"), - Modifier.STATIC, "ajc_before_0", MemberImpl.typesToSignature(ResolvedType.VOID, UnresolvedType - .forNames(formalTypes), false)), 0, -1, -1, null, null); + Modifier.STATIC, "ajc_before_0", + MemberImpl.typesToSignature(UnresolvedType.VOID, UnresolvedType.forNames(formalTypes), false)), 0, -1, -1, null, + null); ResolvedType inAspect = world.resolve("Aspect"); CrosscuttingMembers xcut = new CrosscuttingMembers(inAspect, true); diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/TjpWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/TjpWeaveTestCase.java index ee6d20e5e..b24b3f6d0 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/TjpWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/TjpWeaveTestCase.java @@ -18,6 +18,7 @@ import java.util.Arrays; import org.aspectj.weaver.Advice; import org.aspectj.weaver.AdviceKind; import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ShadowMunger; import org.aspectj.weaver.TestUtils; import org.aspectj.weaver.UnresolvedType; @@ -92,7 +93,7 @@ public class TjpWeaveTestCase extends WeaveTestCase { .methodFromString("static java.lang.Object Aspect.ajc_around(org.aspectj.runtime.internal.AroundClosure, org.aspectj.lang.JoinPoint)"), Advice.ThisJoinPoint | Advice.ExtraArgument, -1, -1, null, rtx); - weaveTest("HelloWorld", "TjpAround2HelloWorld", Arrays.asList(new BcelAdvice[] { munger1, munger2 })); + weaveTest("HelloWorld", "TjpAround2HelloWorld", Arrays.asList(new ShadowMunger[] { munger1, munger2 })); } } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java index 117877e53..e3d62faa3 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java @@ -81,7 +81,7 @@ public abstract class WeaveTestCase extends TestCase { } public void weaveTest(String name, String outName, ShadowMunger planner) throws IOException { - List l = new ArrayList(1); + List l = new ArrayList(1); l.add(planner); weaveTest(name, outName, l); } @@ -89,7 +89,7 @@ public abstract class WeaveTestCase extends TestCase { // static String classDir = "../weaver/bin"; static String classDir = BcweaverTests.TESTDATA_PATH + File.separator + "bin"; - public void weaveTest(String name, String outName, List planners) throws IOException { + public void weaveTest(String name, String outName, List planners) throws IOException { BcelWeaver weaver = new BcelWeaver(world); try { if (behave15) @@ -97,7 +97,7 @@ public abstract class WeaveTestCase extends TestCase { UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath); - weaver.addClassFile(classFile,false); + weaver.addClassFile(classFile, false); weaver.setShadowMungers(planners); weaveTestInner(weaver, classFile, name, outName); } finally { @@ -170,8 +170,8 @@ public abstract class WeaveTestCase extends TestCase { } void realCheckClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException { - TestUtil.assertMultiLineStringEquals(expectedFile/* "classes" */, FileUtil - .readAsString(new File(TESTDATA_DIR, expectedFile)), gen.toLongString()); + TestUtil.assertMultiLineStringEquals(expectedFile/* "classes" */, + FileUtil.readAsString(new File(TESTDATA_DIR, expectedFile)), gen.toLongString()); } // ---- @@ -197,18 +197,14 @@ public abstract class WeaveTestCase extends TestCase { return makeConcreteAdvice(kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get(" + extraArgType + ")", 1); } - public List makeAdviceAll(String kind, boolean matchOnlyPrintln) { - List ret = new ArrayList(); + public List makeAdviceAll(String kind, boolean matchOnlyPrintln) { + List ret = new ArrayList(); if (matchOnlyPrintln) { - ret - .add(makeConcreteAdvice(kind + "(): call(* *.println(..)) -> static void Aspect.ajc_" + kind - + "_method_execution()")); + ret.add(makeConcreteAdvice(kind + "(): call(* *.println(..)) -> static void Aspect.ajc_" + kind + "_method_execution()")); } else { ret.add(makeConcreteAdvice(kind + "(): call(* *.*(..)) -> static void Aspect.ajc_" + kind + "_method_call()")); ret.add(makeConcreteAdvice(kind + "(): call(*.new(..)) -> static void Aspect.ajc_" + kind + "_constructor_call()")); - ret - .add(makeConcreteAdvice(kind + "(): execution(* *.*(..)) -> static void Aspect.ajc_" + kind - + "_method_execution()")); + ret.add(makeConcreteAdvice(kind + "(): execution(* *.*(..)) -> static void Aspect.ajc_" + kind + "_method_execution()")); ret.add(makeConcreteAdvice(kind + "(): execution(*.new(..)) -> static void Aspect.ajc_" + kind + "_constructor_execution()")); // ret.add( @@ -226,7 +222,7 @@ public abstract class WeaveTestCase extends TestCase { return ret; } - public List makeAdviceAll(final String kind) { + public List makeAdviceAll(final String kind) { return makeAdviceAll(kind, false); } @@ -270,7 +266,7 @@ public abstract class WeaveTestCase extends TestCase { } } - protected void weaveTest(String[] inClassNames, String outKind, List patternMungers) throws IOException { + protected void weaveTest(String[] inClassNames, String outKind, List patternMungers) throws IOException { for (int i = 0; i < inClassNames.length; i++) { String inFileName = inClassNames[i]; weaveTest(inFileName, outKind + inFileName, patternMungers); diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java index 9efe6bc20..e8999bafd 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java @@ -18,135 +18,139 @@ import junit.framework.TestCase; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.IMessage; -import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.IMessage.Kind; +import org.aspectj.bridge.IMessageHandler; import org.aspectj.util.LangUtil; import org.aspectj.weaver.BcweaverTests; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.bcel.BcelWorld; -import org.aspectj.weaver.patterns.TestScope; /* * Sample types that this program uses are: - -import p.SimpleAnnotation; -@SimpleAnnotation(id=2) -public class AnnotatedClass { + import p.SimpleAnnotation; - @SimpleAnnotation(id=3) - public void m1() { } + @SimpleAnnotation(id=2) + public class AnnotatedClass { - @SimpleAnnotation(id=4) - int i; -} + @SimpleAnnotation(id=3) + public void m1() { } + + @SimpleAnnotation(id=4) + int i; + } * with SimpleAnnotation defined as: -package p; -import java.lang.annotation.*; + package p; + import java.lang.annotation.*; -@Retention(RetentionPolicy.RUNTIME) -public @interface SimpleAnnotation { - int id(); - String fruit() default "bananas"; -} + @Retention(RetentionPolicy.RUNTIME) + public @interface SimpleAnnotation { + int id(); + String fruit() default "bananas"; + } -*NOTE NOTE NOTE NOTE NOTE NOTE NOTE* -If you need to rebuild the test data code, run 'ant -f build-15.xml' in the -testdata directory. + *NOTE NOTE NOTE NOTE NOTE NOTE NOTE* + If you need to rebuild the test data code, run 'ant -f build-15.xml' in the + testdata directory. */ public class AnnotationPatternMatchingTestCase extends TestCase { - + private BcelWorld world; - private AnnotationTypePattern fooTP,simpleAnnotationTP; - + private AnnotationTypePattern fooTP, simpleAnnotationTP; + private ResolvedType loadType(String name) { if (world == null) { - world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); - world.setBehaveInJava5Way(true); + world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); + world.setBehaveInJava5Way(true); } return world.resolve(name); } - + private void initAnnotationTypePatterns() { PatternParser p = new PatternParser("@Foo"); fooTP = p.maybeParseAnnotationPattern(); - fooTP = fooTP.resolveBindings(makeSimpleScope(),new Bindings(3),true); - + fooTP = fooTP.resolveBindings(makeSimpleScope(), new Bindings(3), true); + p = new PatternParser("@p.SimpleAnnotation"); simpleAnnotationTP = p.maybeParseAnnotationPattern(); - simpleAnnotationTP = simpleAnnotationTP.resolveBindings(makeSimpleScope(),new Bindings(3),true); + simpleAnnotationTP = simpleAnnotationTP.resolveBindings(makeSimpleScope(), new Bindings(3), true); } - - + public void testAnnotationPatternMatchingOnTypes() { if (LangUtil.is15VMOrGreater()) { - ResolvedType rtx = loadType("AnnotatedClass"); - initAnnotationTypePatterns(); - - // One should match - assertTrue("@Foo should not match on the AnnotatedClass", - fooTP.matches(rtx).alwaysFalse()); - assertTrue("@SimpleAnnotation should match on the AnnotatedClass", - simpleAnnotationTP.matches(rtx).alwaysTrue()); + ResolvedType rtx = loadType("AnnotatedClass"); + initAnnotationTypePatterns(); + + // One should match + assertTrue("@Foo should not match on the AnnotatedClass", fooTP.matches(rtx).alwaysFalse()); + assertTrue("@SimpleAnnotation should match on the AnnotatedClass", simpleAnnotationTP.matches(rtx).alwaysTrue()); } } - + static class MyMessageHandler implements IMessageHandler { - public List messages = new ArrayList(); + public List messages = new ArrayList(); + public boolean handleMessage(IMessage message) throws AbortException { messages.add(message); return false; } - public boolean isIgnoring(Kind kind) {return false;} - public void dontIgnore(IMessage.Kind kind) {} - public void ignore(Kind kind) {} + + public boolean isIgnoring(Kind kind) { + return false; + } + + public void dontIgnore(IMessage.Kind kind) { + } + + public void ignore(Kind kind) { + } } - + public void testReferenceToNonAnnotationType() { -// ResolvedType rtx = - loadType("AnnotatedClass"); // inits the world + // ResolvedType rtx = + loadType("AnnotatedClass"); // inits the world PatternParser p = new PatternParser("@java.lang.String"); - + MyMessageHandler mh = new MyMessageHandler(); world.setMessageHandler(mh); AnnotationTypePattern atp = p.maybeParseAnnotationPattern(); - atp = atp.resolveBindings(makeSimpleScope(),new Bindings(3),true); - - assertTrue("Expected 1 error message but got "+mh.messages.size(),mh.messages.size()==1); - + atp = atp.resolveBindings(makeSimpleScope(), new Bindings(3), true); + + assertTrue("Expected 1 error message but got " + mh.messages.size(), mh.messages.size() == 1); + String expected = "Type referred to is not an annotation type"; - String msg = ((IMessage)mh.messages.get(0)).toString(); - assertTrue("Expected: "+expected+" but got "+msg,msg.indexOf(expected)!=-1); + String msg = ((IMessage) mh.messages.get(0)).toString(); + assertTrue("Expected: " + expected + " but got " + msg, msg.indexOf(expected) != -1); } - + public void testReferenceViaFormalToNonAnnotationType() { -// ResolvedType rtx = - loadType("AnnotatedClass"); // inits the world + // ResolvedType rtx = + loadType("AnnotatedClass"); // inits the world PatternParser p = new PatternParser("a"); - + MyMessageHandler mh = new MyMessageHandler(); world.setMessageHandler(mh); AnnotationTypePattern atp = p.parseAnnotationNameOrVarTypePattern(); - atp = atp.resolveBindings(makeSimpleScope(),new Bindings(3),true); - - assertTrue("Expected 2 error messages but got "+mh.messages.size(),mh.messages.size()==1); - + atp = atp.resolveBindings(makeSimpleScope(), new Bindings(3), true); + + assertTrue("Expected 3 error messages but got " + mh.messages.size(), mh.messages.size() == 3); + String expected = "Type referred to is not an annotation type"; - String msg = ((IMessage)mh.messages.get(0)).toString(); - assertTrue("Expected: "+expected+" but got "+msg,msg.indexOf(expected)!=-1); - -// expected = "Binding not supported in @pcds (1.5.0 M1 limitation): null"; -// msg = ((IMessage)mh.messages.get(1)).toString(); -// assertTrue("Expected: "+expected+" but got "+msg,msg.indexOf(expected)!=-1); + String msg = ((IMessage) mh.messages.get(0)).toString(); + assertTrue("Expected: " + expected + " but got " + msg, msg.indexOf(expected) != -1); + + // expected = "Binding not supported in @pcds (1.5.0 M1 limitation): null"; + // msg = ((IMessage)mh.messages.get(1)).toString(); + // assertTrue("Expected: "+expected+" but got "+msg,msg.indexOf(expected)!=-1); } - + public TestScope makeSimpleScope() { - return new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world); + return new TestScope(new String[] { "int", "java.lang.String" }, new String[] { "a", "b" }, world); } public void testUnresolvedAnnotationTypes() { @@ -161,98 +165,88 @@ public class AnnotationPatternMatchingTestCase extends TestCase { // Correct! } } - + public void testAnnotationPatternMatchingOnMethods() { if (LangUtil.is15VMOrGreater()) { - ResolvedType rtx = loadType("AnnotatedClass"); - ResolvedMember aMethod = rtx.getDeclaredMethods()[1]; - - assertTrue("Haven't got the right method, I'm looking for 'm1()': "+aMethod.getName(), - aMethod.getName().equals("m1")); - - initAnnotationTypePatterns(); - - // One should match - assertTrue("@Foo should not match on the AnnotatedClass.m1() method", - fooTP.matches(aMethod).alwaysFalse()); - assertTrue("@SimpleAnnotation should match on the AnnotatedClass.m1() method", - simpleAnnotationTP.matches(aMethod).alwaysTrue()); + ResolvedType rtx = loadType("AnnotatedClass"); + ResolvedMember aMethod = rtx.getDeclaredMethods()[1]; + + assertTrue("Haven't got the right method, I'm looking for 'm1()': " + aMethod.getName(), aMethod.getName().equals("m1")); + + initAnnotationTypePatterns(); + + // One should match + assertTrue("@Foo should not match on the AnnotatedClass.m1() method", fooTP.matches(aMethod).alwaysFalse()); + assertTrue("@SimpleAnnotation should match on the AnnotatedClass.m1() method", simpleAnnotationTP.matches(aMethod) + .alwaysTrue()); } } - + public void testAnnotationPatternMatchingOnFields() { if (LangUtil.is15VMOrGreater()) { - ResolvedType rtx = loadType("AnnotatedClass"); - ResolvedMember aField = rtx.getDeclaredFields()[0]; + ResolvedType rtx = loadType("AnnotatedClass"); + ResolvedMember aField = rtx.getDeclaredFields()[0]; - assertTrue("Haven't got the right field, I'm looking for 'i'"+aField.getName(), - aField.getName().equals("i")); + assertTrue("Haven't got the right field, I'm looking for 'i'" + aField.getName(), aField.getName().equals("i")); - initAnnotationTypePatterns(); - - // One should match - assertTrue("@Foo should not match on the AnnotatedClass.i field", - fooTP.matches(aField).alwaysFalse()); - assertTrue("@SimpleAnnotation should match on the AnnotatedClass.i field", - simpleAnnotationTP.matches(aField).alwaysTrue()); + initAnnotationTypePatterns(); + + // One should match + assertTrue("@Foo should not match on the AnnotatedClass.i field", fooTP.matches(aField).alwaysFalse()); + assertTrue("@SimpleAnnotation should match on the AnnotatedClass.i field", simpleAnnotationTP.matches(aField) + .alwaysTrue()); } } - + public void testAnnotationTypeResolutionOnTypes() { ResolvedType rtx = loadType("AnnotatedClass"); ResolvedType[] types = rtx.getAnnotationTypes(); - assertTrue("Did not expect null",types!=null); - assertTrue("Expected 1 entry but got "+types.length,types.length==1); - assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], - types[0].equals(world.resolve("p.SimpleAnnotation"))); + assertTrue("Did not expect null", types != null); + assertTrue("Expected 1 entry but got " + types.length, types.length == 1); + assertTrue("Should be 'p.SimpleAnnotation' but is " + types[0], types[0].equals(world.resolve("p.SimpleAnnotation"))); } - + public void testAnnotationTypeResolutionOnMethods() { ResolvedType rtx = loadType("AnnotatedClass"); ResolvedMember aMethod = rtx.getDeclaredMethods()[1]; - assertTrue("Haven't got the right method, I'm looking for 'm1()': "+aMethod.getName(), - aMethod.getName().equals("m1")); - + assertTrue("Haven't got the right method, I'm looking for 'm1()': " + aMethod.getName(), aMethod.getName().equals("m1")); + ResolvedType[] types = aMethod.getAnnotationTypes(); - assertTrue("Did not expect null",types!=null); - assertTrue("Expected 1 entry but got "+types.length,types.length==1); - assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], - types[0].equals(world.resolve("p.SimpleAnnotation"))); + assertTrue("Did not expect null", types != null); + assertTrue("Expected 1 entry but got " + types.length, types.length == 1); + assertTrue("Should be 'p.SimpleAnnotation' but is " + types[0], types[0].equals(world.resolve("p.SimpleAnnotation"))); } - + public void testAnnotationTypeResolutionOnFields() { ResolvedType rtx = loadType("AnnotatedClass"); ResolvedMember aField = rtx.getDeclaredFields()[0]; - assertTrue("Haven't got the right field, I'm looking for 'i'"+aField.getName(), - aField.getName().equals("i")); - + assertTrue("Haven't got the right field, I'm looking for 'i'" + aField.getName(), aField.getName().equals("i")); + ResolvedType[] types = aField.getAnnotationTypes(); - assertTrue("Did not expect null",types!=null); - assertTrue("Expected 1 entry but got "+types.length,types.length==1); - assertTrue("Should be 'p.SimpleAnnotation' but is "+types[0], - types[0].equals(world.resolve("p.SimpleAnnotation"))); + assertTrue("Did not expect null", types != null); + assertTrue("Expected 1 entry but got " + types.length, types.length == 1); + assertTrue("Should be 'p.SimpleAnnotation' but is " + types[0], types[0].equals(world.resolve("p.SimpleAnnotation"))); } - + public void testWildPatternMatchingOnTypes() { - + ResolvedType rtx = loadType("AnnotatedClass"); - initAnnotationTypePatterns(); - - // Let's create something wild + initAnnotationTypePatterns(); + + // Let's create something wild PatternParser p = new PatternParser("@(Foo || Boo)"); AnnotationTypePattern ap = p.maybeParseAnnotationPattern(); - ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); - assertTrue("shouldnt match the type AnnotatedClass",ap.matches(rtx).alwaysFalse()); - - + ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); + assertTrue("shouldnt match the type AnnotatedClass", ap.matches(rtx).alwaysFalse()); + p = new PatternParser("@(p.SimpleAnnotation || Boo)"); ap = p.maybeParseAnnotationPattern(); - ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true); - assertTrue("should match the type AnnotatedClass",ap.matches(rtx).alwaysTrue()); + ap = ap.resolveBindings(makeSimpleScope(), new Bindings(3), true); + assertTrue("should match the type AnnotatedClass", ap.matches(rtx).alwaysTrue()); } } diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ConcretizationTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ConcretizationTestCase.java index 53373b4b5..8c3fd0d9c 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/ConcretizationTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/ConcretizationTestCase.java @@ -10,7 +10,6 @@ * PARC initial implementation * ******************************************************************/ - package org.aspectj.weaver.patterns; import org.aspectj.weaver.UnresolvedType; @@ -20,140 +19,98 @@ public class ConcretizationTestCase extends WeaveTestCase { { regenerate = false; } + public ConcretizationTestCase(String name) { super(name); } - public void testNothingForAntJUnit() {} - - // String[] none = new String[0]; - - - - /* XXX temporarily skipping - public void testCflowResidual() throws IOException { - - BcelAdvice a = (BcelAdvice) makeConcreteTestAdviceEntryPart(); - - TestShadow shadow = new TestShadow(Shadow.MethodCall, - Member.methodFromString("int Aspect.i(int x)"), - UnresolvedType.OBJECT, - world); - - ExposedState state = new ExposedState(1); - - a.specializeOn(shadow); - - //System.err.println(shadow); - //System.err.println(a); - //System.err.println(a.exposedState); - - + public void testNothingForAntJUnit() { } - - - public Advice makeConcreteTestAdviceEntryPart() throws IOException { - // XXX copied from below, refactor later - - - // returns the advice for the entry part of cflow(foo(a)) - Pointcut in = - createResolvedPointcut( - "cflow(foo(a)) && (args(b) && !cflow(foo(int)))", - new String[] { "b", "a" }, - new String[] { "float", "int" }); - - ResolvedPointcutDefinition ref = - new ResolvedPointcutDefinition( - UnresolvedType.forName("Aspect"), - 0, - "foo", - new UnresolvedType[] { ResolvedType.INT }, - createResolvedPointcut( - "args(refA)", - new String[] { "refA" }, - new String[] { "int" })); - BcelObjectType target = (BcelObjectType) world.resolve("Aspect"); - - // now munge this to get the pointcut in it - - target.addPointcutDefinition(ref); - CrosscuttingMembers xcut = new CrosscuttingMembers(target); - target.crosscuttingMembers = xcut; - - Advice adviceMember = - new BcelAdvice( - AdviceKind.Before, - in, - Member.method(UnresolvedType.forName("FOO"), 0, "garadf", "(FI)V"), - 0, - 0, 0, null, - null); - // The pointcut to concretize - - // this returns the actual advice, but we don't care about it now. - in.concretize(target, 2, adviceMember); - - List c = (List)xcut.getCflowEntries(); //target.getExtraConcreteShadowMungers(); - - return (Advice) c.get(0); - } - - public void XtestCflow() throws IOException { - Pointcut in = createResolvedPointcut("cflow(foo(a)) && (args(b) && !cflow(foo(int)))", - new String[] {"b", "a"}, new String[] {"float", "int"} ); - - ResolvedPointcutDefinition ref = - new ResolvedPointcutDefinition(UnresolvedType.forName("Aspect"), - 0, "foo", new UnresolvedType[] { ResolvedType.INT }, - createResolvedPointcut("args(refA)", - new String[] {"refA"}, new String[] {"int"})); - - List expectedSlots = new ArrayList(); - expectedSlots.add(new ConcreteCflowPointcut.Slot(1, ResolvedType.INT, 0)); - - checkConcr(in, ref, expectedSlots); - } - - public void checkConcr( - Pointcut in, - ResolvedPointcutDefinition referredTo, - List expectedSlots) throws IOException { - - BcelObjectType target = (BcelObjectType)world.resolve("Aspect"); - - // now munge this to get the pointcut in it - - target.addPointcutDefinition(referredTo); - - - Advice adviceMember = new BcelAdvice(AdviceKind.Before, in, - Member.method(UnresolvedType.forName("FOO"), 0, "garadf", "(FI)V"), 0, 0, 0, null, null); - - // The pointcut to concretize - AndPointcut ap = (AndPointcut)in.concretize(target, 2, adviceMember); - - - ConcreteCflowPointcut conc = (ConcreteCflowPointcut)ap.left; - - List slots = conc.slots; - TestUtil.assertSetEquals(expectedSlots, slots); - - } - */ - - - public Pointcut createResolvedPointcut( - String pointcutSource, String[] formalNames, String[] formalTypes) { - final Pointcut sp = Pointcut.fromString(pointcutSource); - final Pointcut rp = - sp.resolve( - new SimpleScope( - world, - SimpleScope.makeFormalBindings(UnresolvedType.forNames(formalTypes), - formalNames) - )); + // String[] none = new String[0]; + + /* + * XXX temporarily skipping public void testCflowResidual() throws IOException { + * + * BcelAdvice a = (BcelAdvice) makeConcreteTestAdviceEntryPart(); + * + * TestShadow shadow = new TestShadow(Shadow.MethodCall, Member.methodFromString("int Aspect.i(int x)"), UnresolvedType.OBJECT, + * world); + * + * ExposedState state = new ExposedState(1); + * + * a.specializeOn(shadow); + * + * //System.err.println(shadow); //System.err.println(a); + * + * //System.err.println(a.exposedState); + * + * + * } + * + * + * + * public Advice makeConcreteTestAdviceEntryPart() throws IOException { // XXX copied from below, refactor later + * + * + * // returns the advice for the entry part of cflow(foo(a)) Pointcut in = createResolvedPointcut( + * "cflow(foo(a)) && (args(b) && !cflow(foo(int)))", new String[] { "b", "a" }, new String[] { "float", "int" }); + * + * ResolvedPointcutDefinition ref = new ResolvedPointcutDefinition( UnresolvedType.forName("Aspect"), 0, "foo", new + * UnresolvedType[] { UnresolvedType.INT }, createResolvedPointcut( "args(refA)", new String[] { "refA" }, new String[] { "int" + * })); BcelObjectType target = (BcelObjectType) world.resolve("Aspect"); + * + * // now munge this to get the pointcut in it + * + * target.addPointcutDefinition(ref); CrosscuttingMembers xcut = new CrosscuttingMembers(target); target.crosscuttingMembers = + * xcut; + * + * Advice adviceMember = new BcelAdvice( AdviceKind.Before, in, Member.method(UnresolvedType.forName("FOO"), 0, "garadf", + * "(FI)V"), 0, 0, 0, null, null); // The pointcut to concretize + * + * // this returns the actual advice, but we don't care about it now. in.concretize(target, 2, adviceMember); + * + * List c = (List)xcut.getCflowEntries(); //target.getExtraConcreteShadowMungers(); + * + * return (Advice) c.get(0); } + * + * public void XtestCflow() throws IOException { Pointcut in = + * createResolvedPointcut("cflow(foo(a)) && (args(b) && !cflow(foo(int)))", new String[] {"b", "a"}, new String[] {"float", + * "int"} ); + * + * ResolvedPointcutDefinition ref = new ResolvedPointcutDefinition(UnresolvedType.forName("Aspect"), 0, "foo", new + * UnresolvedType[] { UnresolvedType.INT }, createResolvedPointcut("args(refA)", new String[] {"refA"}, new String[] {"int"})); + * + * List expectedSlots = new ArrayList(); expectedSlots.add(new ConcreteCflowPointcut.Slot(1, UnresolvedType.INT, 0)); + * + * checkConcr(in, ref, expectedSlots); } + * + * public void checkConcr( Pointcut in, ResolvedPointcutDefinition referredTo, List expectedSlots) throws IOException { + * + * BcelObjectType target = (BcelObjectType)world.resolve("Aspect"); + * + * // now munge this to get the pointcut in it + * + * target.addPointcutDefinition(referredTo); + * + * + * Advice adviceMember = new BcelAdvice(AdviceKind.Before, in, Member.method(UnresolvedType.forName("FOO"), 0, "garadf", + * "(FI)V"), 0, 0, 0, null, null); + * + * // The pointcut to concretize AndPointcut ap = (AndPointcut)in.concretize(target, 2, adviceMember); + * + * + * ConcreteCflowPointcut conc = (ConcreteCflowPointcut)ap.left; + * + * List slots = conc.slots; TestUtil.assertSetEquals(expectedSlots, slots); + * + * } + */ + + public Pointcut createResolvedPointcut(String pointcutSource, String[] formalNames, String[] formalTypes) { + final Pointcut sp = Pointcut.fromString(pointcutSource); + final Pointcut rp = sp.resolve(new SimpleScope(world, SimpleScope.makeFormalBindings(UnresolvedType.forNames(formalTypes), + formalNames))); return rp; } } diff --git a/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java index 0a844ec5d..8047bbd4c 100644 --- a/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java +++ b/weaver/testsrc/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateTest.java @@ -11,7 +11,6 @@ * ******************************************************************/ package org.aspectj.weaver.reflect; - import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; @@ -30,193 +29,193 @@ public class ReflectionBasedReferenceTypeDelegateTest extends TestCase { protected ReflectionWorld world; private ResolvedType objectType; private ResolvedType classType; - + public void testIsAspect() { assertFalse(objectType.isAspect()); } - + public void testIsAnnotationStyleAspect() { assertFalse(objectType.isAnnotationStyleAspect()); } - + public void testIsInterface() { assertFalse(objectType.isInterface()); assertTrue(world.resolve("java.io.Serializable").isInterface()); } - + public void testIsEnum() { assertFalse(objectType.isEnum()); } - + public void testIsAnnotation() { assertFalse(objectType.isAnnotation()); } - + public void testIsAnnotationWithRuntimeRetention() { assertFalse(objectType.isAnnotationWithRuntimeRetention()); } - + public void testIsClass() { assertTrue(objectType.isClass()); assertFalse(world.resolve("java.io.Serializable").isClass()); } - + public void testIsGeneric() { assertFalse(objectType.isGenericType()); } - + public void testIsExposedToWeaver() { assertFalse(objectType.isExposedToWeaver()); } - + public void testHasAnnotation() { assertFalse(objectType.hasAnnotation(UnresolvedType.forName("Foo"))); } - + public void testGetAnnotations() { - assertEquals("no entries",0,objectType.getAnnotations().length); + assertEquals("no entries", 0, objectType.getAnnotations().length); } - + public void testGetAnnotationTypes() { - assertEquals("no entries",0,objectType.getAnnotationTypes().length); + assertEquals("no entries", 0, objectType.getAnnotationTypes().length); } - + public void testGetTypeVariables() { - assertEquals("no entries",0,objectType.getTypeVariables().length); + assertEquals("no entries", 0, objectType.getTypeVariables().length); } - + public void testGetPerClause() { assertNull(objectType.getPerClause()); } - + public void testGetModifiers() { - assertEquals(Object.class.getModifiers(),objectType.getModifiers()); + assertEquals(Object.class.getModifiers(), objectType.getModifiers()); } - + public void testGetSuperclass() { - assertTrue("Superclass of object should be null, but it is: "+objectType.getSuperclass(),objectType.getSuperclass()==null); - assertEquals(objectType,world.resolve("java.lang.Class").getSuperclass()); + assertTrue("Superclass of object should be null, but it is: " + objectType.getSuperclass(), + objectType.getSuperclass() == null); + assertEquals(objectType, world.resolve("java.lang.Class").getSuperclass()); ResolvedType d = world.resolve("reflect.tests.D"); - assertEquals(world.resolve("reflect.tests.C"),d.getSuperclass()); + assertEquals(world.resolve("reflect.tests.C"), d.getSuperclass()); + } + + public void testArrayArgsSig() throws Exception { + Method invokeMethod = Method.class.getMethod("invoke", new Class[] { Object.class, Object[].class }); + ResolvedMember reflectionMethod = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMethod(invokeMethod, world); + String exp = "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"; + assertTrue("Expected: \n" + exp + "\n but got:\n" + reflectionMethod.getSignature(), reflectionMethod.getSignature() + .equals(exp)); } - - public void testArrayArgsSig() throws Exception { - Method invokeMethod = Method.class.getMethod("invoke", new Class[] { Object.class, Object[].class}); - ResolvedMember reflectionMethod = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMethod(invokeMethod, world); - String exp = "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"; - assertTrue("Expected: \n"+exp+"\n but got:\n"+reflectionMethod.getSignature(), reflectionMethod.getSignature().equals(exp)); - } protected int findMethod(String name, ResolvedMember[] methods) { - for (int i=0; i -1); - - assertEquals(world.resolve("java.lang.String"),methods[idx].getReturnType()); + + assertEquals(world.resolve("java.lang.String"), methods[idx].getReturnType()); assertEquals(1, methods[idx].getParameterTypes().length); - assertEquals(objectType,methods[idx].getParameterTypes()[0]); - assertEquals(1,methods[idx].getExceptions().length); - assertEquals(world.resolve("java.lang.Exception"),methods[idx].getExceptions()[0]); + assertEquals(objectType, methods[idx].getParameterTypes()[0]); + assertEquals(1, methods[idx].getExceptions().length); + assertEquals(world.resolve("java.lang.Exception"), methods[idx].getExceptions()[0]); int baridx = findMethod("bar", methods); int initidx = findMethod("", methods); assertTrue(baridx > -1); assertTrue(initidx > -1); assertTrue(baridx != initidx && baridx != idx && idx <= 2 && initidx <= 2 && baridx <= 2); - + ResolvedType d = world.resolve("reflect.tests.D"); methods = d.getDeclaredMethods(); - assertEquals(2,methods.length); + assertEquals(2, methods.length); classType = world.resolve("java.lang.Class"); methods = classType.getDeclaredMethods(); - assertEquals(Class.class.getDeclaredMethods().length + Class.class.getDeclaredConstructors().length, methods.length); + assertEquals(Class.class.getDeclaredMethods().length + Class.class.getDeclaredConstructors().length, methods.length); } - + public void testGetDeclaredFields() { ResolvedMember[] fields = objectType.getDeclaredFields(); - assertEquals(0,fields.length); + assertEquals(0, fields.length); ResolvedType c = world.resolve("reflect.tests.C"); fields = c.getDeclaredFields(); - - assertEquals(2,fields.length); - assertEquals("f",fields[0].getName()); - assertEquals("s",fields[1].getName()); - assertEquals(ResolvedType.INT,fields[0].getReturnType()); - assertEquals(world.resolve("java.lang.String"),fields[1].getReturnType()); + + assertEquals(2, fields.length); + assertEquals("f", fields[0].getName()); + assertEquals("s", fields[1].getName()); + assertEquals(UnresolvedType.INT, fields[0].getReturnType()); + assertEquals(world.resolve("java.lang.String"), fields[1].getReturnType()); } - + public void testGetDeclaredInterfaces() { ResolvedType[] interfaces = objectType.getDeclaredInterfaces(); - assertEquals(0,interfaces.length); + assertEquals(0, interfaces.length); ResolvedType d = world.resolve("reflect.tests.D"); interfaces = d.getDeclaredInterfaces(); - assertEquals(1,interfaces.length); - assertEquals(world.resolve("java.io.Serializable"),interfaces[0]); - } - + assertEquals(1, interfaces.length); + assertEquals(world.resolve("java.io.Serializable"), interfaces[0]); + } + public void testGetDeclaredPointcuts() { ResolvedMember[] pointcuts = objectType.getDeclaredPointcuts(); - assertEquals(0,pointcuts.length); + assertEquals(0, pointcuts.length); } - - - + public void testSerializableSuperclass() { ResolvedType serializableType = world.resolve("java.io.Serializable"); ResolvedType superType = serializableType.getSuperclass(); - assertTrue("Superclass of serializable should be Object but was "+superType,superType.equals(UnresolvedType.OBJECT)); + assertTrue("Superclass of serializable should be Object but was " + superType, superType.equals(UnresolvedType.OBJECT)); - BcelWorld bcelworld = new BcelWorld(); - bcelworld.setBehaveInJava5Way(true); - ResolvedType bcelSupertype = bcelworld.resolve(UnresolvedType.SERIALIZABLE).getSuperclass(); - assertTrue("Should be null but is "+bcelSupertype,bcelSupertype.equals(UnresolvedType.OBJECT)); + BcelWorld bcelworld = new BcelWorld(); + bcelworld.setBehaveInJava5Way(true); + ResolvedType bcelSupertype = bcelworld.resolve(UnresolvedType.SERIALIZABLE).getSuperclass(); + assertTrue("Should be null but is " + bcelSupertype, bcelSupertype.equals(UnresolvedType.OBJECT)); } - - public void testSubinterfaceSuperclass() { + + public void testSubinterfaceSuperclass() { ResolvedType ifaceType = world.resolve("java.security.Key"); ResolvedType superType = ifaceType.getSuperclass(); - assertTrue("Superclass should be Object but was "+superType,superType.equals(UnresolvedType.OBJECT)); + assertTrue("Superclass should be Object but was " + superType, superType.equals(UnresolvedType.OBJECT)); - BcelWorld bcelworld = new BcelWorld(); - bcelworld.setBehaveInJava5Way(true); - ResolvedType bcelSupertype = bcelworld.resolve("java.security.Key").getSuperclass(); - assertTrue("Should be null but is "+bcelSupertype,bcelSupertype.equals(UnresolvedType.OBJECT)); + BcelWorld bcelworld = new BcelWorld(); + bcelworld.setBehaveInJava5Way(true); + ResolvedType bcelSupertype = bcelworld.resolve("java.security.Key").getSuperclass(); + assertTrue("Should be null but is " + bcelSupertype, bcelSupertype.equals(UnresolvedType.OBJECT)); } - + public void testVoidSuperclass() { ResolvedType voidType = world.resolve(Void.TYPE); ResolvedType superType = voidType.getSuperclass(); assertNull(superType); - - BcelWorld bcelworld = new BcelWorld(); - bcelworld.setBehaveInJava5Way(true); - ResolvedType bcelSupertype = bcelworld.resolve("void").getSuperclass(); - assertTrue("Should be null but is "+bcelSupertype,bcelSupertype==null); + + BcelWorld bcelworld = new BcelWorld(); + bcelworld.setBehaveInJava5Way(true); + ResolvedType bcelSupertype = bcelworld.resolve("void").getSuperclass(); + assertTrue("Should be null but is " + bcelSupertype, bcelSupertype == null); } public void testIntSuperclass() { @@ -224,87 +223,91 @@ public class ReflectionBasedReferenceTypeDelegateTest extends TestCase { ResolvedType superType = voidType.getSuperclass(); assertNull(superType); - BcelWorld bcelworld = new BcelWorld(); - bcelworld.setBehaveInJava5Way(true); - ResolvedType bcelSupertype = bcelworld.resolve("int").getSuperclass(); - assertTrue("Should be null but is "+bcelSupertype,bcelSupertype==null); + BcelWorld bcelworld = new BcelWorld(); + bcelworld.setBehaveInJava5Way(true); + ResolvedType bcelSupertype = bcelworld.resolve("int").getSuperclass(); + assertTrue("Should be null but is " + bcelSupertype, bcelSupertype == null); + } + + public void testGenericInterfaceSuperclass_BcelWorldResolution() { + BcelWorld bcelworld = new BcelWorld(); + bcelworld.setBehaveInJava5Way(true); + + UnresolvedType javaUtilMap = UnresolvedType.forName("java.util.Map"); + + ReferenceType rawType = (ReferenceType) bcelworld.resolve(javaUtilMap); + assertTrue("Should be the raw type ?!? " + rawType.getTypekind(), rawType.isRawType()); + + ReferenceType genericType = (ReferenceType) rawType.getGenericType(); + assertTrue("Should be the generic type ?!? " + genericType.getTypekind(), genericType.isGenericType()); + + ResolvedType rt = rawType.getSuperclass(); + assertTrue("Superclass for Map raw type should be Object but was " + rt, rt.equals(UnresolvedType.OBJECT)); + + ResolvedType rt2 = genericType.getSuperclass(); + assertTrue("Superclass for Map generic type should be Object but was " + rt2, rt2.equals(UnresolvedType.OBJECT)); } - - public void testGenericInterfaceSuperclass_BcelWorldResolution() { - BcelWorld bcelworld = new BcelWorld(); - bcelworld.setBehaveInJava5Way(true); - - UnresolvedType javaUtilMap = UnresolvedType.forName("java.util.Map"); - - ReferenceType rawType = (ReferenceType) bcelworld.resolve(javaUtilMap); - assertTrue("Should be the raw type ?!? "+rawType.getTypekind(),rawType.isRawType()); - - ReferenceType genericType = (ReferenceType)rawType.getGenericType(); - assertTrue("Should be the generic type ?!? "+genericType.getTypekind(),genericType.isGenericType()); - - ResolvedType rt = rawType.getSuperclass(); - assertTrue("Superclass for Map raw type should be Object but was "+rt,rt.equals(UnresolvedType.OBJECT)); - - ResolvedType rt2 = genericType.getSuperclass(); - assertTrue("Superclass for Map generic type should be Object but was "+rt2,rt2.equals(UnresolvedType.OBJECT)); - } - - // FIXME asc maybe. The reflection list of methods returned doesn't include (the static initializer) ... is that really a problem. - public void testCompareSubclassDelegates() { - - boolean barfIfClinitMissing = false; - world.setBehaveInJava5Way(true); - - BcelWorld bcelWorld = new BcelWorld(getClass().getClassLoader(),IMessageHandler.THROW,null); - bcelWorld.setBehaveInJava5Way(true); - UnresolvedType javaUtilHashMap = UnresolvedType.forName("java.util.HashMap"); - ReferenceType rawType =(ReferenceType)bcelWorld.resolve(javaUtilHashMap ); - - ReferenceType rawReflectType =(ReferenceType)world.resolve(javaUtilHashMap ); - ResolvedMember[] rms1 = rawType.getDelegate().getDeclaredMethods(); - ResolvedMember[] rms2 = rawReflectType.getDelegate().getDeclaredMethods(); - StringBuffer errors = new StringBuffer(); - Set one = new HashSet(); - for (int i = 0; i < rms1.length; i++) { + + // FIXME asc maybe. The reflection list of methods returned doesn't include (the static initializer) ... is that really + // a problem. + public void testCompareSubclassDelegates() { + + boolean barfIfClinitMissing = false; + world.setBehaveInJava5Way(true); + + BcelWorld bcelWorld = new BcelWorld(getClass().getClassLoader(), IMessageHandler.THROW, null); + bcelWorld.setBehaveInJava5Way(true); + UnresolvedType javaUtilHashMap = UnresolvedType.forName("java.util.HashMap"); + ReferenceType rawType = (ReferenceType) bcelWorld.resolve(javaUtilHashMap); + + ReferenceType rawReflectType = (ReferenceType) world.resolve(javaUtilHashMap); + ResolvedMember[] rms1 = rawType.getDelegate().getDeclaredMethods(); + ResolvedMember[] rms2 = rawReflectType.getDelegate().getDeclaredMethods(); + StringBuffer errors = new StringBuffer(); + Set one = new HashSet(); + for (int i = 0; i < rms1.length; i++) { one.add(rms1[i].toString()); } - Set two = new HashSet(); - for (int i = 0; i < rms2.length; i++) { + Set two = new HashSet(); + for (int i = 0; i < rms2.length; i++) { two.add(rms2[i].toString()); } - for (int i = 0;i")) continue; - errors.append("Couldn't find "+rms1[i].toString()+" in the reflection set\n"); - } - } - assertTrue("Errors:"+errors.toString(),errors.length()==0); - - // the good old ibm vm seems to offer clinit through its reflection support (see pr145322) - if (rms1.length==rms2.length) return; - if (barfIfClinitMissing) { - // the numbers must be exact - assertEquals(rms1.length,rms2.length); - } else { - // the numbers can be out by one in favour of bcel - if (rms1.length!=(rms2.length+1)) { - for (int i = 0; i < rms1.length; i++) { - System.err.println("bcel"+i+" is "+rms1[i]); + for (int i = 0; i < rms2.length; i++) { + if (!one.contains(rms2[i].toString())) { + errors.append("Couldn't find " + rms2[i].toString() + " in the bcel set\n"); + } + } + for (int i = 0; i < rms1.length; i++) { + if (!two.contains(rms1[i].toString())) { + if (!barfIfClinitMissing && rms1[i].getName().equals("")) + continue; + errors.append("Couldn't find " + rms1[i].toString() + " in the reflection set\n"); + } + } + assertTrue("Errors:" + errors.toString(), errors.length() == 0); + + // the good old ibm vm seems to offer clinit through its reflection support (see pr145322) + if (rms1.length == rms2.length) + return; + if (barfIfClinitMissing) { + // the numbers must be exact + assertEquals(rms1.length, rms2.length); + } else { + // the numbers can be out by one in favour of bcel + if (rms1.length != (rms2.length + 1)) { + for (int i = 0; i < rms1.length; i++) { + System.err.println("bcel" + i + " is " + rms1[i]); } - for (int i = 0; i < rms2.length; i++) { - System.err.println("refl"+i+" is "+rms2[i]); + for (int i = 0; i < rms2.length; i++) { + System.err.println("refl" + i + " is " + rms2[i]); } - } - assertTrue("Should be one extra (clinit) in BCEL case, but bcel="+rms1.length+" reflect="+rms2.length,rms1.length==rms2.length+1); - } - } - - // todo: array of int + } + assertTrue("Should be one extra (clinit) in BCEL case, but bcel=" + rms1.length + " reflect=" + rms2.length, + rms1.length == rms2.length + 1); + } + } + + // todo: array of int protected void setUp() throws Exception { world = new ReflectionWorld(getClass().getClassLoader()); -- 2.39.5