multithreading.atl 1.3 KB
Newer Older
Gerson Sunyé's avatar
Gerson Sunyé committed
1
2
3
library multithreading;


Gerson Sunyé's avatar
Gerson Sunyé committed
4
5
6
7
8
9
10
11
12
13
--- Goes through all the variables to check if the following rule is followed:
--- Avoid using java.lang.ThreadGroup;
helper def: avoidThreadGroup() : Set(smm!Measure) =
    java!VariableDeclarationStatement.allInstances()
		-> select(variable | variable.type.type.name = 'ThreadGroup')
		-> collect(variable | thisModule.measureAvoidThreadGroup(variable) );


--- Goes through all the methods to check if the following rule is followed:
--- Don't call Thread.run()
Gerson Sunyé's avatar
Gerson Sunyé committed
14
helper def: dontCallThreadRun() : Set(smm!Measure) =
15
16
17
18
		java!MethodDeclaration.allInstances()
			 -> select (m | m.name='run' )
			 -> select (m | m.abstractTypeDeclaration <> OclUndefined )
			 -> select (m | m.abstractTypeDeclaration.name = 'Thread' )
19
20
			 -> collect (m | thisModule.MeasureDontCallThreadRun(m));

Gerson Sunyé's avatar
Gerson Sunyé committed
21
--- Returns a set of measures each time the method 'notify()' is used instead of 'notifyAll()'
22
23
24
25
26
27
28
29
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)))
;