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
8b92f1d6
Commit
8b92f1d6
authored
Dec 12, 2019
by
E19C506H
Browse files
CloneMethodMustBePublic
parent
fbf1a695
Changes
3
Hide whitespace changes
Inline
Side-by-side
input/clone-method-must-be-public.xmi
0 → 100644
View file @
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=
"Foo"
usagesInTypeAccess=
"//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"
>
<modifier
visibility=
"public"
/>
<bodyDeclarations
xsi:type=
"java:MethodDeclaration"
originalCompilationUnit=
"//@compilationUnits.0"
name=
"clone"
>
<annotations
originalCompilationUnit=
"//@compilationUnits.0"
>
<type
type=
"//@ownedElements.1/@ownedPackages.0/@ownedElements.1"
/>
</annotations>
<modifier
visibility=
"protected"
/>
<body
originalCompilationUnit=
"//@compilationUnits.0"
>
<statements
xsi:type=
"java:ReturnStatement"
originalCompilationUnit=
"//@compilationUnits.0"
>
<comments
xsi:type=
"java:LineComment"
originalCompilationUnit=
"//@compilationUnits.0"
content=
"// Violation, must be public"
/>
<expression
xsi:type=
"java:NullLiteral"
originalCompilationUnit=
"//@compilationUnits.0"
/>
</statements>
</body>
<returnType
type=
"//@ownedElements.0/@ownedElements.0"
/>
</bodyDeclarations>
<superInterfaces
type=
"//@ownedElements.1/@ownedPackages.0/@ownedElements.0"
/>
</ownedElements>
</ownedElements>
<ownedElements
name=
"java"
proxy=
"true"
>
<ownedPackages
name=
"lang"
proxy=
"true"
>
<ownedElements
xsi:type=
"java:InterfaceDeclaration"
name=
"Cloneable"
proxy=
"true"
usagesInTypeAccess=
"//@ownedElements.0/@ownedElements.0/@superInterfaces.0"
/>
<ownedElements
xsi:type=
"java:AnnotationTypeDeclaration"
name=
"Override"
proxy=
"true"
usagesInTypeAccess=
"//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@annotations.0/@type"
/>
</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=
"Foo.java"
originalFilePath=
"D:\workSpace\Test\src\Foo.java"
commentList=
"//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@comments.0"
types=
"//@ownedElements.0/@ownedElements.0"
/>
</java:Model>
src/main/atl/analysis.atl
View file @
8b92f1d6
...
...
@@ -51,6 +51,7 @@ helper def: allMeasures(project: java!Model): Set(smm!Measure) =
thisModule.UnconditionalIfStatement(),
thisModule.EmptyInitializer(),
thisModule.ExcessiveClassLength(),
thisModule.CloneMethodMustBePublic(),
-- Design rules
--
thisModule.tooManyFields(),
...
...
@@ -1248,4 +1249,23 @@ rule MeasureExcessiveClassLength(w: java!MethodDeclaration) {
do {
noc;
}
}
-- A Measure instance if the class violates the rule CloneMethodMustBePublic.
rule MeasureCloneMethodMustBePublic(w: java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'CloneMethodMustBePublic',
shortDescription <- 'CloneMethodMustBePublic'
),
measurement: smm!DirectMeasurement (
error <- w.originalCompilationUnit.name+ 'the clone methode in here need to be public '
)
do {
noc;
}
}
\ No newline at end of file
src/main/atl/codestyle.atl
View file @
8b92f1d6
...
...
@@ -95,7 +95,12 @@ helper def: ExcessiveClassLength() : Set(smm!Measure) =
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveClassLength(w));
-- Rule for metrics ExcessiveClassLength : return the set of class Measures that violates the rule.
helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.modifier <> OclUndefined )
->select (w | w.modifier <> 'public')
->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