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

Merge branch 'fix/TooManyFields' into 'master'

Fix #764 TooManyFields

Closes #764

See merge request naomod/mde/projet-2019!4
parents 2fabdcb3 e0d1a116
This diff is collapsed.
......@@ -23,6 +23,7 @@ rule Java2SMM {
helper def: allMeasures(project : java!Model): Set(smm!Measure) =
Set{
thisModule.numberOfClasses(),
thisModule.tooManyFields() -- to test, use input/example_toomanyfields.xmi
thisModule.tooFewBranchesForASwitchStatement(),
thisModule.useIndexOfChar(), --to test, use input/useIndexOfChar_java.xmi
thisModule.tooManyMethods() --to test, use input/tooManyMethods.xmi
......@@ -31,6 +32,43 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
--
};
-- Rule for metrics TooManyFields : return the set of class Measures that violates the rule.
-- To test, example_toomanyfields.xmi, two classe must violates the rule.
helper def: tooManyFields() : Set(smm!Measure) =
-- Browse through all class
java!ClassDeclaration.allInstances() -> reject(each | each.isProxy())->iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if there are more than 15 fields in the class.
if thisModule.numberFieldsInClasse(i) >15
then res->union(Set{thisModule.MesureTooManyFields(i)})
else res
endif
);
helper def: numberFieldsInClasse(s:java!ClassDeclaration) : Integer =
-- Return the number of FieldDeclaration in a class.
s.bodyDeclarations-> select(r | r.oclIsTypeOf(java!FieldDeclaration))->size();
-- A Measure instance if the class violates the rule 'TooManyFields'.
rule MesureTooManyFields(class : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'TooManyFields',
shortDescription <- 'Classes that have too many fields can become unwieldy and could be redesigned to have fewer field.'
),
measurement: smm!DirectMeasurement (
error <- class.originalCompilationUnit.name + ' have too many fields'
)
do {
noc;
}
}
--Goes through all the methods to check if the following rule is followed:
--Use String.indexOf(char) when checking for the index of a single character; it executes faster.
helper def: useIndexOfChar() : Set(smm!Measure) =
......@@ -174,5 +212,3 @@ rule MesureTooManyMethods(class : java!ClassDeclaration) {
noc;
}
}
---------------------------------------------------------------------------------------------------------------------
\ No newline at end of file
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