Commit fa6c7381 authored by E19C506H's avatar E19C506H
Browse files

ExcessiveMethodLength

parent f0b9040a
This diff is collapsed.
This diff is collapsed.
......@@ -50,6 +50,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.noPackageDeclaration(),
thisModule.UnconditionalIfStatement(),
thisModule.EmptyInitializer(),
thisModule.ExcessiveMethodLength(),
-- Design rules
--
thisModule.tooManyFields(),
......@@ -1171,8 +1172,7 @@ rule MesureFinalizeShouldBeProtected(m: java!MethodDeclaration) {
}
}
-- Khaled AMIRAT
-- A Measure instance if the class violates the rule 'AvoidFieldNameMatchingMethodName'.
-- A Measure instance if the class violates the rule AvoidNoPackageDeclaration.
rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) {
to
om: smm!ObservedMeasure (
......@@ -1192,6 +1192,7 @@ rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) {
}
}
-- A Measure instance if the class violates the rule UnconditionalIfStatement.
rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
to
om: smm!ObservedMeasure (
......@@ -1211,6 +1212,7 @@ rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
}
}
-- A Measure instance if the class violates the rule EmptyInitializer.
rule MeasureEmptyInitializer(w: java!Initializer) {
to
om: smm!ObservedMeasure (
......@@ -1227,4 +1229,23 @@ rule MeasureEmptyInitializer(w: java!Initializer) {
do {
noc;
}
}
-- A Measure instance if the class violates the rule ExcessiveMethodLength.
rule MeasureExcessiveMethodLength(w: java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExcessiveMethodLength',
shortDescription <- ': methods are excessively long this usually indicates that the method is doing more than its name/signature might suggest. They also become challenging for others to digest since excessive scrolling causes readers to lose focus'
),
measurement: smm!DirectMeasurement (
error <- w.originalCompilationUnit.name+ 'has a methode with more than 1000 line of code per a method it may need a separation in the code'
)
do {
noc;
}
}
\ No newline at end of file
......@@ -80,8 +80,24 @@ helper def: UnconditionalIfStatement() : Set(smm!Measure) =
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
-- Rule for metrics EmptyInitializer : return the set of class Measures that violates the rule.
helper def: EmptyInitializer() : Set(smm!Measure) =
java!Initializer.allInstances()
->select( w | w.body.statements.size() = 0)
->collect(w | thisModule.MeasureEmptyInitializer(w));
-- Rule for metrics ExcessiveClassLength : return the set of class Measures that violates the rule.
helper def: ExcessiveMethodLength() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.body <> OclUndefined )
->select (w | w.body.statements <> OclUndefined )
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveMethodLength(w));
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