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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import org.aspectj.apache.bcel.generic.InstructionFactory;
  16. import org.aspectj.weaver.NameMangler;
  17. import org.aspectj.weaver.Shadow;
  18. public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
  19. {
  20. regenerate = false;
  21. }
  22. public MoveInstructionsWeaveTestCase(String name) {
  23. super(name);
  24. }
  25. public void testHello() throws IOException {
  26. BcelAdvice p = new BcelAdvice(null, makePointcutAll(), null, 0, -1, -1, null, null) {
  27. public void specializeOn(Shadow s) {
  28. super.specializeOn(s);
  29. ((BcelShadow) s).initializeForAroundClosure();
  30. }
  31. public boolean implementOn(Shadow s) {
  32. BcelShadow shadow = (BcelShadow) s;
  33. LazyMethodGen newMethod = shadow.extractShadowInstructionsIntoNewMethod(NameMangler.getExtractableName(shadow
  34. .getSignature())
  35. + "_extracted", 0, this.getSourceLocation(), new ArrayList(),shadow.getEnclosingClass().isInterface());
  36. shadow.getRange().append(shadow.makeCallToCallback(newMethod));
  37. if (!shadow.isFallsThrough()) {
  38. shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
  39. }
  40. return true;
  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 boolean implementOn(Shadow s) {
  53. BcelShadow shadow = (BcelShadow) s;
  54. LazyMethodGen newMethod =
  55. shadow.extractShadowInstructionsIntoNewMethod(NameMangler.getExtractableName(shadow
  56. .getSignature())
  57. + "_extracted" + counter++, 0, this.getSourceLocation(), new ArrayList(),shadow.getEnclosingClass().isInterface());
  58. shadow.getRange().append(shadow.makeCallToCallback(newMethod));
  59. if (!shadow.isFallsThrough()) {
  60. shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
  61. }
  62. return true;
  63. }
  64. };
  65. weaveTest("FancyHelloWorld", "ExtractedFancyHelloWorld", p);
  66. }
  67. }