--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+}
if (!world.areAllLintIgnored()) {
suppressLintWarnings(world);
}
+ exposedState.setConcreteAspect(concreteAspect);
runtimeTest = getPointcut().findResidue(shadow, exposedState);
if (!world.areAllLintIgnored()) {
clearLintSuppressions(world, this.suppressedLintKinds);
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;
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;
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;
// 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);
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
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
*
argVars[i] = tmp;
tmp.setPositionInAroundState(i + positionOffset);
}
- index += type.getSize();
+ index += type.resolve(world).getSize();
}
}
allArgVarsInitialized = true;
* @return true, iff this shadow returns a value
*/
private boolean hasANonVoidReturnType() {
- return this.getReturnType() != ResolvedType.VOID;
+ return !this.getReturnType().equals(UnresolvedType.VOID);
}
/**
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());
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();
{
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
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;
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();
}
Type ot = i.getType(cpg);
UnresolvedType ut = fromBcel(ot);
ut = UnresolvedType.makeArray(ut, 1);
- retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[] { ResolvedType.INT });
+ retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", new ResolvedType[] { INT });
} else if (i instanceof MULTIANEWARRAY) {
MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY) i;
UnresolvedType ut = null;
}
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, "<init>", parms);
+ retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", 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, "<init>", new ResolvedType[] { ResolvedType.INT });
+ retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", new ResolvedType[] { INT });
} else {
throw new BCException("Cannot create array construction signature for this non-array instruction:" + i);
}
classPath.closeArchives();
typeMap.report();
typeMap.demote(true);
- ResolvedType.resetPrimitives();
+ // ResolvedType.resetPrimitives();
}
// / The repository interface methods
// 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;
// }
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;
}
}
if (returnType != null) {
return;
}
-
MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPool(), true);
this.returnType = gen.getReturnType();
// 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;
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;
*******************************************************************************/
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<String, Object> attributes;
private ArrayList children;
private String name;
private char pushedBackChar;
private Reader reader;
- private static Map entities = new HashMap();
-
+ private static Map<String, char[]> entities = new HashMap<String, char[]>();
- static{
+ static {
entities.put("amp", new char[] { '&' });
entities.put("quot", new char[] { '"' });
entities.put("apos", new char[] { '\'' });
public LightXMLParser() {
this.name = null;
- this.attributes = new HashMap();
+ this.attributes = new HashMap<String, Object>();
this.children = new ArrayList();
}
public void parseFromReader(Reader reader) throws Exception {
this.pushedBackChar = NULL_CHAR;
- this.attributes = new HashMap();
+ this.attributes = new HashMap<String, Object>();
this.name = null;
this.children = new ArrayList();
this.reader = reader;
// All xml should start by <xml, a <!-- or <nodeName, if not throw
// exception
if (c != '<') {
- throw new Exception(
- "LightParser Exception: Expected < but got: " + c);
+ throw new Exception("LightParser Exception: Expected < but got: " + c);
}
// read next character
// Iterate while next character is not [a-z] [A-Z] [0-9] [ .:_-] not
// null
c = this.getNextChar();
- if (((c < 'a') || (c > '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;
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) {
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();
}
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();
}
char nextChar = this.getNextChar();
if (nextChar != '>') {
- throw new Exception("Parsing error. Expected > but got: "
- + nextChar);
+ throw new Exception("Parsing error. Expected > but got: " + nextChar);
}
}
}
}
-
- 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) {
buf.append(value);
}
}
+
private void pushBackChar(char c) {
this.pushedBackChar = c;
}
this.attributes.put(name, value.toString());
}
- public Map getAttributes() {
+ public Map<String, Object> getAttributes() {
return this.attributes;
}
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;
}
public void weaveCompleted() {
- ResolvedType.resetPrimitives();
+ // ResolvedType.resetPrimitives();
if (delegateForCurrentClass != null) {
delegateForCurrentClass.weavingCompleted();
}
- ResolvedType.resetPrimitives();
+ // ResolvedType.resetPrimitives();
// bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress
}
};
* Adrian Colyer, canBeParameterized tests
* ******************************************************************/
-
package org.aspectj.weaver;
import java.lang.reflect.Modifier;
*/
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.<init>(int, java.lang.Object)");
- kindTest(m, Member.CONSTRUCTOR);
- declaringTypeTest(m, "Foo");
- nameTest(m, "<init>");
- 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.<init>(int, java.lang.Object)");
+ kindTest(m, Member.CONSTRUCTOR);
+ declaringTypeTest(m, "Foo");
+ nameTest(m, "<init>");
+ 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());
+ }
+
}
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver;
import org.aspectj.bridge.ISourceLocation;
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");
throw new RuntimeException("unimplemented");
}
+ public Var getThisAspectInstanceVar(ResolvedType aspectType) {
+ throw new RuntimeException("unimplemented");
+ }
+
public Var getThisJoinPointVar() {
throw new RuntimeException("unimplemented");
}
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");
}
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 {
};
}
- public List getShadowMungers() {
- List ret = new ArrayList();
+ public List<ShadowMunger> getShadowMungers() {
+ List<ShadowMunger> ret = new ArrayList<ShadowMunger>();
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()"));
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);
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;
.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 }));
}
}
}
public void weaveTest(String name, String outName, ShadowMunger planner) throws IOException {
- List l = new ArrayList(1);
+ List<ShadowMunger> l = new ArrayList<ShadowMunger>(1);
l.add(planner);
weaveTest(name, outName, l);
}
// 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<ShadowMunger> planners) throws IOException {
BcelWeaver weaver = new BcelWeaver(world);
try {
if (behave15)
UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath);
- weaver.addClassFile(classFile,false);
+ weaver.addClassFile(classFile, false);
weaver.setShadowMungers(planners);
weaveTestInner(weaver, classFile, name, outName);
} finally {
}
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());
}
// ----
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<ShadowMunger> makeAdviceAll(String kind, boolean matchOnlyPrintln) {
+ List<ShadowMunger> ret = new ArrayList<ShadowMunger>();
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(
return ret;
}
- public List makeAdviceAll(final String kind) {
+ public List<ShadowMunger> makeAdviceAll(final String kind) {
return makeAdviceAll(kind, false);
}
}
}
- protected void weaveTest(String[] inClassNames, String outKind, List patternMungers) throws IOException {
+ protected void weaveTest(String[] inClassNames, String outKind, List<ShadowMunger> patternMungers) throws IOException {
for (int i = 0; i < inClassNames.length; i++) {
String inFileName = inClassNames[i];
weaveTest(inFileName, outKind + inFileName, patternMungers);
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<IMessage> messages = new ArrayList<IMessage>();
+
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() {
// 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());
}
}
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.patterns;
import org.aspectj.weaver.UnresolvedType;
{
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;
}
}
* ******************************************************************/
package org.aspectj.weaver.reflect;
-
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
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<methods.length; i++) {
+ for (int i = 0; i < methods.length; i++) {
if (name.equals(methods[i].getName())) {
return i;
}
}
return -1;
}
-
+
protected int findMethod(String name, int numArgs, ResolvedMember[] methods) {
- for (int i=0; i<methods.length; i++) {
+ for (int i = 0; i < methods.length; i++) {
if (name.equals(methods[i].getName()) && (methods[i].getParameterTypes().length == numArgs)) {
return i;
}
}
return -1;
}
-
+
public void testGetDeclaredMethods() {
ResolvedMember[] methods = objectType.getDeclaredMethods();
assertEquals(Object.class.getDeclaredMethods().length + Object.class.getDeclaredConstructors().length, methods.length);
-
+
ResolvedType c = world.resolve("reflect.tests.C");
methods = c.getDeclaredMethods();
- assertEquals(3,methods.length);
+ assertEquals(3, methods.length);
int idx = findMethod("foo", methods);
assertTrue(idx > -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("<init>", 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() {
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 <clinit> (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 <clinit> (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<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("<clinit>")) 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("<clinit>"))
+ 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());