Commit 0c295f8c authored by Gerson SUNYE's avatar Gerson SUNYE
Browse files

Merge branch 'AvoidFieldNameMatchingMethodName' into 'master'

Réécriture d'une méthode et ajout de commentaires

See merge request naomod/mde/projet-2019!24
parents fce77735 ec6a7fca
......@@ -45,7 +45,7 @@
<mapEntry key="OUT" value="smm"/>
</mapAttribute>
<mapAttribute key="Path">
<mapEntry key="IN" value="/projet-2019/input/comment-required.xmi"/>
<mapEntry key="IN" value="/projet-2019/input/avoid-field-name-matching-method-name.xmi"/>
<mapEntry key="OUT" value="/projet-2019/output/metrics.xmi"/>
<mapEntry key="java" value="uri:http://www.eclipse.org/MoDisco/Java/0.2.incubation/java"/>
<mapEntry key="smm" value="uri:http://www.eclipse.org/MoDisco/SMM/1.0.Beta2/smm"/>
......
......@@ -38,8 +38,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Multithreading rules
--
thisModule.dontCallThreadRun(),
thisModule.avoidThreadGroup(),
thisModule.useNotifyAllInsteadOfNotify(),
thisModule.avoidThreadGroup(),
-- Code Style rules
--
......
......@@ -29,20 +29,13 @@ helper def:isAvoidPrintStackTrace(s:java!MethodInvocation): Boolean =
helper def: avoidFieldNameMatchingMethodName() : Set(smm!Measure) =
-- Browse through all class
java!ClassDeclaration.allInstances()->iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if there are more than 4 static imports in the class.
-- Foreach FieldDeclaration, check all methods
i.bodyDeclarations->iterate(field; resIter : Set(smm!Measure) = Set{} |
if field.oclIsTypeOf(java!FieldDeclaration)
then
i.bodyDeclarations->iterate(method; resFinal : Set(smm!Measure) = Set{} |
if method.oclIsTypeOf(java!MethodDeclaration)
then
if method.name = field.fragments.first().name
then res->union(Set{thisModule.MesureAvoidFieldNameMatchingMethodName(i, method)})
else res
endif
else res
endif
)
then i.bodyDeclarations
-- Check if the name method and the name field is the same
->select(method | method.oclIsTypeOf(java!MethodDeclaration) and method.name = field.fragments.first().name)
->collect(method | thisModule.MesureAvoidFieldNameMatchingMethodName(i, method))
else res
endif
)
......
......@@ -17,11 +17,7 @@ helper def: shortMethodName() : Set(smm!Measure) =
-- Rule for metrics TooManyStaticImports : return the set of class Measures that violates the rule.
helper def: tooManyStaticImports() : Set(smm!Measure) =
-- Browse through all class(CompilationUnit)
java!CompilationUnit.allInstances()->iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if there are more than 4 static imports in the class.
if i.types.first().oclIsTypeOf(java!ClassDeclaration) and i.imports->select(i | i.static)->size() > 4
then res->union(Set{thisModule.MesureTooManyStaticImports(i)})
else res
endif
);
\ No newline at end of file
java!CompilationUnit.allInstances()
-- Add a new measurement if there are more than 4 static imports in the file.
-> select (c | c.types.first().oclIsTypeOf(java!ClassDeclaration) and c.imports->select(i | i.static)->size() > 4)
-> collect(c | thisModule.MesureTooManyStaticImports(c));
\ No newline at end of file
Supports Markdown
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