Commit 75208ca0 authored by Maud VAN DORSSEN's avatar Maud VAN DORSSEN Committed by Gerson SUNYE
Browse files

Fix#741 Excessive parameter list

parent 3f79b8e3
<?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="test-projet">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ParameterTestClass">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="methodNoParameters">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;Coucou&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.1/@ownedElements.1"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="methodSomeParameters">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param1">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param2">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param3">
<modifier/>
<type type="//@orphanTypes.4"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param4">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param5">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="method10Parameters">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param1">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param2">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param3">
<modifier/>
<type type="//@orphanTypes.4"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param4">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param5">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param6">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param7">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param8">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param9">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param10">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="method20Parameters">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param1">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param2">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param3">
<modifier/>
<type type="//@orphanTypes.4"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param4">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param5">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param6">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param7">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param8">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param9">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param10">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param11">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param12">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param13">
<modifier/>
<type type="//@orphanTypes.4"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param14">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param15">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param16">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param17">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param18">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.6"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param19">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param20">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="File" proxy="true" usagesInImports="//@compilationUnits.0/@imports.0" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.4/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.5/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.5/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.15/@type">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0 //@ownedElements.1/@ownedPackages.1/@ownedElements.2/@superInterfaces.0 //@ownedElements.1/@ownedPackages.1/@ownedElements.7/@superInterfaces.0"/>
<ownedElements xsi:type="java:ClassDeclaration" name="PrintStream" proxy="true">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="println" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression">
<parameters name="arg0" proxy="true">
<type type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</parameters>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.5"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="FilterOutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@superClass">
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="OutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.3/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.6"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Closeable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.4/@superInterfaces.0 //@ownedElements.1/@ownedPackages.0/@ownedElements.2/@superInterfaces.1">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Flushable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.4/@superInterfaces.1"/>
</ownedPackages>
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1 //@ownedElements.1/@ownedPackages.1/@ownedElements.2/@superInterfaces.1 //@ownedElements.1/@ownedPackages.1/@ownedElements.6/@superInterfaces.0">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="System" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression/@expression/@qualifier">
<bodyDeclarations xsi:type="java:FieldDeclaration" proxy="true">
<fragments name="out" proxy="true" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression/@expression"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@bodyDeclarations.0/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.3/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.3/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.3/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.13/@type">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.2/@superInterfaces.2"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="AutoCloseable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.5/@superInterfaces.0"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Appendable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@superInterfaces.0"/>
<ownedElements xsi:type="java:ClassDeclaration" name="Double" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.7/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.7/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.11/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.17/@type">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.7"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Number" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.6/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</ownedElements>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.4/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.6/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.8/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.9/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.4/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.6/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.8/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.9/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.10/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.14/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.16/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.18/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.19/@type"/>
<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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.2/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.2/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.2/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@parameters.12/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="ParameterTestClass.java" originalFilePath="D:\Documents\Cours\M2-ALMA\Gerson\test-projet\src\ParameterTestClass.java" types="//@ownedElements.0/@ownedElements.0">
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</compilationUnits>
</java:Model>
......@@ -53,6 +53,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.tooManyFields(),
thisModule.tooManyMethods(),
thisModule.returnFromFinallyBlock(),
thisModule.excessiveParameterList(),
-- Performance rules
--
......@@ -389,6 +390,28 @@ rule measureAvoidThreadGroup(variable : java!VariableDeclarationFragment) {
}
}
--------------------------------------------- ExcessiveParameterList ---------------------------------------------
-- creates a new Measure when a method has more than 10 parameters
rule MesureExcessiveParameterList(method : java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExcessiveParameterList',
shortDescription <- 'Methods with numerous parameters are a challenge to maintain, especially if most of them share the same datatype.'
),
measurement: smm!DirectMeasurement (
error<-'The method '+ method.name + ' in the class ' + method.originalCompilationUnit.name + ' has an excessive parameter list.'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule 'AvoidFieldNameMatchingMethodName'.
rule MesureAvoidFieldNameMatchingMethodName(class : java!ClassDeclaration, method : java!MethodDeclaration) {
to
......
......@@ -48,3 +48,11 @@ helper def: returnFromFinallyBlock() : Set(smm!Measure) =
endif
);
--------------------------------------------- ExcessiveParameterList ---------------------------------------------
-- Helper for issue ExcessiveParameterList : return a Measure for each method that has too many parameters.
helper def: excessiveParameterList() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
-> select (method | method.body <> OclUndefined and method.parameters.size() > 10)
-> collect(method | thisModule.MesureExcessiveParameterList(method));
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