diff --git a/input/abstract-naming.xmi b/input/abstract-naming.xmi new file mode 100644 index 0000000000000000000000000000000000000000..01f134501301efb8399ebef773bb904f146ca0a2 --- /dev/null +++ b/input/abstract-naming.xmi @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/atl/analysis.atl b/src/main/atl/analysis.atl index 3027b10cd9f8d749ffb4e90df036b85f8125185c..ec9e4d9d6fd172f168add4786b1b253fbf4fe0e3 100644 --- a/src/main/atl/analysis.atl +++ b/src/main/atl/analysis.atl @@ -50,6 +50,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = thisModule.extendsObject(), thisModule.unnecessaryReturn(), thisModule.longVariable(), + thisModule.AbsctractNaming(), -- Design rules -- @@ -96,7 +97,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = -- Best practices rules thisModule.avoidThrowingNewInstanceOfSameException(), - thisModule.useAssertTrueInsteadOfAssertEquals(), + --thisModule.useAssertTrueInsteadOfAssertEquals(), thisModule.switchDensity() --thisModule.avoidStringBufferField() @@ -1095,7 +1096,25 @@ rule MesureFinalizeShouldBeProtected(m : java!MethodDeclaration) { } } - +------------------------------------------- AbsctractNaming---------------------------------------------- +-- A Measure instance if the abstract class are not named AbstractXXX' +rule ruleAbsctractNaming(tab :java!ClassDeclaration) { + to + om: smm!ObservedMeasure ( + measure <- noc, + measurements <- measurement + ), + noc: smm!DimensionalMeasure ( + name <- 'Abstract classes should be named AbstractXXX', + shortDescription <- 'Abstract classes should be named AbstractXXX' + ), + measurement: smm!DirectMeasurement ( + error<-'The Abstract classes'+ tab.name+' should be named AbstractXXX' + ) + do { + noc; + } +} diff --git a/src/main/atl/bestPractices.atl b/src/main/atl/bestPractices.atl index 42956c334c246ff6f55d1e956a75b946f986dbf4..16ca784e28e34412225b7d4b78f55087dc718625 100644 --- a/src/main/atl/bestPractices.atl +++ b/src/main/atl/bestPractices.atl @@ -63,29 +63,29 @@ helper def: switchDensity() : Set (smm!Measure) = ); --------------------------------------------- useAssertTrueInsteadOfAssertEquals --------------------------------------------- -helper def: useAssertTrueInsteadOfAssertEquals() : Set(smm!Measure) = +--helper def: useAssertTrueInsteadOfAssertEquals() : Set(smm!Measure) = -- Browse through all methods use - java!MethodInvocation.allInstances() + --java!MethodInvocation.allInstances() --Check if the method use is assertEqual and a Boolean is used - ->select(assert | thisModule.isWrongUseAssertTrueInsteadOfAssertEquals(assert) and assert.method.name = 'assertEquals') - ->collect(assert | thisModule.MesureUseAssertTrueInsteadOfAssertEquals(assert)); + --->select(assert | thisModule.isWrongUseAssertTrueInsteadOfAssertEquals(assert) and assert.method.name = 'assertEquals') + --->collect(assert | thisModule.MesureUseAssertTrueInsteadOfAssertEquals(assert)); -helper def: isWrongUseAssertTrueInsteadOfAssertEquals(m:java!MethodInvocation) : Boolean = +--helper def: isWrongUseAssertTrueInsteadOfAssertEquals(m:java!MethodInvocation) : Boolean = --Shorten the path m.arguments.last() to lastArgument and check if it's a boolean - let lastArgument : java!Expression = m.arguments.last() in lastArgument.isBoolean(); + --let lastArgument : java!Expression = m.arguments.last() in lastArgument.isBoolean(); --Checks if it's a BooleanLiteral -helper context java!BooleanLiteral def: isBoolean() : Boolean = true; +--helper context java!BooleanLiteral def: isBoolean() : Boolean = true; --Checks if the type of a Expression is Boolean -helper context java!Expression def: isBoolean() : Boolean = - self.variable.variablesContainer.isBoolean(); +--helper context java!Expression def: isBoolean() : Boolean = + -- self.variable.variablesContainer.isBoolean(); --Checks if the type of a VariableDeclarationStatement is Boolean -helper context java!VariableDeclarationStatement def: isBoolean() : Boolean = - self.type.type.name= 'boolean'; +--helper context java!VariableDeclarationStatement def: isBoolean() : Boolean = +-- self.type.type.name= 'boolean'; --Use in case of Boolean.TRUE or Boolean.FALSE -helper context java!FieldDeclaration def: isBoolean() : Boolean = - self.abstractTypeDeclaration.name = 'Boolean'; +--helper context java!FieldDeclaration def: isBoolean() : Boolean = + -- self.abstractTypeDeclaration.name = 'Boolean'; --------------------------------------------- AvoidStringBufferField --------------------------------------------- diff --git a/src/main/atl/codestyle.atl b/src/main/atl/codestyle.atl index cc9c2eec17e1da68ad2029751d93ce342cc1be6d..b05e7fd69ed2ec5aef48c9ef9df2190ea8794087 100644 --- a/src/main/atl/codestyle.atl +++ b/src/main/atl/codestyle.atl @@ -64,3 +64,17 @@ helper def: longVariable() : Set(smm!Measure) = -> select( variable | variable.name.size() > 17) -> collect (variable | thisModule.MeasureLongVariable(variable)); +--------------------------------------------- AbsctractNaming --------------------------------------------- + +helper def : AbsctractNaming(): Set(smm!Measure)= + --Selectione les classes abstract + java!ClassDeclaration.allInstances() + ->select(i|not i.modifier.oclIsUndefined()) + --L'utilisation de reject de modifier.inheritance=#none et #final a été utilisé au lieu d'un select modifier.inheritance=#abstract car abstract est un mot clés atl + -- final,none et abstract sont des enumeration mais abstract est aussi un mot clé de atl ce qui pose probleme au moment de sont utilisation + ->reject(i|i.modifier.inheritance=#none) + ->reject(i|i.modifier.inheritance=#final) + --pour chaque classe abstraite On selectionne que celle qui ne commencent pas par Abstract + ->select(i | not i.name.startsWith('Abstract')) + ->collect(i|thisModule.ruleAbsctractNaming(i)) + ;