Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Yannis LE BARS
Source Code Analyzer
Commits
54d2ed2b
Commit
54d2ed2b
authored
Dec 12, 2019
by
E19C506H
Browse files
AvoidEnumAsIdentifier
parent
8b92f1d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
input/avoid-enum-as-identifier.xmi
0 → 100644
View file @
54d2ed2b
<?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>
src/main/atl/analysis.atl
View file @
54d2ed2b
...
...
@@ -52,6 +52,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.EmptyInitializer(),
thisModule.ExcessiveClassLength(),
thisModule.CloneMethodMustBePublic(),
thisModule.AvoidEnumAsIdentifier(),
-- Design rules
--
thisModule.tooManyFields(),
...
...
@@ -1268,4 +1269,23 @@ rule MeasureCloneMethodMustBePublic(w: java!MethodDeclaration) {
do {
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
src/main/atl/codestyle.atl
View file @
54d2ed2b
...
...
@@ -102,6 +102,12 @@ helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
->select (w | w.modifier <> 'public')
->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));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment