Commit e982607b authored by Gerson SUNYE's avatar Gerson SUNYE
Browse files

Merge branch 'fix/770-CommentRequired' into 'master'

Improvement on fixed issue #770 CommentRequired -> Removed all if/else conditionals

Closes #770

See merge request naomod/mde/projet-2019!69
parents 28e21e40 26c0c7a0
: Pre-requisites :
: * the FART tool : https://sourceforge.net/projects/fart-it/
: * A correct analysis.launch file to serve as base
: This scripts generates for each input xmi, a corresponding ATL launch file
@echo off
setlocal enabledelayedexpansion
: Checks parameter for current IN model name in analysis.launch
if "%~1"=="" (
echo "Enter the name of current IN model in file analysis.launch (for e.g : ./gen-launch-config.bat comment-required)"
exit 0
) else (
SET currentinput=%1
echo "Current input : %%currentinput"
)
: For each input file, generate the corresponding .launch file with this file's name as IN model
for %%f in (input\*.xmi) do (
: set /p content=<%%f
echo "fullname: %%f"
echo "name: %%~nf"
: echo "contents: !content!"
copy analysis.launch analysis-%%~nf.launch
echo %currentinput%
fart analysis-%%~nf.launch %currentinput% "%%~nf"
)
\ No newline at end of file
# Pre-requisites : A correct analysis.launch file to serve as base
# This scripts generates for each input xmi, a corresponding ATL launch file
# Check parameter for current IN model name in analysis.launch
currentinput=""
if [ -z "$1" ]
then
echo "Enter the name of current IN model in file analysis.launch (for e.g : ./gen-launch-config.sh comment-required)"
exit
else
currentinput=$1
echo "Current input : $currentinput"
fi
# For each input file, generate the corresponding .launch file with this file's name as IN model
for file in input/*.xmi; do
filename=$(basename -- "$file") # get basename
filename="${filename%.*}" # remove extension
echo "$filename"
cp analysis.launch analysis-$filename.launch
sed -i "s/$currentinput/$filename/g" analysis-$filename.launch
echo "Replaced : $currentinput by $filename in file analysis-$filename.launch"
done
\ No newline at end of file
......@@ -580,7 +580,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 (
......@@ -592,23 +592,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
--- Returns 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,20 +29,18 @@ 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
thisModule.commentRequiredPropertyDefinitions().get(elem.oclType().name)
let propertyNames:String = '' in thisModule.commentRequiredPropertyDefinitions().get(elem.oclType().name)
-- Concatenate to propertyNames : the name of each property rules that matches requirements for elem
->select(propertyTuple | thisModule.matchesCommentRequiredProperty('Required',elem, propertyTuple))
->iterate (tuple; propertyNames: String = '' |
propertyNames.concat(tuple.property+';')
)
->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,
......@@ -56,40 +54,27 @@ helper def: matchesCommentRequiredProperty(
-- Check correspondance with modifier vibility
.and(
if (tuple.modifier.isEmpty()) then true
else
if (tuple.modifier = elem.modifier.visibility.name) then true else false endif
endif)
tuple.modifier.isEmpty() or tuple.modifier = elem.modifier.visibility.name)
-- Check correspondance with annotation
.and(
if (tuple.annotation.isEmpty()) then true
else
if (thisModule.getAnnotationTypeDeclarationsFromBodyDeclaration(elem)
->exists(annotation | annotation.name = tuple.annotation)
) then true else false endif
endif)
tuple.annotation.isEmpty() or
thisModule.getAnnotationTypeDeclarationsFromBodyDeclaration(elem)
->exists(annotation | annotation.name = tuple.annotation))
-- Check correspondance with prefixes
.and(
if (tuple.prefixes.isEmpty()) then true
else
if (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)
) then true else false endif
endif)
tuple.prefixes.isEmpty() or
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(
......
Supports Markdown
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