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
ce9baa66
Commit
ce9baa66
authored
Dec 22, 2019
by
Gerson SUNYE
Browse files
Merge branch 'unused' into 'master'
Fix #650 Closes #650 See merge request
naomod/mde/projet-2019!158
parents
4eb8c8c7
a6919462
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/atl/analysis.atl
View file @
ce9baa66
...
...
@@ -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
...
...
src/main/atl/bestPractices.atl
View file @
ce9baa66
...
...
@@ -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.
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