Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SubtypeConstructorCW.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import org.aspectj.testing.Tester;
  2. class C implements Runnable { // CW 5
  3. public void run() {
  4. }
  5. }
  6. class F implements Runnable {
  7. F(int i) {}// CW 10
  8. public void run() {
  9. }
  10. }
  11. /** @testcase PR#49295 extra warning (join point?) for typepattern-type execution */
  12. public class SubtypeConstructorCW {
  13. public static void main(String[] args) {
  14. new C().run();
  15. new D("").run();
  16. new E("", 0).run();
  17. new F(0).run();
  18. }
  19. }
  20. class D implements Runnable {
  21. D(String s) {
  22. }
  23. public void run() {
  24. }
  25. }
  26. class E implements Runnable {
  27. E(String s, int i) {
  28. }
  29. public void run() {
  30. }
  31. }
  32. // XXX warning: harness might ignore duplicates, so this can give false positives
  33. aspect A {
  34. static {
  35. Tester.expectEvents(
  36. new String[] {
  37. "before execution(C())",
  38. "before execution(F(int))",
  39. });
  40. }
  41. static void event(String s) {
  42. System.out.println(" \"" + s + "\",");
  43. }
  44. // getting two warning rather than one, and on wrong places
  45. declare warning : execution((Runnable +).new (..))
  46. && !execution(new (String,
  47. .
  48. .)) : "Runnable constructors should take String as first parameter";
  49. // this works as expected
  50. // declare warning: execution((!Runnable && Runnable+).new(..))
  51. // && !execution(new(String, ..))
  52. // : "Runnable constructors should take String as first parm";
  53. before() : execution((Runnable +).new (..))
  54. && !execution(new (String,..)) {
  55. event("before " + thisJoinPointStaticPart);
  56. }
  57. }