You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MoveInstructionsWeaveTestCase.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.*;
  14. import org.aspectj.apache.bcel.generic.InstructionFactory;
  15. import org.aspectj.weaver.*;
  16. public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
  17. {
  18. regenerate = false;
  19. }
  20. public MoveInstructionsWeaveTestCase(String name) {
  21. super(name);
  22. }
  23. public void testHello() throws IOException {
  24. BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
  25. public void specializeOn(Shadow s) {
  26. super.specializeOn(s);
  27. ((BcelShadow) s).initializeForAroundClosure();
  28. }
  29. public void implementOn(Shadow s) {
  30. BcelShadow shadow = (BcelShadow) s;
  31. LazyMethodGen newMethod =
  32. shadow.extractMethod(
  33. shadow.getSignature().getExtractableName() + "_extracted",
  34. 0,
  35. this);
  36. shadow.getRange().append(shadow.makeCallToCallback(newMethod));
  37. if (!shadow.isFallsThrough()) {
  38. shadow.getRange().append(
  39. InstructionFactory.createReturn(newMethod.getReturnType()));
  40. }
  41. }
  42. };
  43. weaveTest("HelloWorld", "ExtractedHelloWorld", p);
  44. }
  45. static int counter = 0;
  46. public void testFancyHello() throws IOException {
  47. BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
  48. public void specializeOn(Shadow s) {
  49. super.specializeOn(s);
  50. ((BcelShadow) s).initializeForAroundClosure();
  51. }
  52. public void implementOn(Shadow s) {
  53. BcelShadow shadow = (BcelShadow) s;
  54. LazyMethodGen newMethod = shadow.extractMethod(shadow.getSignature().getExtractableName() + "_extracted" + counter++, 0, this);
  55. shadow.getRange().append(shadow.makeCallToCallback(newMethod));
  56. if (! shadow.isFallsThrough()) {
  57. shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
  58. }
  59. }
  60. };
  61. weaveTest("FancyHelloWorld", "ExtractedFancyHelloWorld", p);
  62. }
  63. }