Commit 54d2ed2b authored by E19C506H's avatar E19C506H
Browse files

AvoidEnumAsIdentifier

parent 8b92f1d6
<?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="A">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration">
<type/>
</bodyDeclarations>
</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="A.java" originalFilePath="D:\workSpace\Test\src\A.java" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
...@@ -52,6 +52,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) = ...@@ -52,6 +52,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.EmptyInitializer(), thisModule.EmptyInitializer(),
thisModule.ExcessiveClassLength(), thisModule.ExcessiveClassLength(),
thisModule.CloneMethodMustBePublic(), thisModule.CloneMethodMustBePublic(),
thisModule.AvoidEnumAsIdentifier(),
-- Design rules -- Design rules
-- --
thisModule.tooManyFields(), thisModule.tooManyFields(),
...@@ -1268,4 +1269,23 @@ rule MeasureCloneMethodMustBePublic(w: java!MethodDeclaration) { ...@@ -1268,4 +1269,23 @@ rule MeasureCloneMethodMustBePublic(w: java!MethodDeclaration) {
do { do {
noc; noc;
} }
}
-- A Measure instance if the class violates the rule AvoidEnumAsIdentifier.
rule MeasureAvoidEnumAsIdentifier(w: java!VariableDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidEnumAsIdentifier',
shortDescription <- 'AvoidEnumAsIdentifier'
),
measurement: smm!DirectMeasurement (
error <- w.originalCompilationUnit.name+ 'has a variable named to enum witch is a reserved name'
)
do {
noc;
}
} }
\ No newline at end of file
...@@ -102,6 +102,12 @@ helper def: CloneMethodMustBePublic() : Set(smm!Measure) = ...@@ -102,6 +102,12 @@ helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
->select (w | w.modifier <> 'public') ->select (w | w.modifier <> 'public')
->collect(w | thisModule.MeasureCloneMethodMustBePublic(w)); ->collect(w | thisModule.MeasureCloneMethodMustBePublic(w));
-- Rule for metrics AvoidEnumAsIdentifier : return the set of class Measures that violates the rule.
helper def: AvoidEnumAsIdentifier() : Set(smm!Measure) =
java!VariableDeclaration.allInstances()
->select (w | w.name <> OclUndefined )
->select (w | w.name = 'enum')
->collect(w | thisModule.MeasureCloneMethodMustBePublic(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