Commit 1072a31a authored by Roxane MARECHAL's avatar Roxane MARECHAL Committed by Gerson SUNYE
Browse files

Fix #882 UseNotifyAllInsteadOfNotify

parent f76ebe91
......@@ -11,4 +11,4 @@ target/
/metrics.xmi
*.launch
!analysis.launch
\ No newline at end of file
!analysis.launch
......@@ -44,8 +44,8 @@
<mapEntry key="OUT" value="smm"/>
</mapAttribute>
<mapAttribute key="Path">
<mapEntry key="IN" value="/projet-2019/input/avoid-field-name-matching-method-name.xmi"/>
<mapEntry key="OUT" value="/projet-2019/output/test.xmi"/>
<mapEntry key="IN" value="/projet-2019/input/use-notify-all-instead-of-notify.xmi"/>
<mapEntry key="OUT" value="/projet-2019/output/metrics.xmi"/>
<mapEntry key="java" value="uri:http://www.eclipse.org/MoDisco/Java/0.2.incubation/java"/>
<mapEntry key="smm" value="uri:http://www.eclipse.org/MoDisco/SMM/1.0.Beta2/smm"/>
</mapAttribute>
......
This diff is collapsed.
......@@ -9,6 +9,7 @@ uses design;
uses codestyle;
uses multithreading;
uses performance;
uses bestPractices;
uses errorProne;
rule Java2SMM {
......@@ -36,6 +37,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
--
thisModule.dontCallThreadRun(),
--thisModule.avoidThreadGroup(),
thisModule.useNotifyAllInsteadOfNotify(),
-- Code Style rules
--
......@@ -402,3 +404,22 @@ rule MesureAvoidFieldNameMatchingMethodName(class : java!ClassDeclaration, metho
noc;
}
}
-- Creates a measure instance when rule 'UseNotifyAllInsteadOfNotify' is violated
rule MeasureUseNotifyAllInsteadOfNotify(method: java!MethodInvocation) {
to
om: smm!ObservedMeasure (
measure <- useNotifyAllInsteadOfNotify,
measurements <- measurement
),
useNotifyAllInsteadOfNotify: smm!DimensionalMeasure (
name <- 'UseNotifyAllInsteadOfNotify',
shortDescription <- 'Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only one is chosen. The thread chosen is arbitrary; thus its usually safer to call notifyAll() instead.'
),
measurement: smm!DirectMeasurement (
error <- 'Used notify() instead of notifyAll() in Class : ' + method.originalCompilationUnit.name
)
do {
useNotifyAllInsteadOfNotify;
}
}
......@@ -60,4 +60,15 @@ helper def:isThreadGroup(s:java!VariableDeclarationFragment): Boolean =
else
false
endif;
\ No newline at end of file
--------------------------------------------- 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)))
;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment