Commit 8b92f1d6 authored by E19C506H's avatar E19C506H
Browse files

CloneMethodMustBePublic

parent fbf1a695
<?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>
......@@ -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(),
......@@ -1249,3 +1250,22 @@ rule MeasureExcessiveClassLength(w: java!MethodDeclaration) {
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
......@@ -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));
......
Markdown is supported
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