Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
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
170ce5c4
Commit
170ce5c4
authored
Dec 05, 2019
by
Louis QUESTEL
Committed by
Gerson SUNYE
Dec 05, 2019
Browse files
fix #679, ExtendsObject 2pts
parent
2226dce2
Changes
3
Hide whitespace changes
Inline
Side-by-side
input/extends-object.xmi
0 → 100644
View file @
170ce5c4
<?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=
"ExtendsObjectRule"
>
<ownedElements
name=
"(default package)"
>
<ownedElements
xsi:type=
"java:ClassDeclaration"
originalCompilationUnit=
"//@compilationUnits.0"
name=
"ExtendsObjectNotPass1"
>
<modifier
visibility=
"public"
/>
<superClass
type=
"//@ownedElements.1/@ownedPackages.0/@ownedElements.0"
>
<qualifier
xsi:type=
"java:PackageAccess"
package=
"//@ownedElements.1/@ownedPackages.0"
>
<qualifier
package=
"//@ownedElements.1"
/>
</qualifier>
</superClass>
</ownedElements>
<ownedElements
xsi:type=
"java:ClassDeclaration"
originalCompilationUnit=
"//@compilationUnits.1"
name=
"ExtendsObjectNotPass2"
>
<modifier
visibility=
"public"
/>
<superClass
type=
"//@ownedElements.1/@ownedPackages.0/@ownedElements.0"
/>
</ownedElements>
<ownedElements
xsi:type=
"java:ClassDeclaration"
originalCompilationUnit=
"//@compilationUnits.2"
name=
"ExtendsObjectPass1"
>
<modifier
visibility=
"public"
/>
</ownedElements>
</ownedElements>
<ownedElements
name=
"java"
proxy=
"true"
usagesInPackageAccess=
"//@ownedElements.0/@ownedElements.0/@superClass/@qualifier/@qualifier"
>
<ownedPackages
name=
"lang"
proxy=
"true"
usagesInPackageAccess=
"//@ownedElements.0/@ownedElements.0/@superClass/@qualifier"
>
<ownedElements
xsi:type=
"java:ClassDeclaration"
name=
"Object"
proxy=
"true"
usagesInTypeAccess=
"//@ownedElements.0/@ownedElements.0/@superClass //@ownedElements.0/@ownedElements.1/@superClass"
/>
</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=
"ExtendsObjectNotPass1.java"
originalFilePath=
"C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectNotPass1.java"
types=
"//@ownedElements.0/@ownedElements.0"
/>
<compilationUnits
name=
"ExtendsObjectNotPass2.java"
originalFilePath=
"C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectNotPass2.java"
types=
"//@ownedElements.0/@ownedElements.1"
/>
<compilationUnits
name=
"ExtendsObjectPass1.java"
originalFilePath=
"C:\Users\33659\Gerson-workspace\ExtendsObjectRule\src\ExtendsObjectPass1.java"
types=
"//@ownedElements.0/@ownedElements.2"
/>
</java:Model>
src/main/atl/analysis.atl
View file @
170ce5c4
...
...
@@ -47,6 +47,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.tooManyStaticImports(),
thisModule.AvoidDollarSigns(),
thisModule.shortClassName(),
thisModule.extendsObject(),
-- Design rules
--
...
...
@@ -717,3 +718,26 @@ rule MeasureFinalFieldCouldBeStatic(field : java!FieldDeclaration) {
noc;
}
}
--------------------------------------------- MeasureExtendsObject ---------------------------------------------
-- A Measure instance if the class violates the rule ExtendsObject.
rule MeasureExtendsObject(variable : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExtendsObject',
shortDescription <- 'No need to explicitly extend Object.'
),
measurement: smm!DirectMeasurement (
error<-'In the Class '+ variable.name + ' No need to explicitly extend Object.'
)
do {
noc;
}
}
src/main/atl/codestyle.atl
View file @
170ce5c4
...
...
@@ -33,4 +33,18 @@ helper def: tooManyStaticImports() : Set(smm!Measure) =
-- Add a new measurement if there are more than 4 static imports in the file.
-> select (c | c.types.first().oclIsTypeOf(java!ClassDeclaration) and c.imports->select(i | i.static)->size() > 4)
-> collect(c | thisModule.MesureTooManyStaticImports(c));
--------------------------------------------- ExtendsObject ---------------------------------------------
-- Rule for metrics ExtendsObject
helper def: extendsObject() : Set(smm!Measure) =
-- select all class with a superTyper
java!ClassDeclaration.allInstances()->select(it | (it.superClass <> OclUndefined))
-- select all class create by the user
->select(it2| it2.proxy = false)
-- select all class who extend Object
->select(it3| it3.superClass.type.name = 'java.lang.Object' or it3.superClass.type.name = 'Object')
-- collect all results and send an error message
->collect(it4|thisModule.MeasureDoNotExtendJavaLangError(it4))
;
Write
Preview
Markdown
is supported
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