Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Roxane MARECHAL
Source Code Analyzer
Commits
1193718f
Commit
1193718f
authored
Dec 22, 2019
by
Roxane Kang Maréchal
Browse files
Added cases which were not taken into consideration and corrected intentional fallthrough detection
parent
75f0e0a6
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
input/missing-break-in-switch.xmi
View file @
1193718f
This diff is collapsed.
Click to expand it.
src/main/atl/analysis.atl
View file @
1193718f
...
...
@@ -175,7 +175,8 @@ rule MeasureMissingBreakInSwitch(ss: java!SwitchStatement) {
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)
-- value <- (thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbIntentionalFallThroughOfASwitchStatement(ss)) - thisModule.nbBreakStatementOfASwitchStatement(ss)
value <- thisModule.nbEmptySwitchCasesOfASwitchStatement(ss)
)
do {
missingBreakInSwitch;
...
...
@@ -2038,17 +2039,34 @@ helper def: numberFieldsInClasse(s:java!ClassDeclaration) : Integer =
--- Returns the number of breaks/return/continue/throw of the switch statement passed in parameter
helper def: nbBreakStatementOfASwitchStatement(ss:java!SwitchStatement) : Integer =
ss.statements->select(each | each.oclIsTypeOf(java!BreakStatement)).size()
ss.statements->select(each |
each.oclIsTypeOf(java!BreakStatement) or
each.oclIsTypeOf(java!ReturnStatement) or
each.oclIsTypeOf(java!ThrowStatement)
).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 empty switch cases of a switch statement
helper def: nbEmptySwitchCasesOfASwitchStatement(ss:java!SwitchStatement) : Integer =
-- Get the number of SwitchCases whoses next sibling is also a SwitchCase
ss.statements
->excluding(ss.statements.last())
->select(statement |
statement.oclIsTypeOf(java!SwitchCase) and
thisModule.nextSiblingIsSwitchCase(ss.statements.indexOf(statement), ss.statements)
).size() +
-- Add the last one if it's a switch case
ss.statements->select(statement
| statement = ss.statements.last() and statement.oclIsTypeOf(java!SwitchCase)).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)
--- Returns true if the next sibling of current SwitchCase is also a SwitchCase
helper def : nextSiblingIsSwitchCase(
indexOfSwitchCase : Integer,
statements : Sequence(java!Statement)) : Boolean =
statements.at(indexOfSwitchCase+1).oclIsTypeOf(java!SwitchCase)
;
--- Returns the name of a BodyDeclaration
...
...
src/main/atl/errorProne.atl
View file @
1193718f
...
...
@@ -14,7 +14,8 @@ helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Bool
-- 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)
(thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbEmptySwitchCasesOfASwitchStatement(ss)) > thisModule.nbBreakStatementOfASwitchStatement(ss)
;
--------------------------------------------- DoNotExtendJavaLangThrowable ---------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment