bestPractices.atl 905 Bytes
Newer Older
Raphael PAGE's avatar
Raphael PAGE committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library bestPractices;

--------------------------------------------- AvoidPrintStackTrace ---------------------------------------------

--Goes through all the methods to check if the following rule is followed:
--Avoid printStackTrace()
helper def: avoidPrintStackTrace() : Set(smm!Measure) =
	java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
		-- Add a new measurement if the argument of String.indexOf() is not of type char when checking for the index of a single character
		if thisModule.isAvoidPrintStackTrace(i) then
			res->union(Set{thisModule.MeasureAvoidPrintStackTrace(i)})
		else 
			res
		endif
	);

--Detect a wrong usage of the method printStackTrace()
--return true if the method is called printStackTrace
helper def:isAvoidPrintStackTrace(s:java!MethodInvocation): Boolean =
		if s.method.name = 'printStackTrace' then
			true
		else
			false
		endif;