Commit b8a00c8e authored by BRAULT Benjamin's avatar BRAULT Benjamin Committed by Gerson SUNYE
Browse files

Abstract class without any method

parent 3c560f2d
<?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="IfStmtsMustUseBraces">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ClassWithIfStmtsMustUseBraces">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ClassWithIfStmtsMustUseBraces">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="nobraces">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="x" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.1/@expression/@leftHandSide //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.2/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.2/@thenStatement/@expression/@operand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.3/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.3/@thenStatement/@expression/@operand"/>
<modifier/>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@fragments.0"/>
<rightHandSide xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
</expression>
</statements>
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="==">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@fragments.0"/>
</expression>
<thenStatement xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@fragments.0"/>
</expression>
</thenStatement>
</statements>
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="==">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="3"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@fragments.0"/>
</expression>
<thenStatement xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@fragments.0"/>
</expression>
</thenStatement>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="braces">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="z" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@leftHandSide //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@thenStatement/@statements.0/@expression/@operand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.3/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.3/@thenStatement/@statements.0/@expression/@operand"/>
<modifier/>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
<rightHandSide xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
</expression>
</statements>
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="==">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
</expression>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
</expression>
</statements>
</thenStatement>
</statements>
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="==">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="3"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
</expression>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
</expression>
</statements>
</thenStatement>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="ClassWithIfStmtsMustUseBraces.java" originalFilePath="C:\Users\forma\eclipse-workspace_2019\IfStmtsMustUseBraces\src\ClassWithIfStmtsMustUseBraces.java" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
<?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>
This diff is collapsed.
......@@ -57,6 +57,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Design rules
--
thisModule.ExcessiveClassLength(),
thisModule.IfBraces(),
thisModule.excessiveParameterList(),
thisModule.finalFieldCouldBeStatic(),
thisModule.longInstantiation(),
......@@ -65,6 +66,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.signatureDeclareThrowsException(),
thisModule.tooManyFields(),
thisModule.tooManyMethods(),
thisModule.SimplifyBooleanAssertion(),
thisModule.abstractClassWithoutAnyMethod(),
-- Performance rules
--
......@@ -81,7 +84,6 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Documentation rules
--
thisModule.commentContent(),
-- Error prone rules
--
......@@ -1298,7 +1300,6 @@ rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) {
measurement: smm!DirectMeasurement (
error <- class.name + ' class have no package declaration'
)
do {
noc;
}
......@@ -1571,4 +1572,87 @@ rule MeasureMethodWithSameNameAsEnclosingClass(method : java!MethodDeclaration)
do {
noc;
}
}
\ No newline at end of file
}
--------------------------------------------- ExcessiveImports ---------------------------------------------
-- creates a new Measure when a class has more than 4 imports
rule MeasureExcessiveImports(i : java!CompilationUnit) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExcessiveImports',
shortDescription <- 'A high number of imports can indicate a high degree of coupling within an object. This rule counts the number of unique imports and reports a violation if the count is above the user-specified threshold.'
),
measurement: smm!DirectMeasurement (
error<-'The class '+ i.name + ' has an excessive imports.',
value<- i.imports.size()
)
do {
noc;
}
}
--------------------------------------------- IfStmtsMustUseBraces ---------------------------------------------
-- creates a new Measure when a class that contains an if statement without braces.
rule MeasureIfStmtsMustUseBraces(i : java!IfStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'If then Statement must use braces',
shortDescription <- 'Deprecated Avoid using if statements without using braces to surround the code block. If the code formatting...'
),
measurement: smm!DirectMeasurement (
error <- 'The class ' + condition.originalCompilationUnit.name + ' has an if statement without braces. '
)
do {
noc;
}
}
--------------------------------------------- SimplifyBooleanAssertion ---------------------------------------------
-- creates a new Measure when a class contains a negation in an assertTrue or assertFalse.
rule MeasureSimplifyBooleanAssertion(i : java!PrefixExpression) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'SimplifyBooleanAssertion',
shortDescription <- 'Avoid negation in an assertTrue or assertFalse test.'
),
measurement: smm!DirectMeasurement (
error<-'The method test ' + i.eContainer().eContainer().eContainer().eContainer().name + ' contains a negation in an assertTrue or assertFalse.'
)
do {
noc;
}
}
--------------------------------------------- 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;
}
}
......@@ -59,8 +59,6 @@ helper def: longVariable() : Set(smm!Measure) =
-> select( variable | variable.name.size() > 17)
-> collect (variable | thisModule.MeasureLongVariable(variable));
--------------------------------------------- ShortVariableName ---------------------------------------------
-- Rule for metrics shortVariableName : return the set of variables measures that violates the rule.
helper def: shortVariableName() : Set(smm!Measure) =
......@@ -102,4 +100,12 @@ helper def: misLeadingVariableName() : Set(smm!Measure) =
-> union(java!SingleVariableDeclaration.allInstances())
-> select(variable | variable.name.size() >= 2)
-> select(variable | variable.name.substring(1,2) = 'm_')
-> collect(variable | thisModule.MeasureMisLeadingVariableName(variable));
\ No newline at end of file
-> collect(variable | thisModule.MeasureMisLeadingVariableName(variable));
--------------------------------------------- IfStmtsMustUseBraces ---------------------------------------------
-- Helper for issue IfStmtsMustUseBraces : return a Measure for each class that contains an if statement without braces.
helper def: IfBraces() : Set(smm!Measure) =
java!IfStatement.allInstances()
-> select(i | i.thenStatement <> OclUndefined)
-> select(i | not i.thenStatement.oclIsTypeOf(java!Block))
-> collect(i | thisModule.MeasureIfStmtsMustUseBraces(i));
......@@ -114,8 +114,6 @@ helper def: avoidThrowingNullPointerException() : Set(smm!Measure) =
->select(c | c.method.name = 'NullPointerException')
->collect(c | thisModule.MeasureAvoidThrowingNullPointerException(c));
--- Issue #738
--- helper ExcessiveClassLength
......@@ -132,4 +130,20 @@ helper def: ExcessiveClassLength() : Set(smm!Measure) =
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveClassLength(w));
--------------------------------------------- SimplifyBooleanAssertion ---------------------------------------------
-- Helper for issue SimplifyBooleanAssertion : return a Measure for each method that contains an assertion of type : !(expression).
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));
--------------------------------------------- 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