multithreading.atl 1.58 KB
Newer Older
Gerson Sunyé's avatar
Gerson Sunyé committed
1
2
3
4
5
6
7
library multithreading;

--------------------------------------------- DontCallThreadRun ---------------------------------------------

--Goes through all the methods to check if the following rule is followed:
--Don't call Thread.run()
helper def: dontCallThreadRun() : Set(smm!Measure) =
8
9
		java!MethodInvocation.allInstances()
			 -> select (m | m.method.name='run' )
10
			 -> select (m | m.method.abstractTypeDeclaration.name = 'Thread' )
11
12
			 -> collect (m | thisModule.MeasureDontCallThreadRun(m));

Gerson Sunyé's avatar
Gerson Sunyé committed
13
14
15
16
17
--------------------------------------------- AvoidThreadGroup  ---------------------------------------------

--Goes through all the variables to check if the following rule is followed:
--Avoid using java.lang.ThreadGroup;
helper def: avoidThreadGroup() : Set(smm!Measure) =
18
19
20
    java!VariableDeclarationStatement.allInstances()
		-> select(variable | variable.type.type.name = 'ThreadGroup')
		-> collect(variable | thisModule.measureAvoidThreadGroup(variable) );
21
22
23
24
25
26
27
28
29
30
31
32
	
--------------------------------------------- UseNotifyAllInsteadOfNotify ---------------------------------------------

-- Returns a set of measures each time the method 'notify()' is used instead of 'notifyAll()'
helper def: useNotifyAllInsteadOfNotify(): Set(smm!Measure) =
	
	-- Get the method declarations of notify() and for each of their MethodInvocation usages, create a measure
	java!MethodDeclaration.allInstances()
		->select(methodDeclaration | methodDeclaration.name = 'notify')
		->collect (methodDeclaration |methodDeclaration.usages
			->collect(methodInvocation | thisModule.MeasureUseNotifyAllInsteadOfNotify(methodInvocation)))
;