Commit f0b9040a authored by E19C506H's avatar E19C506H
Browse files

EmptyInitializer

parent dc04d99f
<?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">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:Initializer" originalCompilationUnit="//@compilationUnits.0">
<modifier static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Why ?"/>
</body>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:Initializer" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Again, why ?"/>
<modifier/>
<body originalCompilationUnit="//@compilationUnits.0"/>
</bodyDeclarations>
</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="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
...@@ -49,6 +49,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) = ...@@ -49,6 +49,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.noPackageDeclaration(), thisModule.noPackageDeclaration(),
thisModule.UnconditionalIfStatement(), thisModule.UnconditionalIfStatement(),
thisModule.EmptyInitializer(),
-- Design rules -- Design rules
-- --
thisModule.tooManyFields(), thisModule.tooManyFields(),
...@@ -1208,4 +1209,22 @@ rule MeasureUnconditionalIfStatement(w: java!IfStatement) { ...@@ -1208,4 +1209,22 @@ rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
do { do {
noc; noc;
} }
}
rule MeasureEmptyInitializer(w: java!Initializer) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'EmptyInitializer',
shortDescription <- ': EmptyInitializer finds '
),
measurement: smm!DirectMeasurement (
error <- 'do not declare an EmptyInitializer, EmptyInitializer is detected in ' + w.originalCompilationUnit.name + ' this block need to be deleted'
)
do {
noc;
}
} }
\ No newline at end of file
...@@ -67,19 +67,21 @@ helper def: longVariable() : Set(smm!Measure) = ...@@ -67,19 +67,21 @@ helper def: longVariable() : Set(smm!Measure) =
-> select( variable | variable.name.size() > 17) -> select( variable | variable.name.size() > 17)
-> collect (variable | thisModule.MeasureLongVariable(variable)); -> collect (variable | thisModule.MeasureLongVariable(variable));
--====Khaled AMIRAT no package declaration
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule. -- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
helper def: noPackageDeclaration() : Set(smm!Measure) = helper def: noPackageDeclaration() : Set(smm!Measure) =
-- Browse through all class(CompilationUnit)
java!CompilationUnit.allInstances() java!CompilationUnit.allInstances()
->select(compUnit | compUnit.package.oclIsUndefined()) ->select(compUnit | compUnit.package.oclIsUndefined())
->collect(err | thisModule.MesureAvoidNoPackageDeclaration(err)); ->collect(err | thisModule.MesureAvoidNoPackageDeclaration(err));
--====Khaled AMIRAT no package declaration -- Rule for metrics UnconditionalIfStatement : return the set of class Measures that violates the rule.
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
helper def: UnconditionalIfStatement() : Set(smm!Measure) = helper def: UnconditionalIfStatement() : Set(smm!Measure) =
-- Browse through all class(CompilationUnit)
java!IfStatement.allInstances() java!IfStatement.allInstances()
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral)) ->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w)); ->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
helper def: EmptyInitializer() : Set(smm!Measure) =
java!Initializer.allInstances()
->select( w | w.body.statements.size() = 0)
->collect(w | thisModule.MeasureEmptyInitializer(w));
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