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.

ModelCoverage.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import java.io.*;
  2. import java.util.List;
  3. interface I { }
  4. class Point {
  5. int x;
  6. static int sx;
  7. {
  8. System.out.println("");
  9. }
  10. { x = 0; }
  11. static { sx = 1; }
  12. public Point() { }
  13. public int getX() {
  14. return x;
  15. }
  16. public void setX(int x) {
  17. this.x = x;
  18. }
  19. public int changeX(int x) {
  20. this.x = x;
  21. return x;
  22. }
  23. void doIt() {
  24. try {
  25. File f = new File(".");
  26. f.getCanonicalPath();
  27. } catch (IOException ioe) {
  28. System.err.println("!");
  29. }
  30. setX(10);
  31. new Point();
  32. }
  33. }
  34. class SubPoint extends Point { }
  35. class Line { }
  36. aspect AdvisesRelationshipCoverage {
  37. pointcut methodExecutionP(): execution(void Point.setX(int));
  38. before(): methodExecutionP() { }
  39. pointcut constructorExecutionP(): execution(Point.new());
  40. before(): constructorExecutionP() { }
  41. pointcut callMethodP(): call(* Point.setX(int));
  42. before(): callMethodP() { }
  43. pointcut callConstructorP(): call(Point.new());
  44. before(): callConstructorP() { }
  45. pointcut getP(): get(int *.*);
  46. before(): getP() { }
  47. pointcut setP(): set(int *.*) && !set(int *.xxx);
  48. before(): setP() { }
  49. pointcut initializationP(): initialization(Point.new(..));
  50. before(): initializationP() { }
  51. pointcut staticinitializationP(): staticinitialization(Point);
  52. before(): staticinitializationP() { }
  53. pointcut handlerP(): handler(IOException);
  54. before(): handlerP() { }
  55. // before(): within(*) && execution(* Point.setX(..)) { }
  56. // before(): within(*) && execution(Point.new()) { }
  57. }
  58. aspect AdviceNamingCoverage {
  59. pointcut named(): call(* *.mumble());
  60. pointcut namedWithOneArg(int i): call(int Point.changeX(int)) && args(i);
  61. pointcut namedWithArgs(int i, int j): set(int Point.x) && args(i, j);
  62. after(): named() { }
  63. after(int i, int j) returning: namedWithArgs(i, j) { }
  64. after() throwing: named() { }
  65. after(): named() { }
  66. before(): named() { }
  67. int around(int i): namedWithOneArg(i) { return i;}
  68. int around(int i) throws SizeException: namedWithOneArg(i) { return proceed(i); }
  69. before(): named() { }
  70. before(int i): call(* *.mumble()) && named() && namedWithOneArg(i) { }
  71. before(int i): named() && call(* *.mumble()) && namedWithOneArg(i) { }
  72. before(): call(* *.mumble()) { }
  73. }
  74. abstract aspect AbstractAspect {
  75. abstract pointcut abPtct();
  76. }
  77. aspect InterTypeDecCoverage {
  78. public int Point.xxx = 0;
  79. public int Point.check(int i, Line l) { return 1 + i; }
  80. }
  81. aspect DeclareCoverage {
  82. pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..));
  83. declare error: illegalNewFigElt(): "Illegal constructor call.";
  84. declare warning: call(* Point.setX(..)): "Illegal call.";
  85. declare parents: Point extends java.io.Serializable;
  86. declare parents: Point+ implements java.util.Observable;
  87. declare parents: Point && Line implements java.util.Observable;
  88. declare soft: SizeException : call(* Point.getX());
  89. declare precedence: AdviceCoverage, InterTypeDecCoverage, *;
  90. // public Line.new(String s) { }
  91. }
  92. class SizeException extends Exception { }
  93. aspect AdviceCoverage {
  94. }
  95. abstract class ModifiersCoverage {
  96. private int a;
  97. protected int b;
  98. public int c;
  99. int d;
  100. static int staticA;
  101. final int finalA = 0;
  102. abstract void abstractM();
  103. }
  104. aspect Pointcuts {
  105. pointcut a(): call(Point.new(..));
  106. }
  107. aspect PointcutUsage {
  108. pointcut usesA(): Pointcuts.a() && within(Point);
  109. pointcut usesUsesA(): usesA();
  110. after(): usesUsesA() { }
  111. }