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

Merge branch 'unused' into 'master'

Fix #650

Closes #650

See merge request naomod/mde/projet-2019!158
parents 4eb8c8c7 a6919462
......@@ -137,6 +137,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.forLoopVariableCount(),
thisModule.oneDeclarationPerLine(),
thisModule.switchDensity(),
thisModule.unusedLocalVariable(),
thisModule.useAssertSameInsteadOfAssertTrue(),
thisModule.useAssertTrueInsteadOfAssertEquals()
......@@ -1956,6 +1957,25 @@ rule MesureTooManyStaticImports(class : java!CompilationUnit) {
}
}
----------------------------------------- UnusedLocalVariable ------------------------------------------------------
--- Creates a measure when a local variable is declared but not used
rule MeasureUnusedLocalVariable(var : java!VariableDeclarationFragment){
to
om: smm!ObservedMeasure (
measure <- unusedLocalVariable,
measurements <- unusedLocalVariable
),
unusedLocalVariable: smm!DimensionalMeasure(
name <- 'UnusedLocalVariable',
shortDescription <- 'Detects when a local variable is declared and/or assigned, but not used'
)
do {
unusedLocalVariable;
}
}
-------------------------------------------UseAssertSameInsteadOfAssertTrue----------------------------------------------
--- A Measure instance if the class violate the rule AssertSameInsteadOfAssertTrue
-- #FIXME: Typo
......@@ -2025,7 +2045,6 @@ rule numberOfClasses() {
}
}
-- Auxiliary helpers:
--- Returns the number of branches in the switch statement passed in parameter
......
......@@ -145,6 +145,14 @@ helper def: switchDensity() : Set (smm!Measure) =
->collect(switchStatement | thisModule.MeasureSwitchDensity(switchCase))
);
--- Rule for metrics UnusedLocalVariable :
helper def: unusedLocalVariable(): Set(ssm!Measures) =
java!VariableDeclarationFragment.allInstances()
-> select(variable | variable.originalCompilationUnit.name = 'LocalVariable.java')
-> select(variable | variable.usageInVariableAccess.isEmpty())
-> collect(variable | thisModule.MeasureUnusedLocalVariable(variable))
;
-- #TODO: Add comment
helper def: useAssertSameInsteadOfAssertTrue() : Set(smm!Measure) =
-- Browse through all methods use
......@@ -165,6 +173,7 @@ helper def: useAssertTrueInsteadOfAssertEquals() : Set(smm!Measure) =
-- Attention !!!
-- Before adding a rule to the end of file, ensure that you are respecting the
-- alphabetical order for rule declarations.
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