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.

BcelTestUtils.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* *******************************************************************
  2. * Copyright (c) 2008 Contributors
  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. * Andy Clement initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import org.aspectj.weaver.Advice;
  14. import org.aspectj.weaver.AdviceKind;
  15. import org.aspectj.weaver.Member;
  16. import org.aspectj.weaver.TestUtils;
  17. import org.aspectj.weaver.UnresolvedType;
  18. import org.aspectj.weaver.World;
  19. import org.aspectj.weaver.patterns.FormalBinding;
  20. import org.aspectj.weaver.patterns.Pointcut;
  21. import org.aspectj.weaver.patterns.SimpleScope;
  22. public class BcelTestUtils {
  23. /**
  24. * Moved from BcelWorld to here
  25. *
  26. * Parse a string into advice.
  27. *
  28. * <blockquote>
  29. *
  30. * <pre>
  31. * Kind ( Id , ... ) : Pointcut -&gt; MethodSignature
  32. * </pre>
  33. *
  34. * </blockquote>
  35. */
  36. public static Advice shadowMunger(World w, String str, int extraFlag) {
  37. str = str.trim();
  38. int start = 0;
  39. int i = str.indexOf('(');
  40. AdviceKind kind = AdviceKind.stringToKind(str.substring(start, i));
  41. start = ++i;
  42. i = str.indexOf(')', i);
  43. String[] ids = TestUtils.parseIds(str.substring(start, i).trim());
  44. // start = ++i;
  45. i = str.indexOf(':', i);
  46. start = ++i;
  47. i = str.indexOf("->", i);
  48. Pointcut pointcut = Pointcut.fromString(str.substring(start, i).trim());
  49. Member m = TestUtils.methodFromString(str.substring(i + 2, str.length()).trim());
  50. // now, we resolve
  51. UnresolvedType[] types = m.getParameterTypes();
  52. FormalBinding[] bindings = new FormalBinding[ids.length];
  53. for (int j = 0, len = ids.length; j < len; j++) {
  54. bindings[j] = new FormalBinding(types[j], ids[j], j, 0, 0);
  55. }
  56. Pointcut p = pointcut.resolve(new SimpleScope(w, bindings));
  57. return new BcelAdvice(kind, p, m, extraFlag, 0, 0, null, null);
  58. }
  59. }