Commit dc04d99f authored by E19C506H's avatar E19C506H
Browse files

UnconditionalIfStatement

parent 5ca75f27
<?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:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<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" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
...@@ -48,6 +48,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) = ...@@ -48,6 +48,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.longVariable(), thisModule.longVariable(),
thisModule.noPackageDeclaration(), thisModule.noPackageDeclaration(),
thisModule.UnconditionalIfStatement(),
-- Design rules -- Design rules
-- --
thisModule.tooManyFields(), thisModule.tooManyFields(),
...@@ -1189,3 +1190,22 @@ rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) { ...@@ -1189,3 +1190,22 @@ rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) {
noc; noc;
} }
} }
rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'UnconditionalIfStatement',
shortDescription <- ': UnconditionalIfStatement finds all instances where a'
+ ' UnconditionalIfStatement statement does nothing.'
),
measurement: smm!DirectMeasurement (
error <- 'UnconditionalIfStatement is detected in ' + w.originalCompilationUnit.name
)
do {
noc;
}
}
\ No newline at end of file
-- @nsURI smm=http://www.eclipse.org/MoDisco/SMM/1.0.Beta2/smm
-- @nsURI java=http://www.eclipse.org/MoDisco/Java/0.2.incubation/java
library codestyle; library codestyle;
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
...@@ -71,3 +74,12 @@ helper def: noPackageDeclaration() : Set(smm!Measure) = ...@@ -71,3 +74,12 @@ helper def: noPackageDeclaration() : Set(smm!Measure) =
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 noPackageDeclaration : return the set of class Measures that violates the rule.
helper def: UnconditionalIfStatement() : Set(smm!Measure) =
-- Browse through all class(CompilationUnit)
java!IfStatement.allInstances()
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
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