Commit 607b0ec2 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Conflict resolution

parents 701957f7 1f57ac8c
<?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="j-unit-static-suite">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest837_a">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="suite">
<modifier visibility="public"/>
<modifier static="true"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest837_b">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="suite">
<modifier visibility="public"/>
<modifier static="false"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest837_c">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="suite">
<modifier visibility="private"/>
<modifier static="true"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest837_d">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="suite">
<modifier visibility="private"/>
<modifier static="false"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest837_2">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="suite">
<modifier visibility="private"/>
<modifier static="false"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="junit" proxy="true">
<ownedPackages name="framework" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="TestCase" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@superClass">
</ownedElements>
</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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="FooTest.java" originalFilePath="/home/roschan/Projets/Eclipse/eclipse-workspace3/ATL/j-unit-static-suite/src/FooTest.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="j-unit-test-contains-too-many-asserts">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest633">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testWith1Assert">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testWith3Asserts">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="notATestBut3Asserts">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest633_2">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testInvalidClass">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="junit" proxy="true">
<ownedPackages name="framework" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="TestCase" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@superClass">
</ownedElements>
</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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="FooTest.java" originalFilePath="/home/roschan/Projets/Eclipse/eclipse-workspace3/ATL/j-unit-test-contains-too-many-asserts/src/FooTest.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="j-unit-test-should-include-assert">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest634">
<modifier visibility="public"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testWithAssert">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:AssertStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testWithoutAssert">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="notATestAndNoAssert">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest634_2">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="testInvalidClass">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="junit" proxy="true">
<ownedPackages name="framework" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="TestCase" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@superClass">
</ownedElements>
</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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="FooTest.java" originalFilePath="/home/roschan/Projets/Eclipse/eclipse-workspace3/ATL/j-unit-test-should-include-assert/src/FooTest.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="switch-stmts-should-have-default">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FooTest646">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="methodWithSwitchKo">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:SwitchStatement" originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Integer" originalCompilationUnit="//@compilationUnits.0" value="1"/>
</statements>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Integer" originalCompilationUnit="//@compilationUnits.0" value="2"/>
</statements>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Integer" originalCompilationUnit="//@compilationUnits.0" value="3"/>
</statements>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="FooTest646_2">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="methodWithSwitchOk">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.1">
<statements xsi:type="java:SwitchStatement" originalCompilationUnit="//@compilationUnits.1">
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.1">
<expression xsi:type="java:Integer" originalCompilationUnit="//@compilationUnits.1" value="1"/>
</statements>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.1">
<expression xsi:type="java:Integer" originalCompilationUnit="//@compilationUnits.1" value="2"/>
</statements>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.1" default="true"/>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</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" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="FooTest646.java" originalFilePath="/home/roschan/Projets/Eclipse/eclipse-workspace3/ATL/switch-stmts-should-have-default/src/FooTest646.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="FooTest646_2.java" originalFilePath="/home/roschan/Projets/Eclipse/eclipse-workspace3/ATL/switch-stmts-should-have-default/src/FooTest646_2.java" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
This diff is collapsed.
......@@ -30,7 +30,6 @@ helper def: avoidFieldNameMatchingMethodName() : Set(smm!Measure) =
)
);
--- Goes through all the methods to check if the following rule is followed:
--- Avoid printStackTrace()
helper def: avoidPrintStackTrace() : Set(smm!Measure) =
......@@ -62,7 +61,6 @@ helper def: avoidReassigningParameters(): Set(smm!Measure) =
)->flatten();
--- Rule for metrics AvoidStringBufferField
-- TODO: improve comment
helper def: avoidStringBufferField() : Set(smm!Measure) =
......@@ -71,7 +69,6 @@ helper def: avoidStringBufferField() : Set(smm!Measure) =
->select(dec | ( dec.type.type.name = 'StringBuffer' or dec.type.type.name = 'StringBuilder'))
->collect(dec | thisModule.MeasureAvoidStringBufferField(dec));
--- Detects the use of empty statements blocks. These blocks serve no purpose and should be removed
helper def: emptyStatementBlock() : Set(smm!Measure) =
java!Block.allInstances()
......@@ -125,16 +122,65 @@ helper context java!VariableDeclarationExpression def: nbLocalVariableDeclaratio
self.fragments.size(); -- The fragments collection contains all the variable declarations of an initializer*
-- Initializer* : for(int x = 0; ...), "int x = 0" is the initializer part of the for loop
--- helper for the rule JUnitTestsShouldIncludeAssert
--TODO ne couvre pas du tout tous les cas possibles que fait le vrai PMD (mockito, etc.)
helper def: jUnitTestsShouldIncludeAssert() : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> select(cl | cl.isTestClass())
-> iterate(i; res : Set(smm!Measure) = Set{} | i.bodyDeclarations
-> select(mtd |
mtd.oclIsTypeOf(java!MethodDeclaration)
and mtd.isTestMethod()
and mtd.numberOfAsserts() < 1
)
-> collect(mtd | thisModule.MeasureJUnitTestsShouldIncludeAssert(mtd, i))
);
-- counts the number of assertions in a method declaration
helper context java!MethodDeclaration def: numberOfAsserts() : Integer =
if self.getBody() = OclUndefined then 0 else
self.getBody().statements
-> select(sttm | sttm <> OclUndefined) -- utile?
-> select(sttm | sttm.oclIsTypeOf(java!AssertStatement))
-> size()
endif;
-- tells if a method is a test (assuming its class is a TestCase)
-- XXX we maybe could check the annotation too?
helper context java!MethodDeclaration def: isTestMethod() : Boolean =
self.name.substring(1, 4) = 'test';
-- tells if a class extends TestCase
helper context java!ClassDeclaration def: isTestClass() : Boolean =
if self.superClass <> OclUndefined then -- the condition is needed because
-- using "and" doesn't prevent the execution of the rest of the expression
-- for some reason, so an error occurs
self.superClass.type.name = 'junit.framework.TestCase' or self.superClass.type.name = 'TestCase'
else
false
endif;
--- helper for the rule JUnitTestContainsTooManyAsserts
helper def: jUnitTestContainsTooManyAsserts(maximumAsserts : Integer) : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> select(cl | cl.isTestClass())
-> iterate(i; res : Set(smm!Measure) = Set{} | i.bodyDeclarations
-> select(mtd |
mtd.oclIsTypeOf(java!MethodDeclaration)
and mtd.isTestMethod()
and mtd.numberOfAsserts() > maximumAsserts
)
-> collect(mtd | thisModule.MeasureJUnitTestContainsTooManyAsserts(mtd, i, maximumAsserts))
);
-- #TODO: Add comment
helper def: oneDeclarationPerLine(): Set(smm!Measure) =
java!VariableDeclarationStatement.allInstances()
->select(s | s.fragments.size()>1)
->collect(s | thisModule.MeasureOneDeclarationPerLine(s));
--- Rule for metrics SwitchDensity :
-- #TODO: Improve comment
-- #TODO: Improve comment
helper def: switchDensity() : Set (smm!Measure) =
-- Browse through all Switch Statements
java!SwitchStatement.allInstances()->iterate(switchCase; res : Set(smm!Measure) = Set{} |
......@@ -145,13 +191,25 @@ helper def: switchDensity() : Set (smm!Measure) =
->collect(switchStatement | thisModule.MeasureSwitchDensity(switchCase))
);
--- helper for the rule for metrics SwitchStmtsShouldHaveDefault
helper def: switchStmtsShouldHaveDefault() : Set(ssm!Measures) =
java!SwitchStatement.allInstances()
-> select(switchSt | not switchSt.hasDefaultCase())
-> collect(switchSt | thisModule.MeasureSwitchStmtsShouldHaveDefault(switchSt));
-- TODO improve comment
helper context java!SwitchStatement def: hasDefaultCase() : Boolean =
self.statements
-> select(case | case.oclIsTypeOf(java!SwitchCase))
-> select(case | case.isDefault())
-> size() > 0;
--- Rule for metrics UnusedLocalVariable :
helper def: unusedLocalVariable(): Set(ssm!Measures) =
java!VariableDeclarationFragment.allInstances()
-> select(variable | variable.originalCompilationUnit.name = 'LocalVariable.java')
-> select(variable | variable.usageInVariableAccess.isEmpty())
-> collect(variable | thisModule.MeasureUnusedLocalVariable(variable))
;
java!VariableDeclarationFragment.allInstances()
-> select(variable | variable.originalCompilationUnit.name = 'LocalVariable.java')
-> select(variable | variable.usageInVariableAccess.isEmpty())
-> collect(variable | thisModule.MeasureUnusedLocalVariable(variable));
-- #TODO: Add comment
helper def: useAssertSameInsteadOfAssertTrue() : Set(smm!Measure) =
......@@ -171,8 +229,6 @@ helper def: useAssertTrueInsteadOfAssertEquals() : Set(smm!Measure) =
->select(assert | thisModule.isWrongUseAssertTrueInsteadOfAssertEquals(assert))
->collect(assert | thisModule.MesureUseAssertTrueInsteadOfAssertEquals(assert));
-- Attention !!!
-- Before adding a rule to the end of file, ensure that you are respecting the
......
......@@ -15,7 +15,6 @@ helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Bool
-- the number of break statements => we don't have a break statement for every switch case
-- in that case, return true, else false
(thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbEmptySwitchCasesOfASwitchStatement(ss)) > thisModule.nbBreakStatementOfASwitchStatement(ss)
;
--------------------------------------------- DoNotExtendJavaLangThrowable ---------------------------------------------
......@@ -31,6 +30,7 @@ helper def: doNotExtendJavaLangThrowable() : Set(smm!Measure) =
-- collect all results and send an error message
->collect(it4|thisModule.MeasureDoNotExtendJavaLangThrowable(it4))
;
--------------------------------------------- SuspiciousEqualsMethodName---------------------------------------------
--Detects the declaration of methods whose name and parameters looks like the equals(Object) method, which denote an intention to override the equals(Object) method.
......@@ -64,10 +64,7 @@ helper def: isWrongEqualsDeclaration(method : java!MethodDeclaration) : Boolean
method.parameters.first().type.type.name = 'Object' and
method.returnType.type.name = 'boolean'
);
--Allows to have the signature of a method as a String.
helper context java!MethodDeclaration def: toString() : String =
if self.hasReturnType() then
......@@ -143,10 +140,8 @@ helper context java!VariableDeclarationFragment def: variableIsObject() : Boolea
self.variablesContainer.type.type.oclIsTypeOf(java!ClassDeclaration);
----------
--------------------------------------------------------------------------------------------------------
------------------------------------------- AvoidCallingFinalize----------------------------------------------
--------------------------------------------------------------------------------
----------------------------- AvoidCallingFinalize -----------------------------
-- Rule for metrics AvoidCallingFinalize
helper def: avoidCallingFinalize() : Set(smm!Measure) =
java!MethodInvocation.allInstances()
......@@ -167,7 +162,8 @@ helper def: emptyWhileStmt() : Set(smm!Measure) =
->select( w | w.body.oclIsTypeOf(java!Block))
->select(w | w.body.statements.isEmpty())
->collect(w | thisModule.MeasureEmptyWhileStmt(w));
------------------------------------------- MeasureDontImportSun----------------------------------------------
--------------------------------- MeasureDontImportSun -------------------------------------
-- Rule for metrics DontImportSun
helper def: dontImportSun() : Set(smm!Measure) =
java!Package.allInstances()
......@@ -182,7 +178,6 @@ helper def: finalizeShouldBeProtected() : Set(smm!Measure) =
->select(m | m.name = 'finalize' and m.modifier.visibility.toString() <> 'protected')
->collect(m | thisModule.MesureFinalizeShouldBeProtected(m));
--------------------------------------------------------------------------------------------------------------
--------------------------------------------DontUseFloatTypeForLoopIndices------------------------------------
......@@ -191,11 +186,7 @@ helper def: dontUseFloatTypeForLoopIndices() : Set(smm!Measure) =
-> select(loop | loop.initializers.type.type = '//@orphanType.2')
-> collect(loop | thisModule.MeasureDontUseFloatTypeForLoopIndices())
;
--------------------------------------------- EmptySwitchStatement ---------------------------------------------
......@@ -207,13 +198,12 @@ helper def: emptySwitchStatement() : Set(smm!Measure) =
------------------------------------------ EmptySynchronizedBlock ---------------------------------------------
--Detects the use of empty synchronized block. These blocks serve no purpose and should be removed
helper def: emptySynchronizedBlock() : Set(smm!Measure) =
java!SynchronizedStatement.allInstances()
->select(synchronizedBlock | synchronizedBlock.body.statements.isEmpty() )
->collect(synchronizedBlock | thisModule.MeasureEmptySynchronizedBlock(synchronizedBlock));
---------------------------------------- EmptyFinallyBlock----------------------------------------------
-- Rule for metrics EmptyFinallyBlock
helper def: emptyFinallyBlock() : Set(smm!Measure) =
......@@ -229,9 +219,6 @@ helper def: emptyfinalizeMethod() : Set(smm!Measure) =
->select( finalizeMethod | finalizeMethod.name = 'finalize' and finalizeMethod.body.statements.isEmpty())
->collect(finalizeMethod| thisModule. MeasureEmptyFinalizer(finalizeMethod));
--- Issues #780, #784, #799, #819, #862, #871
--- helper AvoidCatchingNPE
......@@ -311,28 +298,28 @@ helper def: UseProperClassLoader() : Set(smm!Measure) =
->collect(w | thisModule.MeasureUseProperClassLoader(w));
-----------------------------------------avoidCatchingThrowable----------------------------------------------
---------------------------------- avoidCatchingThrowable -----------------------------------------
-- Rule for metrics avoidCatchingThrowable
helper def: avoidCatchingThrowable() : Set(smm!Measure) =
java!CatchClause.allInstances()
->select(catch | catch.exception.type.type.name = 'Throwable')
->collect(catch | thisModule.MeasureAvoidCatchingThrowable(catch));
-----------------------------------------DoNotCallGarbageCollectionExplicitly----------------------------------------------
-------------------------- DoNotCallGarbageCollectionExplicitly --------------------------------
-- Rule for metrics DoNotCallGarbageCollectionExplicitly
helper def: doNotCallGarbageCollectionExplicitly() : Set(smm!Measure) =
java!MethodInvocation.allInstances()
->select(method | method.method.name = 'gc' and method.method.proxy)
->collect(method | thisModule.MeasureDoNotCallGarbageCollectionExplicitly(method));
-----------------------------------------EmptyCatchBlock----------------------------------------------
------------------------------- EmptyCatchBlock -------------------------------------
-- Rule for metrics EmptyCatchBlock
helper def: emptyCatchBlock() : Set(smm!Measure) =
java!CatchClause.allInstances()
->select(catch | catch.body.statements.size() = 0)
->collect(catch | thisModule.MeasureEmptyCatchBlock(catch));
-----------------------------------------ImportFromSamePackage----------------------------------------------
------------------------------- ImportFromSamePackage -----------------------------------
-- Rule for metrics ImportFromSamePackage
helper def: importFromSamePackage() : Set(smm!Measure) =
java!ImportDeclaration.allInstances()
......@@ -341,20 +328,30 @@ helper def: importFromSamePackage() : Set(smm!Measure) =
-- ------------------------------------------- JUnitSpelling ---------------------------------------------
--- Helper for issue JUnitSpelling : Some JUnit framework methods are easy to misspell !("tearDown", "setUp").
helper def: junitSpelling() : Set(smm!Measure) =
helper def: junitSpelling() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
-> select(i | ((i.name <> 'tearDown' and i.name <> 'setUp') and (i.name.toLower() = 'teardown' or i.name.toLower() = 'setup')))
-> collect(i | thisModule.MeasureJUnitSpelling(i));
-----------------------------------------MethodWithSameNameAsEnclosingClass----------------------------------------------
-- --------------------------- JUnitStaticSuite --------------------------------
--- Helper for issue JUnitStaticSuite : in JUnit TestCase, the method "suite" has to be both public and static
helper def: jUnitStaticSuite() : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> select(cl | cl.isTestClass())
-> iterate(i; res : Set(smm!Measure) = Set{} | i.bodyDeclarations
-> select(mtd | mtd.oclIsTypeOf(java!MethodDeclaration) and mtd.name = 'suite')
-> reject(mtd | mtd.modifier.visibility.toString() = 'public' and mtd.modifier.static = false)
-> collect(mtd | thisModule.MeasureJUnitStaticSuite(i))
);
-------------------------------- MethodWithSameNameAsEnclosingClass ----------------------------------
-- Rule for metrics MethodWithSameNameAsEnclosingClass
helper def: methodWithSameNameAsEnclosingClass() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select(method | method.name = method.abstractTypeDeclaration.name)
->collect(method | thisModule.MeasureMethodWithSameNameAsEnclosingClass(method));
------------------------------------------- testClassWithoutTest ------------------------------------------------------------------------------------
-------------------------- testClassWithoutTest --------------------------------
helper def: testClassWithoutTest() : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
......@@ -370,7 +367,7 @@ helper context java!ClassDeclaration def: nbTestMethod() : Integer =
-> select(bodyDeclaration | bodyDeclaration.name.size() > 4)
-> select(each | each.name.substring(1, 4) = 'test')
-> size();
--------------------------------------------- DoNotCallSystemExit ---------------------------------------------
-- Detects if the method "exit" of the System or Runtime class is called
......@@ -444,7 +441,7 @@ helper context java!CompilationUnit def: hasJunitAnnotation() : Boolean =
-> select(it | it.importedElement.package.package.package.name = 'junit')
;
--------------------------------------------- SuspiciousHashcodeMethodName ---------------------------------------------
-------------------------------- SuspiciousHashcodeMethodName --------------------------------------
helper def: suspiciousHashcodeMethodName(): Set(smm!Measure) =
java!MethodDeclaration.allInstances()
......@@ -514,13 +511,13 @@ helper context java!SingleVariableAccess def : isString() : Boolean =
--- Called if an operand is a string literal
--- Always return true
helper context java!StringLiteral def : isString() : Boolean =
helper context java!StringLiteral def : isString() : Boolean =
true;
--- Called if the operand is 'this'
--- Return true : the expression is of type String
--- return false otherwise
helper context java!ThisExpression def: isString() : Boolean =
helper context java!ThisExpression def: isString() : Boolean =
self.originalCompilationUnit.types
->exists(name | name = 'String');
......@@ -534,7 +531,7 @@ helper context java!Expression def: isString() : Boolean =
--- Param variable : A java declaration of a variable
--- Return true : variable is a string
--- return false otherwise
helper def: variableIsString(variable : java!VariableDeclaration) : Boolean =
helper def: variableIsString(variable : java!VariableDeclaration) : Boolean =
variable.variableIsString();
--- Called when the context is MethodDeclaration
......@@ -554,7 +551,7 @@ helper context java!SingleVariableAccess def: variableIsString() : Boolean =
--- Called when the context is a SingleVariableDeclaration
--- See : variableIsString(variable : java!VariableDeclaration)
helper context java!SingleVariableDeclaration def: variableIsString() : Boolean =
helper context java!SingleVariableDeclaration def: variableIsString() : Boolean =
self.type.type.name = 'String';
--- Called when the context is AbstractMethodDeclaration
......@@ -609,7 +606,7 @@ helper def: nonStaticInitializer() : Set(smm!Measure) =
-> select(i | i.modifier.static = false)
-> collect (i | thisModule.MeasureNonStaticInitializer(i));
--------------------------------------------- SimpleDateFormatNeedsLocale ---------------------------------------------
---------------------------------- SimpleDateFormatNeedsLocale -----------------------------------
--- Indicates if a SimpleDateFormat variable has no Locale parameter
helper def: simpleDateFormatNeedsLocale() : Set(smm!Measure) =
......@@ -618,7 +615,7 @@ helper def: simpleDateFormatNeedsLocale() : Set(smm!Measure) =
-> select(i | i.initializer <> OclUndefined) -> select(i | i.initializer.arguments.size() <= 1 and i.initializer.type.type.name = 'SimpleDateFormat')
-> collect (i | thisModule.MeasureSimpleDateFormatNeedsLocale(i));
--------------------------------------------- NonCaseLabelInSwitchStatement ---------------------------------------------
----------------------------------- NonCaseLabelInSwitchStatement --------------------------------------
--- Indicates if a non-case label is present in a switch statement.
helper def: nonCaseLabelInSwitchStatement() : Set(smm!Measure) =
......@@ -627,3 +624,5 @@ helper def: nonCaseLabelInSwitchStatement() : Set(smm!Measure) =
-> select(i | i.name <> 'case :' and i.name <> 'default:')
-> collect (i | thisModule.MeasureNonCaseLabelInSwitchStatement(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