Commit 10943908 authored by Khaled AMIRAT's avatar Khaled AMIRAT
Browse files

Update src/main/atl/codestyle.atl, src/main/atl/design.atl,...

Update src/main/atl/codestyle.atl, src/main/atl/design.atl, src/main/atl/errorProne.atl, src/main/atl/analysis.atl files
parent 9e61ea94
This diff is collapsed.
-- @nsURI smm=http://www.eclipse.org/MoDisco/SMM/1.0.Beta2/smm
-- @nsURI java=http://www.eclipse.org/MoDisco/Java/0.2.incubation/java
library codestyle;
------------------------------------------------------------------------------------------
......@@ -65,8 +62,7 @@ helper def: longVariable() : Set(smm!Measure) =
----- Fix Issues #699, #738, #780, #784, #799, #819, #862, #871
----- Fix Issues #699
--- helper noPackageDeclaration
--- get all the compilation units
......@@ -80,101 +76,6 @@ helper def: noPackageDeclaration() : Set(smm!Measure) =
->collect(err | thisModule.MesureAvoidNoPackageDeclaration(err));
--- helper UnconditionalIfStatement
--- get all the the used ifstatements and make a selection on all those that contains
--- an only expression in which its type is BooleanLiteral type like (true) or (false)
--- if there is collect them and make a call for MeasureUnconditionalIfStatement rule
--- with the detected ifstatments
helper def: UnconditionalIfStatement() : Set(smm!Measure) =
java!IfStatement.allInstances()
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
--- helper EmptyInitializer
--- get all the the used Initializer make a selection on all those that
--- has nothing inside theire body (empty initialize),
--- check if the contained statments size equals to 0
--- if there is collect them and make a call for MeasureEmptyInitializer rule
--- with the detected Initializer
helper def: EmptyInitializer() : Set(smm!Measure) =
java!Initializer.allInstances()
->select( w | w.body.statements.size() = 0)
->collect(w | thisModule.MeasureEmptyInitializer(w));
--- helper ExcessiveClassLength
--- get all the declaredMethods inside the class
--- check if theire body is defined or not
--- if it is check if this body containes a declared statements or not
--- if it is check if the number of this statement is bigger than 1000
--- in this case make a collection and make call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: ExcessiveClassLength() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.body <> OclUndefined )
->select (w | w.body.statements <> OclUndefined )
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveClassLength(w));
--- helper CloneMethodMustBePublic
--- get all the declaredMethods inside the class
--- check if is clone methode or not
--- check if its modifier is defined
--- check if its visibilty access is different from public
--- if it is the case make collection and make a call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.modifier <> OclUndefined )
->select (w | w.name = 'clone')
->select (w | w.modifier <> 'public')
->collect(w | thisModule.MeasureCloneMethodMustBePublic(w));
--- helper AvoidEnumAsIdentifier
-- modisco do not allow to convert a class with error
-- and a field with enum decleration is already detected by Java compiler
-- so we need at least to change the name of enum to Enum to work
--- get all the declared variable inside the class
--- check if their name are defined and
--- if it's different than reserved key word 'enum''
--- if it is not the case make collection and make a call for MeasureAvoidEnumAsIdentifier rule
--- with the detected VariableDeclaration
helper def: AvoidEnumAsIdentifier() : Set(smm!Measure) =
java!VariableDeclaration.allInstances()
->select (w | w.name <> OclUndefined )
->select (w | w.name = 'enum')
->collect(w | thisModule.MeasureAvoidEnumAsIdentifier(w));
--- helper AvoidCatchingNPE
--- get all the catchClause inside the class
--- check if the name of type for the typeAccess is equals to 'NullPointerException'
--- if it is the case make collection and make a call for MeasureAvoidCatchingNPE rule
--- with the detected VariableDeclaration
helper def: AvoidCatchingNPE() : Set(smm!Measure) =
java!CatchClause.allInstances()
->select (w | w.exception.type.type.name = 'NullPointerException')
->collect(w | thisModule.MeasureAvoidCatchingNPE(w));
--- helper UseProperClassLoader
--- get all the MethodInvocation inside the class
--- check if the invocked method name is equals to getClassLoader
--- if it is the case make collection and make a call for MeasureUseProperClassLoader rule
--- with the detected MethodInvocation
helper def: UseProperClassLoader() : Set(smm!Measure) =
java!MethodInvocation.allInstances()
->select (w | w.method.name='getClassLoader')
->collect(w | thisModule.MeasureUseProperClassLoader(w));
......@@ -112,4 +112,24 @@ helper def: signatureDeclareThrowsException() : Set (smm!Measure) =
helper def: avoidThrowingNullPointerException() : Set(smm!Measure) =
java!ClassInstanceCreation.allInstances()
->select(c | c.method.name = 'NullPointerException')
->collect(c | thisModule.MeasureAvoidThrowingNullPointerException(c));
\ No newline at end of file
->collect(c | thisModule.MeasureAvoidThrowingNullPointerException(c));
--- Issue #738
--- helper ExcessiveClassLength
--- get all the declaredMethods inside the class
--- check if theire body is defined or not
--- if it is check if this body containes a declared statements or not
--- if it is check if the number of this statement is bigger than 1000
--- in this case make a collection and make call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: ExcessiveClassLength() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.body <> OclUndefined )
->select (w | w.body.statements <> OclUndefined )
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveClassLength(w));
......@@ -180,3 +180,83 @@ helper def: finalizeShouldBeProtected() : Set(smm!Measure) =
->select(m | m.name = 'finalize' and m.modifier.visibility.toString() <> 'protected')
->collect(m | thisModule.MesureFinalizeShouldBeProtected(m));
--- Issues #780, #784, #799, #819, #862, #871
--- helper AvoidCatchingNPE
--- get all the catchClause inside the class
--- check if the name of type for the typeAccess is equals to 'NullPointerException'
--- if it is the case make collection and make a call for MeasureAvoidCatchingNPE rule
--- with the detected VariableDeclaration
helper def: AvoidCatchingNPE() : Set(smm!Measure) =
java!CatchClause.allInstances()
->select (w | w.exception.type.type.name = 'NullPointerException')
->collect(w | thisModule.MeasureAvoidCatchingNPE(w));
--- helper AvoidEnumAsIdentifier
-- modisco do not allow to convert a class with error
-- and a field with enum decleration is already detected by Java compiler
-- so we need at least to change the name of enum to Enum to work
--- get all the declared variable inside the class
--- check if their name are defined and
--- if it's different than reserved key word 'enum''
--- if it is not the case make collection and make a call for MeasureAvoidEnumAsIdentifier rule
--- with the detected VariableDeclaration
helper def: AvoidEnumAsIdentifier() : Set(smm!Measure) =
java!VariableDeclaration.allInstances()
->select (w | w.name <> OclUndefined )
->select (w | w.name = 'enum')
->collect(w | thisModule.MeasureAvoidEnumAsIdentifier(w));
--- helper CloneMethodMustBePublic
--- get all the declaredMethods inside the class
--- check if is clone methode or not
--- check if its modifier is defined
--- check if its visibilty access is different from public
--- if it is the case make collection and make a call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.modifier <> OclUndefined )
->select (w | w.name = 'clone')
->select (w | w.modifier <> 'public')
->collect(w | thisModule.MeasureCloneMethodMustBePublic(w));
--- helper EmptyInitializer
--- get all the the used Initializer make a selection on all those that
--- has nothing inside theire body (empty initialize),
--- check if the contained statments size equals to 0
--- if there is collect them and make a call for MeasureEmptyInitializer rule
--- with the detected Initializer
helper def: EmptyInitializer() : Set(smm!Measure) =
java!Initializer.allInstances()
->select( w | w.body.statements.size() = 0)
->collect(w | thisModule.MeasureEmptyInitializer(w));
--- helper UnconditionalIfStatement
--- get all the the used ifstatements and make a selection on all those that contains
--- an only expression in which its type is BooleanLiteral type like (true) or (false)
--- if there is collect them and make a call for MeasureUnconditionalIfStatement rule
--- with the detected ifstatments
helper def: UnconditionalIfStatement() : Set(smm!Measure) =
java!IfStatement.allInstances()
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
--- helper UseProperClassLoader
--- get all the MethodInvocation inside the class
--- check if the invocked method name is equals to getClassLoader
--- if it is the case make collection and make a call for MeasureUseProperClassLoader rule
--- with the detected MethodInvocation
helper def: UseProperClassLoader() : Set(smm!Measure) =
java!MethodInvocation.allInstances()
->select (w | w.method.name='getClassLoader')
->collect(w | thisModule.MeasureUseProperClassLoader(w));
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