Commit c35cc289 authored by Roxane Kang Maréchal's avatar Roxane Kang Maréchal
Browse files

Removed all if else conditionals

parent 71d0c4ae
# Pre-requisites : A correct analysis.launch file to serve as base
# This scripts generates for each input xmi, a corresponding launch file which makes checking results faster and easier
# Check parameter for current IN model name in analysis.launch
currentinput=""
if [ -n "$0" ]
then
echo "Enter the name of current IN model in file analysis.launch (for e.g : ./gen-launch-config.sh comment-required)"
sleep 2
exit
else
currentinput=$0
echo "Current input : $currentinput"
fi
......@@ -577,7 +577,7 @@ rule MeasureUseNotifyAllInsteadOfNotify(method: java!MethodInvocation) {
}
}
-- Creates a measure instance for each element that violates the rule : CommentRequired
--- Creates a measure instance for each element that violates the rule : CommentRequired
rule MeasureCommentRequired(element: java!BodyDeclaration, violatedProperties: Set(String)) {
to
om: smm!ObservedMeasure (
......@@ -589,23 +589,22 @@ rule MeasureCommentRequired(element: java!BodyDeclaration, violatedProperties: S
shortDescription <- 'Denotes whether comments are required (or unwanted) for specific language elements.'
),
measurement: smm!DirectMeasurement (
error <- 'Violated the properties ' + violatedProperties + ' in Class: ' + element.originalCompilationUnit.name + ' -> ' + element.oclType().name + ': ' + element.modifier.visibility + ' ' + thisModule.getBodyDeclarationName(element)
error <- 'Violated the properties ' + violatedProperties + ' in Class: ' + element.originalCompilationUnit.name + ' -> ' + element.oclType().name + ': ' + element.modifier.visibility + ' ' + element.getBodyDeclarationName()
)
do {
commentRequired;
}
}
-- Returns the declaration name of a BodyDeclaration
-- In FielDeclaration, the attribute 'name' is NULL, this information is contained in "fragments" instead
helper def: getBodyDeclarationName(elem: java!BodyDeclaration): String =
if (elem.oclIsTypeOf(java!FieldDeclaration))
then elem.fragments.first().name
else elem.name
endif
;
--- Returns the name of a BodyDeclaration
helper context java!BodyDeclaration def: getBodyDeclarationName() : String =
self.name;
--- In FielDeclaration, the attribute 'name' is NULL, this information is contained in "fragments" instead
helper context java!FieldDeclaration def: getBodyDeclarationName() : String =
self.fragments.first().name;
-- Returns the AnnotationTypeDeclaration corresponding to the given BodyDeclaration
--- Returns the AnnotationTypeDeclaration corresponding to the given BodyDeclaration
-- This is necessary because BodyDeclaration.annotations returns Sequence(!IN<unamed>)
helper def: getAnnotationTypeDeclarationsFromBodyDeclaration(elem: java!BodyDeclaration): Set(java!AnnotationTypeDeclaration) =
java!AnnotationTypeDeclaration.allInstances()
......
......@@ -2,7 +2,7 @@ library documentation;
--------------------------------------------- CommentRequired ---------------------------------------------
-- Returs a set of measures for each element that violates the rule : CommentRequired
--- Returs a set of measures for each element that violates the rule : CommentRequired
helper def: commentRequired() : Set(smm!Measure) =
java!BodyDeclaration.allInstances()
......@@ -15,7 +15,7 @@ helper def: commentRequired() : Set(smm!Measure) =
-> collect (elem | thisModule.MeasureCommentRequired(elem, thisModule.violatedCommentRequiredProperties(elem)))
;
-- Returns true if the given elem violates any of the CommentRequired rule properties
--- Returns true if the given elem violates any of the CommentRequired rule properties
helper def: violatesCommentRequired(elem: java!BodyDeclaration): Boolean =
-- An element violates a property if there's at least one that's violated,
......@@ -29,7 +29,7 @@ helper def: violatesCommentRequired(elem: java!BodyDeclaration): Boolean =
)
;
-- Returns the list of violated CommentRequired properties as a string
--- Returns the list of violated CommentRequired properties as a string
helper def: violatedCommentRequiredProperties(elem: java!BodyDeclaration): String =
-- Get the set of property tuples associated to elem by using elem data type as key to the Map
......@@ -40,7 +40,7 @@ helper def: violatedCommentRequiredProperties(elem: java!BodyDeclaration): Strin
->collect(tuple | propertyNames.concat(tuple.property))
;
-- Returns true if the given property tuple applies to the given elem, false otherwise
--- Returns true if the given property tuple applies to the given elem, false otherwise
helper def: matchesCommentRequiredProperty(
value:String, -- is either 'Required' or 'Ignore'
elem: java!BodyDeclaration,
......@@ -65,23 +65,16 @@ helper def: matchesCommentRequiredProperty(
-- Check correspondance with prefixes
.and(
tuple.prefixes.isEmpty() or
tuple.prefixes->exists(p |
-- If elem is of type FieldDeclaration, name field is null so we have to use fragments
if (elem.oclIsTypeOf(java!FieldDeclaration))
then elem.fragments.first().name.startsWith(p)
else elem.name.startsWith(p)
endif
)
tuple.prefixes->exists(p | elem.getBodyDeclarationName().startsWith(p))
)
;
-- Returns true if the elem has comments, false otherwise
--- Returns true if the elem has comments, false otherwise
helper def: hasComments(elem: java!BodyDeclaration): Boolean =
not elem.comments.isEmpty()
;
-- Contains the default configuration for the CommentRequired rule
--- Contains the default configuration for the CommentRequired rule
-- Can add, delete or modify properties here to customize them just like in PMD
helper def: commentRequiredPropertyDefinitions() :
Map(
......
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