Commit 4864b383 authored by Roxane Kang Maréchal's avatar Roxane Kang Maréchal
Browse files

Merge remote-tracking branch 'upstream/master'

parents 1500a413 d909aaff
......@@ -79,7 +79,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Performance rules
--
thisModule.addEmptyString(),
thisModule.avoidInstantiatingObjectsInLoops(),
-- #FIXME: thisModule.avoidInstantiatingObjectsInLoops(),
thisModule.avoidPrintStackTrace(),
thisModule.avoidRethrowingException(),
thisModule.avoidUsingShortType(),
......@@ -91,6 +91,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.integerInstantiation(),
-- #FIXME:
-- thisModule.startsWith(),
thisModule.stringToString(),
thisModule.tooFewBranchesForASwitchStatement(),
-- #FIXME: thisModule.useArraysAsList(),
thisModule.useIndexOfChar(),
......@@ -131,12 +132,13 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.UseProperClassLoader(),
-- Best practices rules
thisModule.arrayIsStoredDirectly(),
-- #FIXME: thisModule.arrayIsStoredDirectly(),
thisModule.avoidReassigningParameters(),
thisModule.avoidStringBufferField(),
thisModule.forLoopVariableCount(),
thisModule.oneDeclarationPerLine(),
thisModule.switchDensity(),
-- #FIXME: thisModule.unusedLocalVariable(),
thisModule.useAssertSameInsteadOfAssertTrue(),
thisModule.useAssertTrueInsteadOfAssertEquals()
......@@ -151,7 +153,6 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- thisModule.replaceVectorToList()
-- thisModule.unusedPrivateMethod ()
-- thisModule.avoidThrowingNewInstanceOfSameException(),
-- thisModule.stringToString(),
-- thisModule.methodWithSameNameAsEnclosingClass(),
-- thisModule.dontUseFloatTypeForLoopIndices(),
-- thisModule.methodWithSameNameAsEnclosingClass(),
......@@ -1892,6 +1893,25 @@ rule MesureShortVariableName(variable : java!VariableDeclaration) {
}
}
--- Creates a new Measure when the method toString() is unnecessarily invoked.
rule MeasureStringToString(method : java!MethodInvocation) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'StringToString',
shortDescription <- 'Avoid calling toString() on objects already known to be string instances; this is unnecessary.'
),
measurement: smm!DirectMeasurement (
error <- 'The Object ' + method.expression.variable.name + ' is already a String in ' + method.originalCompilationUnit.name
)
do {
noc;
}
}
--- A Measure instance if the class violates the rule 'TooManyFields'.
-- #FIXME: Typo
rule MesureTooManyFields(class : java!ClassDeclaration) {
......@@ -1954,6 +1974,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
......@@ -2023,7 +2062,6 @@ rule numberOfClasses() {
}
}
-- Auxiliary helpers:
--- Returns the number of branches in the switch statement passed in parameter
......@@ -2080,8 +2118,4 @@ helper context java!FieldDeclaration def: getBodyDeclarationName() : String =
-- ATTENTION !!!
-- Before adding a new rule in the end of the file, remember that rules respect an alphabetical order.
-- Before adding a new rule in the end of the file, remember that rules respect an alphabetical order.
\ No newline at end of file
......@@ -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.
This diff is collapsed.
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