summaryrefslogtreecommitdiffstats
path: root/ajde/testdata/examples/coverage/ModelCoverage.java
blob: 075bddc3b978284150d607cb985b8876bda72346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import java.io.*;

class Point { 
	int x;
	static int sx;

	{ x = 0; }
	static { sx = 1; }
	
	public Point() { }
	
	public int getX() { 
		return x;	
	}
	
	public void setX(int x) { 
		this.x = x; 
	}
	 
	public int changeX(int x) { 
		this.x = x;
		return x;
	}
	
	void doIt() { 
		try {
			File f = new File(".");
			f.getCanonicalPath();
		} catch (IOException ioe) {
			System.err.println("!");	
		}	
		setX(10);
		new Point();
	}
} 

class SubPoint extends Point { }

class Line { }

aspect AdvisesRelationshipCoverage {
	pointcut methodExecutionP(): execution(void Point.setX(int));
	before(): methodExecutionP() { }
  
	pointcut constructorExecutionP(): execution(Point.new());
	before(): constructorExecutionP() { }

	pointcut callMethodP(): call(* Point.setX(int));
	before(): callMethodP() { }

	pointcut callConstructorP(): call(Point.new());
	before(): callConstructorP() { }

	pointcut getP(): get(int *.*);
	before(): getP() { }

	pointcut setP(): set(int *.*);
	before(): setP() { }

	pointcut initializationP(): initialization(Point.new(..));
	before(): initializationP() { }

	pointcut staticinitializationP(): staticinitialization(Point);
	before(): staticinitializationP() { }

	pointcut handlerP(): handler(IOException);
	before(): handlerP() { }

//    before(): within(*) && execution(* Point.setX(..)) { }
//    before(): within(*) && execution(Point.new()) { }
}

aspect AdviceNamingCoverage {
	pointcut named(): call(* *.mumble());
	pointcut namedWithOneArg(int i): call(int Point.changeX(int)) && args(i);
	pointcut namedWithArgs(int i, int j): set(int Point.x) && args(i, j);

	after(): named() { }	
	after(int i, int j) returning: namedWithArgs(i, j) { }
	after() throwing: named() { }
	after(): named() { } 
	
	before(): named() { }
	
	int around(int i): namedWithOneArg(i) { return i;}
	int around(int i) throws SizeException: namedWithOneArg(i) { return proceed(i); }
	
	before(): named() { }	
	before(int i): call(* *.mumble()) && named() && namedWithOneArg(i) { }	
	before(int i): named() && call(* *.mumble()) && namedWithOneArg(i) { }	
	
	before(): call(* *.mumble()) { }
}
  
abstract aspect AbstractAspect {
	abstract pointcut abPtct();	
}
  
aspect InterTypeDecCoverage {
    public int Point.xxx = 0;
    public int Point.check(int i, Line l) { return 1 + i; }
}

aspect DeclareCoverage {

    pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..));

    declare error: illegalNewFigElt(): "Illegal constructor call.";
    declare warning: illegalNewFigElt(): "Illegal constructor call.";

    declare parents: Point extends java.io.Serializable;
    declare parents: Point+ implements java.util.Observable;
	declare parents: Point && Line implements java.util.Observable;
    declare soft: SizeException : call(* Point.getX());
	declare precedence: AdviceCoverage, InterTypeDecCoverage, *;
//	public Line.new(String s) {  }
}

class SizeException extends Exception { } 

aspect AdviceCoverage {

}