private ExposedState exposedState;
public BcelAdvice(AjAttribute.AdviceAttribute attribute, Pointcut pointcut, Member signature, ResolvedType concreteAspect) {
- super(attribute, pointcut, shrink(attribute.getKind(), concreteAspect, signature));//(signature==null?null:signature.slimline
+ super(attribute, pointcut, shrink(attribute.getKind(), concreteAspect, signature));// (signature==null?null:signature.slimline
// ()));
this.concreteAspect = concreteAspect;
}
if (bm.getMethod() != null && bm.getMethod().getAnnotations() != null)
return m;
ResolvedMemberImpl simplermember = new ResolvedMemberImpl(bm.getKind(), bm.getDeclaringType(), bm.getModifiers(),
- bm.getReturnType(), bm.getName(), bm.getParameterTypes());//,bm.getExceptions(),bm.getBackingGenericMember()
+ bm.getReturnType(), bm.getName(), bm.getParameterTypes());// ,bm.getExceptions(),bm.getBackingGenericMember()
// );
simplermember.setParameterNames(bm.getParameterNames());
return simplermember;
return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven();
}
- public void implementOn(Shadow s) {
+ public boolean implementOn(Shadow s) {
hasMatchedAtLeastOnce = true;
BcelShadow shadow = (BcelShadow) s;
// It might be dangerous to change that especially for @AJ aspect non compiled with AJC since if those
// are not weaved (f.e. use of some limiteed LTW etc) then they cannot be prepared for inlining.
// One solution would be to flag @AJ aspect with an annotation as "prepared" and query that one.
+ LazyClassGen enclosingClass = shadow.getEnclosingClass();
+ if (enclosingClass != null && enclosingClass.isInterface() && shadow.getEnclosingMethod().getName().charAt(0) == '<') {
+ // Do not add methods with bodies to an interface (252198, 163005)
+ shadow.getWorld().getLint().cannotAdviseJoinpointInInterfaceWithAroundAdvice.signal(shadow.toString(), shadow
+ .getSourceLocation());
+ return false;
+ }
if (!canInline(s)) {
shadow.weaveAroundClosure(this, hasDynamicTests());
} else {
} else {
throw new BCException("unimplemented kind: " + getKind());
}
+ return true;
}
private void removeUnnecessaryProblems(BcelMethod method, int problemLineNumber) {
* method-execution, then the new method for the advice can also be re-lined. We are not doing that presently.
*/
public void weaveAroundInline(BcelAdvice munger, boolean hasDynamicTest) {
-
// !!! THIS BLOCK OF CODE SHOULD BE IN A METHOD CALLED weaveAround(...);
Member mungerSig = munger.getSignature();
// Member originalSig = mungerSig; // If mungerSig is on a parameterized type, originalSig is the member on the generic type
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.World;
import org.aspectj.weaver.patterns.Pointcut;
public class IdWeaveTestCase extends WeaveTestCase {
public IdWeaveTestCase(String name) {
super(name);
}
-
- public void testFancyId() throws IOException {
- final List l = new ArrayList();
+
+ public void testFancyId() throws IOException {
+ final List l = new ArrayList();
Pointcut pointcut2 = makePointcutAll();
- BcelAdvice p =
- new BcelAdvice(null, pointcut2, null, 0, -1, -1, null, null) {
- public boolean match(Shadow shadow, World world) {
- if (super.match(shadow, world)) {
- l.add(shadow);
- }
- return false;
- }
- };
- weaveTest(new String[] {"FancyHelloWorld"}, "Id2", p);
-
- checkShadowSet(l, new String[] {
- "method-call(void java.io.PrintStream.println(java.lang.Object))",
- "method-call(void java.io.PrintStream.println(java.lang.String))",
- "method-call(java.lang.StringBuffer java.lang.StringBuffer.append(int))",
- "method-call(java.lang.String java.lang.StringBuffer.toString())",
- "method-execution(java.lang.String FancyHelloWorld.getName())",
- "field-get(java.io.PrintStream java.lang.System.out)",
- "method-call(void java.io.PrintStream.println(java.lang.String))",
- "method-execution(void FancyHelloWorld.main(java.lang.String[]))",
- "method-call(int java.lang.String.hashCode())",
- "constructor-execution(void FancyHelloWorld.<init>())",
- "constructor-call(void java.lang.StringBuffer.<init>(java.lang.String))"
- });
- }
+ BcelAdvice p = new BcelAdvice(null, pointcut2, null, 0, -1, -1, null, null) {
+ public boolean match(Shadow shadow, World world) {
+ if (super.match(shadow, world)) {
+ l.add(shadow);
+ }
+ return false;
+ }
+ };
+ weaveTest(new String[] { "FancyHelloWorld" }, "Id2", p);
+
+ checkShadowSet(l, new String[] { "method-call(void java.io.PrintStream.println(java.lang.Object))",
+ "method-call(void java.io.PrintStream.println(java.lang.String))",
+ "method-call(java.lang.StringBuffer java.lang.StringBuffer.append(int))",
+ "method-call(java.lang.String java.lang.StringBuffer.toString())",
+ "method-execution(java.lang.String FancyHelloWorld.getName())",
+ "field-get(java.io.PrintStream java.lang.System.out)",
+ "method-call(void java.io.PrintStream.println(java.lang.String))",
+ "method-execution(void FancyHelloWorld.main(java.lang.String[]))", "method-call(int java.lang.String.hashCode())",
+ "constructor-execution(void FancyHelloWorld.<init>())",
+ "constructor-call(void java.lang.StringBuffer.<init>(java.lang.String))" });
+ }
+
+ public void testId() throws IOException {
+ final List l = new ArrayList();
+ BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
+ public boolean implementOn(Shadow shadow) {
+ l.add(shadow);
+ return true;
+ }
+ };
+ weaveTest(new String[] { "HelloWorld" }, "Id2", p);
+ checkShadowSet(l, new String[] { "method-execution(void HelloWorld.main(java.lang.String[]))",
+ "method-call(void java.io.PrintStream.println(java.lang.String))",
+ "field-get(java.io.PrintStream java.lang.System.out)", "constructor-execution(void HelloWorld.<init>())", });
+ }
- public void testId() throws IOException {
- final List l = new ArrayList();
- BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
- public void implementOn(Shadow shadow) {
- l.add(shadow);
- }
- };
- weaveTest(new String[] {"HelloWorld"}, "Id2", p);
-
- checkShadowSet(l, new String[] {
- "method-execution(void HelloWorld.main(java.lang.String[]))",
- "method-call(void java.io.PrintStream.println(java.lang.String))",
- "field-get(java.io.PrintStream java.lang.System.out)",
- "constructor-execution(void HelloWorld.<init>())",
- });
- }
-
- // this test requires that Trace has been unzipped and placed in the correct place
-// public void testTraceId() throws IOException {
-// String saveClassDir = classDir;
-// try {
-// classDir = "testdata/dummyAspect.jar";
-//
-//
-//
-// final List l = new ArrayList();
-// BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
-// public void implementOn(Shadow shadow) {
-// l.add(shadow);
-// }
-// };
-// boolean tempRunTests = runTests;
-// runTests = false;
-// weaveTest(new String[] {"DummyAspect"}, "Id", p);
-// runTests = tempRunTests;
-//
-// checkShadowSet(l, new String[] {
-// "constructor-execution(void DummyAspect.<init>())",
-// // XXX waiting on parser stuff
-// //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))",
-// });
-// } finally {
-// classDir = saveClassDir;
-// }
-// }
+ // this test requires that Trace has been unzipped and placed in the correct place
+ // public void testTraceId() throws IOException {
+ // String saveClassDir = classDir;
+ // try {
+ // classDir = "testdata/dummyAspect.jar";
+ //
+ //
+ //
+ // final List l = new ArrayList();
+ // BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
+ // public void implementOn(Shadow shadow) {
+ // l.add(shadow);
+ // }
+ // };
+ // boolean tempRunTests = runTests;
+ // runTests = false;
+ // weaveTest(new String[] {"DummyAspect"}, "Id", p);
+ // runTests = tempRunTests;
+ //
+ // checkShadowSet(l, new String[] {
+ // "constructor-execution(void DummyAspect.<init>())",
+ // // XXX waiting on parser stuff
+ // //"advice-execution(void DummyAspect.ajc_before_1(java.lang.Object))",
+ // });
+ // } finally {
+ // classDir = saveClassDir;
+ // }
+ // }
}
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
-import java.io.*;
+import java.io.IOException;
import org.aspectj.apache.bcel.generic.InstructionFactory;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.NameMangler;
+import org.aspectj.weaver.Shadow;
public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
{
public MoveInstructionsWeaveTestCase(String name) {
super(name);
}
- public void testHello() throws IOException {
- BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
- public void specializeOn(Shadow s) {
- super.specializeOn(s);
- ((BcelShadow) s).initializeForAroundClosure();
- }
- public void implementOn(Shadow s) {
+
+ public void testHello() throws IOException {
+ BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
+ public void specializeOn(Shadow s) {
+ super.specializeOn(s);
+ ((BcelShadow) s).initializeForAroundClosure();
+ }
+
+ public boolean implementOn(Shadow s) {
BcelShadow shadow = (BcelShadow) s;
- LazyMethodGen newMethod =
- shadow.extractMethod(
- NameMangler.getExtractableName(shadow.getSignature()) + "_extracted",
- 0,
- this);
+ LazyMethodGen newMethod = shadow.extractMethod(
+ NameMangler.getExtractableName(shadow.getSignature()) + "_extracted", 0, this);
shadow.getRange().append(shadow.makeCallToCallback(newMethod));
if (!shadow.isFallsThrough()) {
- shadow.getRange().append(
- InstructionFactory.createReturn(newMethod.getReturnType()));
+ shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
}
+ return true;
}
- };
+ };
+
+ weaveTest("HelloWorld", "ExtractedHelloWorld", p);
+ }
+
+ static int counter = 0;
- weaveTest("HelloWorld", "ExtractedHelloWorld", p);
- }
-
- static int counter = 0;
public void testFancyHello() throws IOException {
BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
- public void specializeOn(Shadow s) {
- super.specializeOn(s);
- ((BcelShadow) s).initializeForAroundClosure();
- }
- public void implementOn(Shadow s) {
- BcelShadow shadow = (BcelShadow) s;
- LazyMethodGen newMethod = shadow.extractMethod(NameMangler.getExtractableName(shadow.getSignature()) + "_extracted" + counter++, 0, this);
- shadow.getRange().append(shadow.makeCallToCallback(newMethod));
+ public void specializeOn(Shadow s) {
+ super.specializeOn(s);
+ ((BcelShadow) s).initializeForAroundClosure();
+ }
+
+ public boolean implementOn(Shadow s) {
+ BcelShadow shadow = (BcelShadow) s;
+ LazyMethodGen newMethod = shadow.extractMethod(NameMangler.getExtractableName(shadow.getSignature()) + "_extracted"
+ + counter++, 0, this);
+ shadow.getRange().append(shadow.makeCallToCallback(newMethod));
- if (! shadow.isFallsThrough()) {
- shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
- }
- }
- };
+ if (!shadow.isFallsThrough()) {
+ shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
+ }
+ return true;
+ }
+ };
weaveTest("FancyHelloWorld", "ExtractedFancyHelloWorld", p);
}
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
-import java.io.*;
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
-import org.aspectj.weaver.*;
-import org.aspectj.weaver.patterns.*;
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.VersionedDataInputStream;
+import org.aspectj.weaver.patterns.FormalBinding;
+import org.aspectj.weaver.patterns.Pointcut;
+import org.aspectj.weaver.patterns.SimpleScope;
public class PatternWeaveTestCase extends WeaveTestCase {
{
regenerate = false;
}
-
+
public PatternWeaveTestCase(String name) {
super(name);
}
-
- String[] none = new String[0];
- //XXX this test is incompatible with optimizations made to weaver
+ String[] none = new String[0];
+
+ // XXX this test is incompatible with optimizations made to weaver
public void testPublic() throws IOException {
- String[] publicHello = new String[] {
- "method-execution(void HelloWorld.main(java.lang.String[]))",
- };
- String[] publicFancyHello = new String[] {
- "method-execution(void FancyHelloWorld.main(java.lang.String[]))",
- "method-execution(java.lang.String FancyHelloWorld.getName())",
- };
+ String[] publicHello = new String[] { "method-execution(void HelloWorld.main(java.lang.String[]))", };
+ String[] publicFancyHello = new String[] { "method-execution(void FancyHelloWorld.main(java.lang.String[]))",
+ "method-execution(java.lang.String FancyHelloWorld.getName())", };
checkPointcut("execution(public * *(..))", publicHello, publicFancyHello);
}
-//
-// public void testPrintln() throws IOException {
-// String[] callPrintlnHello = new String[] {
-// "method-call(void java.io.PrintStream.println(java.lang.String))",
-// };
-// String[] callPrintlnFancyHello = new String[] {
-// "method-call(void java.io.PrintStream.println(java.lang.String))",
-// "method-call(void java.io.PrintStream.println(java.lang.String))",
-// "method-call(void java.io.PrintStream.println(java.lang.Object))",
-// };
-// checkPointcut("call(* println(*))", callPrintlnHello, callPrintlnFancyHello);
-// }
-//
-// public void testMumble() throws IOException {
-// checkPointcut("call(* mumble(*))", none, none);
-// }
-//
-// public void testFooBar() throws IOException {
-// checkPointcut("call(FooBar *(..))", none, none);
-// }
-//
-// public void testGetOut() throws IOException {
-// String[] getOutHello = new String[] {
-// "field-get(java.io.PrintStream java.lang.System.out)",
-// };
-//
-// checkPointcut("get(* java.lang.System.out)", getOutHello, getOutHello);
-// }
-//
-//// private Pointcut makePointcut(String s) {
-//// return new PatternParser(s).parsePointcut();
-//// }
-//
- private void checkPointcut(String pointcutSource, String[] expectedHelloShadows,
- String[] expectedFancyShadows) throws IOException
- {
- Pointcut sp = Pointcut.fromString(pointcutSource);
- Pointcut rp = sp.resolve(new SimpleScope(world, FormalBinding.NONE));
- Pointcut cp = rp.concretize(ResolvedType.MISSING, ResolvedType.MISSING, 0);
-
- final List l = new ArrayList();
- BcelAdvice p = new BcelAdvice(null, cp, null, 0, -1, -1, null, null) {
- public void implementOn(Shadow shadow) {
- l.add(shadow);
- }
- };
- weaveTest(new String[] {"HelloWorld"}, "PatternWeave", p);
-
- checkShadowSet(l, expectedHelloShadows);
-
-
- l.clear();
- weaveTest(new String[] {"FancyHelloWorld"}, "PatternWeave", p);
-
- checkShadowSet(l, expectedFancyShadows);
-
- checkSerialize(rp);
- }
-
+
+ //
+ // public void testPrintln() throws IOException {
+ // String[] callPrintlnHello = new String[] {
+ // "method-call(void java.io.PrintStream.println(java.lang.String))",
+ // };
+ // String[] callPrintlnFancyHello = new String[] {
+ // "method-call(void java.io.PrintStream.println(java.lang.String))",
+ // "method-call(void java.io.PrintStream.println(java.lang.String))",
+ // "method-call(void java.io.PrintStream.println(java.lang.Object))",
+ // };
+ // checkPointcut("call(* println(*))", callPrintlnHello, callPrintlnFancyHello);
+ // }
+ //
+ // public void testMumble() throws IOException {
+ // checkPointcut("call(* mumble(*))", none, none);
+ // }
+ //
+ // public void testFooBar() throws IOException {
+ // checkPointcut("call(FooBar *(..))", none, none);
+ // }
+ //
+ // public void testGetOut() throws IOException {
+ // String[] getOutHello = new String[] {
+ // "field-get(java.io.PrintStream java.lang.System.out)",
+ // };
+ //
+ // checkPointcut("get(* java.lang.System.out)", getOutHello, getOutHello);
+ // }
+ //
+ // // private Pointcut makePointcut(String s) {
+ // // return new PatternParser(s).parsePointcut();
+ // // }
+ //
+ private void checkPointcut(String pointcutSource, String[] expectedHelloShadows, String[] expectedFancyShadows)
+ throws IOException {
+ Pointcut sp = Pointcut.fromString(pointcutSource);
+ Pointcut rp = sp.resolve(new SimpleScope(world, FormalBinding.NONE));
+ Pointcut cp = rp.concretize(ResolvedType.MISSING, ResolvedType.MISSING, 0);
+
+ final List l = new ArrayList();
+ BcelAdvice p = new BcelAdvice(null, cp, null, 0, -1, -1, null, null) {
+ public boolean implementOn(Shadow shadow) {
+ l.add(shadow);
+ return true;
+ }
+ };
+ weaveTest(new String[] { "HelloWorld" }, "PatternWeave", p);
+
+ checkShadowSet(l, expectedHelloShadows);
+
+ l.clear();
+ weaveTest(new String[] { "FancyHelloWorld" }, "PatternWeave", p);
+
+ checkShadowSet(l, expectedFancyShadows);
+
+ checkSerialize(rp);
+ }
+
public void checkSerialize(Pointcut p) throws IOException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bo);
p.write(out);
out.close();
-
+
ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
VersionedDataInputStream in = new VersionedDataInputStream(bi);
Pointcut newP = Pointcut.read(in, null);
-
- assertEquals("write/read", p, newP);
- }
+ assertEquals("write/read", p, newP);
+ }
}