Commit 75f0e0a6 authored by Roxane Kang Maréchal's avatar Roxane Kang Maréchal
Browse files

Improved comments related to missing break in switch

parent b48745b0
...@@ -161,10 +161,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = ...@@ -161,10 +161,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
--- Creates an instance of Measure for the switch statement missing one or more break statements --- Creates an instance of Measure for the switch statement missing one or more break/return statements
-- To test, use input model : missing-break-in-switch.xmi rule MeasureMissingBreakInSwitch(ss: java!SwitchStatement) {
-- #TODO: rename rule
rule createMeasureForMissingBreakInSwitch(ss: java!SwitchStatement) {
to to
om: smm!ObservedMeasure ( om: smm!ObservedMeasure (
measure <- missingBreakInSwitch, measure <- missingBreakInSwitch,
...@@ -2038,7 +2036,7 @@ helper def: numberFieldsInClasse(s:java!ClassDeclaration) : Integer = ...@@ -2038,7 +2036,7 @@ helper def: numberFieldsInClasse(s:java!ClassDeclaration) : Integer =
-- Return the number of FieldDeclaration in a class. -- Return the number of FieldDeclaration in a class.
s.bodyDeclarations-> select(r | r.oclIsTypeOf(java!FieldDeclaration))->size(); s.bodyDeclarations-> select(r | r.oclIsTypeOf(java!FieldDeclaration))->size();
--- Returns the number of breaks of the switch statement passed in parameter --- Returns the number of breaks/return/continue/throw of the switch statement passed in parameter
helper def: nbBreakStatementOfASwitchStatement(ss:java!SwitchStatement) : Integer = helper def: nbBreakStatementOfASwitchStatement(ss:java!SwitchStatement) : Integer =
ss.statements->select(each | each.oclIsTypeOf(java!BreakStatement)).size() ss.statements->select(each | each.oclIsTypeOf(java!BreakStatement)).size()
; ;
......
...@@ -2,14 +2,14 @@ library errorProne; ...@@ -2,14 +2,14 @@ library errorProne;
---------------------------------- Missing break in switch--------------------------------------------- ---------------------------------- Missing break in switch---------------------------------------------
-- Returns a set of measures for each switch statement that violates the rule : missing break in switch --- Returns a set of measures for every switch statement without break or return statements for each case option
helper def: missingBreakInSwitch(): Set(smm!Measure) = helper def: missingBreakInSwitch(): Set(smm!Measure) =
java!SwitchStatement.allInstances() java!SwitchStatement.allInstances()
-> select (switchStatement | thisModule.switchStatementContainsMissingBreaks(switchStatement)) -> select (switchStatement | thisModule.switchStatementContainsMissingBreaks(switchStatement))
-> collect (switchStatement | thisModule.createMeasureForMissingBreakInSwitch(switchStatement)) -> collect (switchStatement | thisModule.MeasureMissingBreakInSwitch(switchStatement))
; ;
-- Returns true if the switch statement contains missing breaks, false otherwise --- Returns true if the switch statement contains missing breaks or return, false otherwise
helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Boolean = helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Boolean =
-- If the number of switch cases (omitting those that empty => indicates intentional fallout) is bigger than -- 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 -- the number of break statements => we don't have a break statement for every switch case
......
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