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.

ExecutionPointcutMatchingParamAndReturnTypes.aj 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import java.util.*;
  2. public aspect ExecutionPointcutMatchingParamAndReturnTypes {
  3. // rule 3) a raw parameter pattern matches any parameterized type
  4. declare warning : execution(Generic.new(List))
  5. : "raw param type matching in execution ok";
  6. declare warning : execution(List UglyBuilding.foo())
  7. : "raw return type matching in execution ok";
  8. // rule 4) A param type declared using a type variable is matched by its erasure
  9. declare warning : execution(Generic.new(Object))
  10. : "erasure type matching in execution ok";
  11. declare warning : execution(Object Generic.foo())
  12. : "erasure type matching in execution ok";
  13. // rule 5) no join points in bridge methods
  14. declare warning : execution(void UglyBuilding.iSee(String))
  15. : "execution and parameterized method ok";
  16. declare warning : execution(* ISore.*(..))
  17. : "execution and generic interface ok";
  18. declare warning : execution(* I2.*(..))
  19. : "execution and interface control test";
  20. declare warning : execution(void UglyBuilding.iSee(Object))
  21. : "should be no join points for bridge methods";
  22. // rule 6) parameterized types in return and args can be matched exactly
  23. declare warning : execution(Generic.new(List<String>)) : "match on parameterized args";
  24. declare warning : execution(List<Number> *(..)) : "match on parameterized return type";
  25. }
  26. class Generic<T> {
  27. int x;
  28. public Generic(List<String> ls) {
  29. x = 5;
  30. }
  31. public Generic(T t) {
  32. x = 6;
  33. }
  34. T foo() { x = 7; return null; }
  35. }
  36. interface ISore<E> {
  37. void iSee(E anE);
  38. }
  39. interface I2 {
  40. void ic2it();
  41. }
  42. class UglyBuilding implements ISore<String>, I2 {
  43. int y;
  44. // this class will have a bridge method with signature void iSee(Object), with a cast and call
  45. // to the method below
  46. public void iSee(String s) {
  47. y = 2;
  48. }
  49. public void ic2it() { y = 4; }
  50. List<Number> foo() { y = 1; return null; }
  51. }