Commit 7faa5f34 authored by LePandaRoox's avatar LePandaRoox
Browse files

Fixed issue #723 AbstractClassWithoutAnyMethod

parent e5057704
<?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="AbstractClassWithoutAnyMethod">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ExampleClassAbstractWithMethod">
<modifier visibility="public" inheritance="abstract"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier/>
<type type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="field"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="otherField"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="workInOtherField">
<modifier visibility="public" inheritance="abstract"/>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="workInOtherFieldButNoAbstract">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="0"/>
</statements>
</body>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.2" name="ExampleClassNoAbstract">
<modifier visibility="public"/>
</ownedElements>
</ownedElements>
<ownedElements name="">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ExampleClassAbstractWithoutMethod">
<modifier visibility="public" inheritance="abstract"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="field"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="otherField"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.1/@ownedElements.0/@bodyDeclarations.0/@type">
<superInterfaces type="//@ownedElements.2/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@returnType //@ownedElements.1/@ownedElements.0/@bodyDeclarations.1/@type"/>
<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="ExampleClassAbstractWithMethod.java" originalFilePath="C:\Users\forma\Documents\Workspace\W_GIT\AbstractClassWithoutAnyMethod\src\ExampleClassAbstractWithMethod.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ExampleClassAbstractWithoutMethod.java" originalFilePath="C:\Users\forma\Documents\Workspace\W_GIT\AbstractClassWithoutAnyMethod\src\ExampleClassAbstractWithoutMethod.java" package="//@ownedElements.1" types="//@ownedElements.1/@ownedElements.0"/>
<compilationUnits name="ExampleClassNoAbstract.java" originalFilePath="C:\Users\forma\Documents\Workspace\W_GIT\AbstractClassWithoutAnyMethod\src\ExampleClassNoAbstract.java" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
......@@ -65,6 +65,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.signatureDeclareThrowsException(),
thisModule.avoidThrowingNullPointerException(),
thisModule.SimplifyBooleanAssertion(),
thisModule.abstractClassWithoutAnyMethod(),
-- Performance rules
--
......@@ -1200,3 +1201,24 @@ rule MeasureIfStmtsMustUseBraces(i : java!IfStatement) {
}
}
--------------------------------------------- AbstractClassWithoutAnyMethod ---------------------------------------------
-- creates a new Measure when an abstract class does not provides any methods.
rule MeasureAbstractClassWithoutAnyMethod(i : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AbstractClassWithoutAnyMethod',
shortDescription <- 'If an abstract class does not provides any methods, it may be acting as a simple data containerth...'
),
measurement: smm!DirectMeasurement (
error<-'The class anstract' + i.name + ' has not method.'
)
do {
noc;
}
}
......@@ -120,4 +120,14 @@ helper def: SimplifyBooleanAssertion() : Set(java!PrefixExpression) =
java!PrefixExpression.allInstances()
-> select(i | i.operator.toString() = '!')
-> select(i | i.eContainer().method.name = 'assertTrue' or i.eContainer().method.name = 'assertFalse')
-> collect(i | thisModule.MeasureSimplifyBooleanAssertion(i));
\ No newline at end of file
-> collect(i | thisModule.MeasureSimplifyBooleanAssertion(i));
--------------------------------------------- AbstractClassWithoutAnyMethod ---------------------------------------------
-- Rule for metrics AbstractClassWithoutAnyMethod : return the set of class Measures that violates the rule.
helper def: abstractClassWithoutAnyMethod() : Set(smm!Measure) =
-- Browse through all class
java!ClassDeclaration.allInstances()
-> select(i | i.bodyDeclarations -> select(r | r.oclIsTypeOf(java!MethodDeclaration)) -> size() = 0)
-> select(i | i.modifier <> OclUndefined)
-> select(i | i.modifier.inheritance -> toString() = 'abstract')
-> collect(i | thisModule.MeasureAbstractClassWithoutAnyMethod(i));
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