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.

ShadowMunger.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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;
  13. import java.util.Collection;
  14. import org.aspectj.bridge.ISourceLocation;
  15. import org.aspectj.util.PartialOrder;
  16. import org.aspectj.weaver.patterns.PerClause;
  17. import org.aspectj.weaver.patterns.Pointcut;
  18. /**
  19. * For every shadow munger, nothing can be done with it until it is concretized. Then...
  20. *
  21. * (Then we call fast match.)
  22. *
  23. * For every shadow munger, for every shadow,
  24. * first match is called,
  25. * then (if match returned true) the shadow munger is specialized for the shadow,
  26. * which may modify state.
  27. * Then implement is called.
  28. */
  29. public abstract class ShadowMunger implements PartialOrder.PartialComparable, IHasPosition {
  30. protected Pointcut pointcut;
  31. // these three fields hold the source location of this munger
  32. protected int start, end;
  33. protected ISourceContext sourceContext;
  34. public ShadowMunger(Pointcut pointcut, int start, int end, ISourceContext sourceContext) {
  35. this.pointcut = pointcut;
  36. this.start = start;
  37. this.end = end;
  38. this.sourceContext = sourceContext;
  39. }
  40. public abstract ShadowMunger concretize(ResolvedTypeX fromType, World world, PerClause clause);
  41. public abstract void specializeOn(Shadow shadow);
  42. public abstract void implementOn(Shadow shadow);
  43. /**
  44. * All overriding methods should call super
  45. */
  46. public boolean match(Shadow shadow, World world) {
  47. return pointcut.match(shadow).maybeTrue();
  48. }
  49. public int fallbackCompareTo(Object other) {
  50. return toString().compareTo(toString());
  51. }
  52. public int getEnd() {
  53. return end;
  54. }
  55. public int getStart() {
  56. return start;
  57. }
  58. public ISourceLocation getSourceLocation() {
  59. //System.out.println("get context: " + this + " is " + sourceContext);
  60. if (sourceContext == null) {
  61. //System.err.println("no context: " + this);
  62. return null;
  63. }
  64. return sourceContext.makeSourceLocation(this);
  65. }
  66. // ---- fields
  67. public static final ShadowMunger[] NONE = new ShadowMunger[0];
  68. public Pointcut getPointcut() {
  69. return pointcut;
  70. }
  71. /**
  72. * @return a Collection of ResolvedTypeX for all checked exceptions that
  73. * might be thrown by this munger
  74. */
  75. public abstract Collection getThrownExceptions();
  76. }