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

Merge branch 'fix/shortClassName' into 'master'

short class name

See merge request naomod/mde/projet-2019!34
parents 792753bd cb641655
<?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="shortclassname">
<ownedElements name="shortclassname">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Alphabet">
<modifier visibility="public"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="Abc">
<modifier visibility="public"/>
</ownedElements>
</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="Alphabet.java" originalFilePath="C:\Users\Marion\_FACULTE\_M2\Model_photon\shortclassname\src\shortclassname\Alphabet.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="Abc.java" originalFilePath="C:\Users\Marion\_FACULTE\_M2\Model_photon\shortclassname\src\shortclassname\Abc.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
......@@ -45,7 +45,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
--
thisModule.shortMethodName(),
thisModule.tooManyStaticImports(),
thisModule.AvoidDollarSigns() ,
thisModule.AvoidDollarSigns(),
thisModule.shortClassName(),
-- Design rules
--
......@@ -155,6 +156,26 @@ rule MesureShortMethodName(method : java!MethodDeclaration) {
}
-- A Measure instance if the class violates the rule 'ShortClassName'.
rule MesureShortClassName(class : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ShortClassName',
shortDescription <- 'Short Classnames with fewer than e.g. five characters are not recommended.'
),
measurement: smm!DirectMeasurement (
error <- 'The Class ' + class.name + ' is too short.'
)
do {
noc;
}
}
-- creates a new Measure when Thread.run() is used instead of Thread.start()
rule MeasureDontCallThreadRun(method : java!MethodInvocation) {
to
......
......@@ -13,6 +13,13 @@ helper def: shortMethodName() : Set(smm!Measure) =
endif
);
--------------------------------------------- ShortClassName ---------------------------------------------
-- Rule for metrics shortClassName : return the set of class Measures that violates the rule.
helper def: shortClassName() : Set(smm!Measure) =
java!ClassDeclaration.allInstances() -> reject(each | each.isProxy())
-> select( i | i.name.size() < 4)
-> collect (i | thisModule.MesureShortClassName(i));
--------------------------------------------- TooManyStaticImports ---------------------------------------------
-- Rule for metrics TooManyStaticImports : return the set of class Measures that violates the rule.
......@@ -20,4 +27,5 @@ helper def: tooManyStaticImports() : Set(smm!Measure) =
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
-> collect(c | thisModule.MesureTooManyStaticImports(c));
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