Commit 0a633114 authored by Hanane HADJI's avatar Hanane HADJI
Browse files

fix rule package case

parent 607b0ec2
<?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="Package">
<ownedElements name="com">
<ownedPackages name="MyCompany">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="SomeClass">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// should be lowercase name" prefixOfParent="true"/>
<modifier visibility="public"/>
</ownedElements>
</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="SomeClass.java" originalFilePath="C:\Users\HP\eclipse-workspace-modeling-two\Package\src\com\MyCompany\SomeClass.java" commentList="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@comments.0" package="//@ownedElements.0/@ownedPackages.0" types="//@ownedElements.0/@ownedPackages.0/@ownedElements.0"/>
</java:Model>
......@@ -74,6 +74,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.finalFieldCouldBeStatic(),
thisModule.IfBraces(),
thisModule.IfElseStmtsMustUseBraces(),
thisModule.packageCase(),
thisModule.longInstantiation(),
thisModule.returnFromFinallyBlock(),
thisModule.shortInstantiation(),
......@@ -1566,6 +1567,27 @@ rule MeasureNonStaticInitializer(classDeclaration : java!ClassDeclaration) {
noc;
}
}
--------------------------PackageCase----------------------------------------------
-- A Measure instance if the class violate the rule PackageCase
rule MeasurePackageCase(p : java!CompilationUnit) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'PackageCase',
shortDescription <- ' : Detects when a package definition contains uppercase characters.'
),
measurement: smm!DirectMeasurement (
error <- ' Package Upper Case in' + p.package.name + 'is detected '
)
do {
noc;
}
}
-- ----------------------------------------- OneDeclarationPerLine ----------------------------------------
--- creates a measure when several variables are declared on the same line
......
......@@ -241,3 +241,10 @@ helper def: IfElseStmtsMustUseBraces() : Set(smm!Measure) =
-> select(cond | not cond.elseStatement.oclIsTypeOf(java!Block))
-> collect(b | thisModule.MeasureIfElseStmtsMustUseBraces(b));
---------------------- MeasurePackageCase----------------------------------------------
-- Rule for metrics PackageCase
helper def: packageCase() : Set(smm!Measure) =
java!CompilationUnit.allInstances()
->select(p | not p.package.oclIsUndefined() and p.package.name.substring(1, 1)=p.package.name.substring(1, 1).toUpper())
->collect(p | thisModule.MeasurePackageCase(p));
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