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
f0b9040a
Commit
f0b9040a
authored
Dec 12, 2019
by
E19C506H
Browse files
EmptyInitializer
parent
dc04d99f
Changes
3
Hide whitespace changes
Inline
Side-by-side
input/empty-initializer.xmi
0 → 100644
View file @
f0b9040a
<?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>
src/main/atl/analysis.atl
View file @
f0b9040a
...
...
@@ -49,6 +49,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.noPackageDeclaration(),
thisModule.UnconditionalIfStatement(),
thisModule.EmptyInitializer(),
-- Design rules
--
thisModule.tooManyFields(),
...
...
@@ -1208,4 +1209,22 @@ rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
do {
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
src/main/atl/codestyle.atl
View file @
f0b9040a
...
...
@@ -67,19 +67,21 @@ helper def: longVariable() : Set(smm!Measure) =
-> select( variable | variable.name.size() > 17)
-> collect (variable | thisModule.MeasureLongVariable(variable));
--====Khaled AMIRAT no package declaration
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
helper def: noPackageDeclaration() : Set(smm!Measure) =
-- Browse through all class(CompilationUnit)
java!CompilationUnit.allInstances()
->select(compUnit | compUnit.package.oclIsUndefined())
->collect(err | thisModule.MesureAvoidNoPackageDeclaration(err));
--====Khaled AMIRAT no package declaration
-- Rule for metrics noPackageDeclaration : return the set of class Measures that violates the rule.
-- Rule for metrics UnconditionalIfStatement : 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));
-- 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));
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