Commit f040e51d authored by Martin ARS's avatar Martin ARS Committed by Gerson SUNYE
Browse files

Applications de petites modifications dans mes trois issues, toomanymethod,...

Applications de petites modifications dans mes trois issues, toomanymethod, toomanystaticimports ent avoidfieldnamematchingmethodname
parent 6148a550
......@@ -2,6 +2,7 @@
<launchConfiguration type="org.eclipse.m2m.atl.adt.launching.atlTransformation">
<stringAttribute key="ATL File Name" value="/projet-2019/src/main/atl/analysis.atl"/>
<stringAttribute key="ATL VM" value="EMF-specific VM"/>
<stringAttribute key="ATL_COMPILER" value="atl2006"/>
<booleanAttribute key="IS_REFINING" value="false"/>
<mapAttribute key="Input">
<mapEntry key="IN" value="java"/>
......@@ -42,8 +43,8 @@
<mapEntry key="OUT" value="smm"/>
</mapAttribute>
<mapAttribute key="Path">
<mapEntry key="IN" value="/projet-2019/input/avoid-print-stack-trace.xmi"/>
<mapEntry key="OUT" value="/projet-2019/metrics.xmi"/>
<mapEntry key="IN" value="/projet-2019/input/avoid-field-name-matching-method-name.xmi"/>
<mapEntry key="OUT" value="/projet-2019/output/test.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"/>
</mapAttribute>
......
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="AvoidFieldNameMatchingMethodName">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ClassWithNoMatchingName">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="normalField"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="normalMethod1">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="normalMethod2">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ClassWithMatchingName2">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="normalField"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="matching1"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="matching2"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="normalMethod1">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="normalMethod2">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="matching1">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="matching2">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.2" name="ClassWithMatchingName1">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.2">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
<fragments originalCompilationUnit="//@compilationUnits.2" name="matching"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.2" name="matching">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.2"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.2/@type">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
<ownedElements xsi:type="java:ClassDeclaration" name="Object" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.2/@bodyDeclarations.0/@type"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.3/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.4/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.5/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.6/@returnType //@ownedElements.0/@ownedElements.2/@bodyDeclarations.1/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="ClassWithNoMatchingName.java" originalFilePath="D:\Programmation\Projets\Eclipse\AvoidFieldNameMatchingMethodName\src\ClassWithNoMatchingName.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ClassWithMatchingName2.java" originalFilePath="D:\Programmation\Projets\Eclipse\AvoidFieldNameMatchingMethodName\src\ClassWithMatchingName2.java" types="//@ownedElements.0/@ownedElements.1"/>
<compilationUnits name="ClassWithMatchingName1.java" originalFilePath="D:\Programmation\Projets\Eclipse\AvoidFieldNameMatchingMethodName\src\ClassWithMatchingName1.java" types="//@ownedElements.0/@ownedElements.2"/>
</java:Model>
......@@ -34,13 +34,14 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Multithreading rules
--
thisModule.dontCallThreadRun(),
thisModule.avoidThreadGroup(),
--thisModule.avoidThreadGroup(),
-- Code Style rules
--
thisModule.shortMethodName(),
thisModule.tooManyStaticImports(),
thisModule.AvoidDollarSigns() ,
thisModule.avoidFieldNameMatchingMethodName(),
-- Design rules
--
......@@ -245,12 +246,6 @@ helper def: nbBranchesOfASwitchStatement(switchStatement:java!SwitchStatement) :
endif
);
helper def: numberMethodsInClasse(s:java!ClassDeclaration) : Integer =
-- Return the number of MethodsDeclaration in a class.
s.bodyDeclarations->select(r | r.oclIsTypeOf(java!MethodDeclaration))->reject(without | without.name.startsWith('get') or without.name.startsWith('set') or without.name.startsWith('is'))->size();
-- A Measure instance if the class violates the rule 'TooManyMethods'.
rule MesureTooManyMethods(class : java!ClassDeclaration) {
to
......@@ -289,23 +284,6 @@ rule MesureReturnFromFinallyBlock(method : java!MethodDeclaration) {
}
}
--------------------------------------------- TooManyStaticImports ---------------------------------------------
-- 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 thisModule.numberOfStaticImportInClass(i) > 4
then res->union(Set{thisModule.MesureTooManyStaticImports(i)})
else res
endif
);
-- Return the number of static imports in a specific ClassDeclaration.
helper def: numberOfStaticImportInClass(s:java!CompilationUnit) : Integer =
s.imports->select(i | i.static)->size();
-- A Measure instance if the class violates the rule 'TooManyStaticImports'.
rule MesureTooManyStaticImports(class : java!CompilationUnit) {
to
......@@ -363,3 +341,23 @@ rule measureAvoidThreadGroup(variable : java!VariableDeclarationFragment) {
noc;
}
}
-- A Measure instance if the class violates the rule 'AvoidFieldNameMatchingMethodName'.
rule MesureAvoidFieldNameMatchingMethodName(class : java!ClassDeclaration, method : java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidFieldNameMatchingMethodName',
shortDescription <- 'It can be confusing to have a field name with the same name as a method. While this is permitted, having information (field) and actions (method) is not clear naming. Developers versed in Smalltalk often prefer this approach as the methods denote accessor methods.'
),
measurement: smm!DirectMeasurement (
error <- 'In the ' + class.name + ' class you have an field and an method with the same name : '+ method.name
)
do {
noc;
}
}
......@@ -21,4 +21,29 @@ helper def:isAvoidPrintStackTrace(s:java!MethodInvocation): Boolean =
true
else
false
endif;
\ No newline at end of file
endif;
--------------------------------------------- AvoidFieldNameMatchingMethodName ---------------------------------------------
-- Rule for metrics AvoidFieldNameMatchingMethodName : return the set of class Measures that violates the rule.
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.
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
)
else res
endif
)
);
\ No newline at end of file
......@@ -20,8 +20,8 @@ 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 thisModule.numberOfStaticImportInClass(i) > 4
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
......@@ -15,12 +15,12 @@ helper def: tooManyFields() : Set(smm!Measure) =
--------------------------------------------- TooManyMethods ---------------------------------------------
-- Rule for metrics TooManyMethods : return the set of class Measures that violates the rule.
helper def: tooManyMethods() : Set(smm!Measure) =
-- Browse through all class
java!ClassDeclaration.allInstances() -> reject(each | each.isProxy())->iterate(i; res : Set(smm!Measure) = Set{} |
java!ClassDeclaration.allInstances()->reject(each | each.isProxy())->iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if there are more than 10 methods in the class.
if thisModule.numberMethodsInClasse(i) > 10
if i.bodyDeclarations->select(r | r.oclIsTypeOf(java!MethodDeclaration))->reject(without |
without.name.startsWith('get') or without.name.startsWith('set') or without.name.startsWith('is'))->size() > 10
then res->union(Set{thisModule.MesureTooManyMethods(i)})
else res
endif
......
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