Commit c7223cdc authored by Gerson SUNYE's avatar Gerson SUNYE
Browse files

Merge branch 'master' into 'fix/882-UseNotifyAllInsteadOfNotify'

# Conflicts:
#   .gitignore
#   src/main/atl/analysis.atl
parents 09f419ce f76ebe91
......@@ -11,6 +11,7 @@
<mapEntry key="bestPractices" value="/projet-2019/src/main/atl/bestPractices.asm"/>
<mapEntry key="codestyle" value="/projet-2019/src/main/atl/codestyle.asm"/>
<mapEntry key="design" value="/projet-2019/src/main/atl/design.asm"/>
<mapEntry key="errorProne" value="/projet-2019/src/main/atl/errorProne.asm"/>
<mapEntry key="multithreading" value="/projet-2019/src/main/atl/multithreading.asm"/>
<mapEntry key="performance" value="/projet-2019/src/main/atl/performance.asm"/>
</mapAttribute>
......
This diff is collapsed.
......@@ -10,6 +10,7 @@ uses codestyle;
uses multithreading;
uses performance;
uses bestPractices;
uses errorProne;
rule Java2SMM {
from
......@@ -56,7 +57,11 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.uselessStringValueOf(),
thisModule.tooFewBranchesForASwitchStatement(),
thisModule.useIndexOfChar(),
thisModule.avoidPrintStackTrace()
thisModule.avoidPrintStackTrace(),
-- Error prone rules
--
thisModule.missingBreakInSwitch()
};
......@@ -218,7 +223,6 @@ rule numberOfClasses() {
}
}
-- Rule that creates an instance of Measure for the switch statement with too few branches passed in parameter
rule createMeasureForTooFewBranchesForASwitchStatement(switchStatement: java!SwitchStatement) {
to
......@@ -248,6 +252,43 @@ helper def: nbBranchesOfASwitchStatement(switchStatement:java!SwitchStatement) :
endif
);
-- Returns the number of breaks of the switch statement passed in parameter
helper def: nbBreakStatementOfASwitchStatement(ss:java!SwitchStatement) : Integer =
ss.statements->select(each | each.oclIsTypeOf(java!BreakStatement)).size()
;
-- Returns the number of expressions of the switch statement passed in parameter
helper def: nbExpressionsStatementOfASwitchStatement(ss:java!SwitchStatement) : Integer =
ss.statements->select(each | each.oclIsTypeOf(java!ExpressionStatement)).size()
;
-- Returns the number of intentional fall-through (empty switch cases) of a switchStatement
helper def: nbIntentionalFallThroughOfASwitchStatement(ss:java!SwitchStatement) : Integer =
thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbExpressionsStatementOfASwitchStatement(ss)
;
-- Creates an instance of Measure for the switch statement missing one or more break statements
-- To test, use input model : missing-break-in-switch.xmi
rule createMeasureForMissingBreakInSwitch(ss: java!SwitchStatement) {
to
om: smm!ObservedMeasure (
measure <- missingBreakInSwitch,
measurements <- measurement
),
missingBreakInSwitch: smm!DimensionalMeasure (
name <- 'Missing break in Switch',
shortDescription <- 'Switch statements without break or return statements for each case option may indicate problematic behaviour. Empty cases are ignored as these indicate an intentional fall-through.'
),
measurement: smm!DirectMeasurement (
error <- 'Missing breaks in Switch in Class : ' + ss.originalCompilationUnit.name + '',
-- Indicates the number of breaks missing in the switch statement
value <- (thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbIntentionalFallThroughOfASwitchStatement(ss)) - thisModule.nbBreakStatementOfASwitchStatement(ss)
)
do {
missingBreakInSwitch;
}
}
-- A Measure instance if the class violates the rule 'TooManyMethods'.
rule MesureTooManyMethods(class : java!ClassDeclaration) {
to
......
library errorProne;
---------------------------------- Missing break in switch---------------------------------------------
-- Returns a set of measures for each switch statement that violates the rule : missing break in switch
helper def: missingBreakInSwitch(): Set(smm!Measure) =
java!SwitchStatement.allInstances()
-> select (switchStatement | thisModule.switchStatementContainsMissingBreaks(switchStatement))
-> collect (switchStatement | thisModule.createMeasureForMissingBreakInSwitch(switchStatement))
;
-- Returns true if the switch statement contains missing breaks, false otherwise
helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Boolean =
-- If the number of switch cases (omitting those that empty => indicates intentional fallout) is bigger than
-- the number of break statements => we don't have a break statement for every switch case
-- in that case, return true, else false
(thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbIntentionalFallThroughOfASwitchStatement(ss)) > thisModule.nbBreakStatementOfASwitchStatement(ss)
;
--------------------------------------------------------------------------------------------------------
\ No newline at end of file
Markdown is supported
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