Commit 4f84224c authored by Marion HUNAULT's avatar Marion HUNAULT
Browse files

first commit for short variable name rule

parent af84985e
This diff is collapsed.
......@@ -47,6 +47,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.tooManyStaticImports(),
thisModule.avoidDollarSigns(),
thisModule.shortClassName(),
thisModule.shortVariableName(),
thisModule.extendsObject(),
thisModule.unnecessaryReturn(),
thisModule.longVariable(),
......@@ -184,6 +185,26 @@ rule MesureShortClassName(class : java!ClassDeclaration) {
}
}
-- A Measure instance if the variable violates the rule 'ShortVariableName'.
rule MesureShortVariableName(variable : java!VariableDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ShortVariableName',
shortDescription <- 'Short Variable names with fewer than e.g. three characters are not recommended.'
),
measurement: smm!DirectMeasurement (
error <- 'The Variable ' + variable.name + ' is too short.'
)
do {
noc;
}
}
-- creates a new Measure when Thread.run() is used instead of Thread.start()
rule MeasureDontCallThreadRun(method : java!MethodInvocation) {
......
......@@ -64,3 +64,16 @@ helper def: longVariable() : Set(smm!Measure) =
-> select( variable | variable.name.size() > 17)
-> collect (variable | thisModule.MeasureLongVariable(variable));
--------------------------------------------- ShortVariableName ---------------------------------------------
-- Rule for metrics shortVariableName : return the set of variables measures that violates the rule.
helper def: shortVariableName() : Set(smm!Measure) =
java!SingleVariableDeclaration.allInstances()
-> reject(each | each.isProxy() or not each.catchClause->oclIsUndefined() or not each.enhancedForStatement->oclIsUndefined())
-> select( i | i.name.size() < 3)
-> union( java!VariableDeclarationFragment.allInstances()
-> reject(each | each.isProxy() or each.variablesContainer.oclIsTypeOf(java!VariableDeclarationExpression))
-> select( i | i.name.size() < 3)
)
-> collect (i | thisModule.MesureShortVariableName(i));
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