From 20433679d1908b2aa6e8432ab54b0364fd3a42ca Mon Sep 17 00:00:00 2001 From: chanez Date: Fri, 13 Dec 2019 16:10:20 +0100 Subject: [PATCH 1/2] Fix #661 AbstractNaming --- input/abstractNaming_java.xmi | 76 ++++++++++++++++++++++++++++++++++ src/main/atl/analysis.atl | 23 +++++++++- src/main/atl/bestPractices.atl | 26 ++++++------ src/main/atl/codestyle.atl | 14 +++++++ 4 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 input/abstractNaming_java.xmi diff --git a/input/abstractNaming_java.xmi b/input/abstractNaming_java.xmi new file mode 100644 index 0000000..01f1345 --- /dev/null +++ b/input/abstractNaming_java.xmi @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/atl/analysis.atl b/src/main/atl/analysis.atl index 3027b10..ec9e4d9 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 42956c3..16ca784 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 cc9c2ee..b05e7fd 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)) + ; -- GitLab From 0e268a466a02a88844f75ef3b4cd74ddcd2c1182 Mon Sep 17 00:00:00 2001 From: Chanez AMRI Date: Mon, 16 Dec 2019 15:40:39 +0100 Subject: [PATCH 2/2] Update abstractNaming_java.xmi --- input/{abstractNaming_java.xmi => abstract-naming.xmi} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename input/{abstractNaming_java.xmi => abstract-naming.xmi} (100%) diff --git a/input/abstractNaming_java.xmi b/input/abstract-naming.xmi similarity index 100% rename from input/abstractNaming_java.xmi rename to input/abstract-naming.xmi -- GitLab