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) = java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} | if (thisModule.isDontCallThreadRun(i)) then res->union(Set{thisModule.MeasureDontCallThreadRun(i)}) else res endif ); --Detect a wrong usage of the method Thread.run() --return true if run() is called on a Thread variable or on a Thread instance creation helper def:isDontCallThreadRun(s:java!MethodInvocation): Boolean = if s.method.name = 'run' then --check if the method is called like this: --t.run() where t is of type Thread if s.expression.oclType().toString() = 'java!SingleVariableAccess' then if s.expression.variable.variablesContainer.type.type.name.toString() = 'Thread' then true else false endif --check if the method run is called like this: --new Thread().run(); else if s.expression.oclType().toString() = 'java!ClassInstanceCreation' then if s.expression.method.name.toString() = 'Thread' then true else false endif else false endif endif else false endif; --------------------------------------------- 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) = java!VariableDeclarationFragment.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} | if (thisModule.isThreadGroup(i)) then res->union(Set{thisModule.measureAvoidThreadGroup(i)}) else res endif ); --Detect a wrong usage of the variable type java.lang.ThreadGroup --return true if the variable of type java.lang.ThreadGroup helper def:isThreadGroup(s:java!VariableDeclarationFragment): Boolean = if s.variablesContainer.type.type.name.toString() = 'ThreadGroup' then true else false endif;