Commit 5c0a64fe authored by Gerson SUNYE's avatar Gerson SUNYE
Browse files

Merge branch 'master' into 'master'

fix #679, ExtendsObject 2pts

Closes #679, #736, #901, #898, and #810

See merge request naomod/mde/projet-2019!42
parents 2226dce2 170ce5c4
<?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="ExtendsObjectRule">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ExtendsObjectNotPass1">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0">
<qualifier xsi:type="java:PackageAccess" package="//@ownedElements.1/@ownedPackages.0">
<qualifier package="//@ownedElements.1"/>
</qualifier>
</superClass>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ExtendsObjectNotPass2">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.2" name="ExtendsObjectPass1">
<modifier visibility="public"/>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true" usagesInPackageAccess="//@ownedElements.0/@ownedElements.0/@superClass/@qualifier/@qualifier">
<ownedPackages name="lang" proxy="true" usagesInPackageAccess="//@ownedElements.0/@ownedElements.0/@superClass/@qualifier">
<ownedElements xsi:type="java:ClassDeclaration" name="Object" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@superClass //@ownedElements.0/@ownedElements.1/@superClass"/>
</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"/>
<compilationUnits name="ExtendsObjectNotPass1.java" originalFilePath="C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectNotPass1.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ExtendsObjectNotPass2.java" originalFilePath="C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectNotPass2.java" types="//@ownedElements.0/@ownedElements.1"/>
<compilationUnits name="ExtendsObjectPass1.java" originalFilePath="C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectPass1.java" types="//@ownedElements.0/@ownedElements.2"/>
</java:Model>
......@@ -47,6 +47,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.tooManyStaticImports(),
thisModule.AvoidDollarSigns(),
thisModule.shortClassName(),
thisModule.extendsObject(),
-- Design rules
--
......@@ -717,3 +718,26 @@ rule MeasureFinalFieldCouldBeStatic(field : java!FieldDeclaration) {
noc;
}
}
--------------------------------------------- MeasureExtendsObject ---------------------------------------------
-- A Measure instance if the class violates the rule ExtendsObject.
rule MeasureExtendsObject(variable : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExtendsObject',
shortDescription <- 'No need to explicitly extend Object.'
),
measurement: smm!DirectMeasurement (
error<-'In the Class '+ variable.name + ' No need to explicitly extend Object.'
)
do {
noc;
}
}
......@@ -33,4 +33,18 @@ helper def: tooManyStaticImports() : Set(smm!Measure) =
-- 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));
--------------------------------------------- ExtendsObject ---------------------------------------------
-- Rule for metrics ExtendsObject
helper def: extendsObject() : Set(smm!Measure) =
-- select all class with a superTyper
java!ClassDeclaration.allInstances()->select(it | (it.superClass <> OclUndefined))
-- select all class create by the user
->select(it2| it2.proxy = false)
-- select all class who extend Object
->select(it3| it3.superClass.type.name = 'java.lang.Object' or it3.superClass.type.name = 'Object')
-- collect all results and send an error message
->collect(it4|thisModule.MeasureDoNotExtendJavaLangError(it4))
;
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