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

Merge branch 'IfStmtsMustUseBraces' into 'master'

IfStmtsMustUseBraces and add excessiveImport missing

Closes #688 and #723

See merge request naomod/mde/projet-2019!125
parents 9f26a17b 92b66413
<?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="ExcessiveImports">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ClassWithExcessiveImports">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier/>
<type type="//@orphanTypes.9"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="toto">
<initializer xsi:type="java:ClassInstanceCreation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<type type="//@orphanTypes.9"/>
</initializer>
</fragments>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ClassWithoutExcessiveImport">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@orphanTypes.9"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="toto">
<initializer xsi:type="java:ClassInstanceCreation" originalCompilationUnit="//@compilationUnits.1" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<type type="//@orphanTypes.9"/>
</initializer>
</fragments>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="util" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="ArrayList" proxy="true" usagesInImports="//@compilationUnits.0/@imports.0 //@compilationUnits.1/@imports.0" usagesInTypeAccess="//@orphanTypes.9/@type">
<bodyDeclarations xsi:type="java:ConstructorDeclaration" name="ArrayList" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0/@initializer //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@fragments.0/@initializer"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.4"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.2/@ownedElements.0"/>
<typeParameters name="E" proxy="true"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="AbstractList" proxy="true" usagesInImports="//@compilationUnits.0/@imports.1" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.4"/>
<typeParameters name="E" proxy="true"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="AbstractCollection" proxy="true" usagesInImports="//@compilationUnits.0/@imports.2" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
<typeParameters name="E" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Collection" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@superInterfaces.0 //@ownedElements.1/@ownedPackages.0/@ownedElements.4/@superInterfaces.0">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<typeParameters name="E" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="List" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superInterfaces.0 //@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
<typeParameters name="E" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="RandomAccess" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1"/>
<ownedElements xsi:type="java:ClassDeclaration" name="Arrays" proxy="true" usagesInImports="//@compilationUnits.0/@imports.3"/>
<ownedElements xsi:type="java:ClassDeclaration" name="Calendar" proxy="true" usagesInImports="//@compilationUnits.0/@imports.4">
<superInterfaces type="//@ownedElements.1/@ownedPackages.2/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</ownedElements>
</ownedPackages>
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Iterable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.3/@superInterfaces.0">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Cloneable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2 //@ownedElements.1/@ownedPackages.0/@ownedElements.7/@superInterfaces.1"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.7/@superInterfaces.2 //@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superInterfaces.0">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Integer" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@typeArguments.0">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Number" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.2/@ownedElements.0"/>
</ownedElements>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.3 //@ownedElements.1/@ownedPackages.0/@ownedElements.7/@superInterfaces.0 //@ownedElements.1/@ownedPackages.1/@ownedElements.4/@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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ParameterizedType" name="java.util.ArrayList&lt;java.lang.Integer>" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0/@initializer/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@fragments.0/@initializer/@type">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<typeArguments type="//@ownedElements.1/@ownedPackages.1/@ownedElements.3"/>
</orphanTypes>
<compilationUnits name="ClassWithExcessiveImports.java" originalFilePath="C:\Users\forma\eclipse-workspace_2019\ExcessiveImports\src\ClassWithExcessiveImports.java" types="//@ownedElements.0/@ownedElements.0">
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.6"/>
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.7"/>
</compilationUnits>
<compilationUnits name="ClassWithoutExcessiveImport.java" originalFilePath="C:\Users\forma\eclipse-workspace_2019\ExcessiveImports\src\ClassWithoutExcessiveImport.java" types="//@ownedElements.0/@ownedElements.1">
<imports originalCompilationUnit="//@compilationUnits.1" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</compilationUnits>
</java:Model>
......@@ -68,6 +68,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.tooManyMethods(),
thisModule.SimplifyBooleanAssertion(),
thisModule.abstractClassWithoutAnyMethod(),
thisModule.excessiveImports(),
-- Performance rules
--
......@@ -1608,7 +1609,7 @@ rule MeasureIfStmtsMustUseBraces(i : java!IfStatement) {
shortDescription <- 'Deprecated Avoid using if statements without using braces to surround the code block. If the code formatting...'
),
measurement: smm!DirectMeasurement (
error <- 'The class ' + condition.originalCompilationUnit.name + ' has an if statement without braces. '
error <- 'The class ' + i.originalCompilationUnit.name + ' has an if statement without braces. '
)
do {
noc;
......
......@@ -108,4 +108,4 @@ helper def: IfBraces() : Set(smm!Measure) =
java!IfStatement.allInstances()
-> select(i | i.thenStatement <> OclUndefined)
-> select(i | not i.thenStatement.oclIsTypeOf(java!Block))
-> collect(i | thisModule.MeasureIfStmtsMustUseBraces(i));
-> collect(i | thisModule.MeasureIfStmtsMustUseBraces(i));
\ No newline at end of file
......@@ -147,3 +147,11 @@ helper def: abstractClassWithoutAnyMethod() : Set(smm!Measure) =
-> select(i | i.modifier <> OclUndefined)
-> select(i | i.modifier.inheritance -> toString() = 'abstract')
-> collect(i | thisModule.MeasureAbstractClassWithoutAnyMethod(i));
--------------------------------------------- ExcessiveImports ---------------------------------------------
-- Helper for issue ExcessiveImports : return a Measure for each class that has too many imports.
helper def: excessiveImports() : Set(smm!Measure) =
java!CompilationUnit.allInstances()
-> select (i | i.imports <> OclUndefined)
-> select (i | i.imports.size() > 4)
-> collect(i | thisModule.MeasureExcessiveImports(i));
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