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

Ignored properties are now properly ignored. Left todo : get Annotation check working

parent 975760b3
......@@ -379,7 +379,7 @@ rule MeasureCommentRequired(element: java!NamedElement, violatedProperties: Set(
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.getNamedElementName(element)
error <- 'Violated the properties {' + violatedProperties + '} in Class: ' + element.originalCompilationUnit.name + ' -> ' + element.oclType().name + ': ' + element.modifier.visibility + ' ' + thisModule.getNamedElementName(element)
)
do {
commentRequired;
......
library documentation;
-- Returs a set of measures for each element that violates the rule : comment required
-- Returs a set of measures for each element that violates the rule : comment value
helper def: commentRequired() : Set(smm!Measure) =
java!NamedElement.allInstances()
-> select (elem | not elem.oclIsTypeOf(java!Package) and elem.proxy = false)
-> select (elem | thisModule.commentRequiredPropertyCustomization().getKeys().contains(elem.oclType().name))
-> select (elem | thisModule.violatesCommentRequired(elem))
-> collect (elem | thisModule.MeasureCommentRequired(elem, thisModule.violatedCommentRequiredProperty(elem)))
-> collect (elem | thisModule.MeasureCommentRequired(elem, thisModule.violatedCommentRequiredProperties(elem)))
;
-- Returns true if the given elem violates any of the "comment required" rule properties
-- Returns true if the given elem violates any of the "comment value" rule properties
helper def: violatesCommentRequired(elem: java!NamedElement): Boolean =
thisModule.commentRequiredPropertyCustomization().get(elem.oclType().name)
->exists(propertyTuple | thisModule.violatesCommentRequiredPropertyRequirements(elem, propertyTuple))
-- An element violates a property if there's at least one that's violated and if
-- it doesn't match any 'Ignored' properties
(thisModule.commentRequiredPropertyCustomization().get(elem.oclType().name)
->exists(propertyTuple | thisModule.matchesCommentRequiredProperty('Required',elem, propertyTuple)))
.and(
-- TO CORRECT
not thisModule.commentRequiredPropertyCustomization().get(elem.oclType().name)
->exists(propertyTuple | thisModule.matchesCommentRequiredProperty('Ignored',elem, propertyTuple))
)
;
helper def: violatedCommentRequiredProperty(elem: java!NamedElement): String =
-- Returns the list of violated "comment value" properties as a string
helper def: violatedCommentRequiredProperties(elem: java!NamedElement): String =
thisModule.commentRequiredPropertyCustomization().get(elem.oclType().name)
->select(propertyTuple | thisModule.violatesCommentRequiredPropertyRequirements(elem, propertyTuple))
->select(propertyTuple | thisModule.matchesCommentRequiredProperty('Required',elem, propertyTuple))
->iterate (tuple; propertyNames: String = '' |
propertyNames.concat(tuple.property+';')
)
;
-- Returns true if the given property tuple applies to the given elem, false otherwise
helper def: violatesCommentRequiredPropertyRequirements(
helper def: matchesCommentRequiredProperty(
value:String,
elem: java!NamedElement,
tuple: TupleType(property:String, required:Boolean, modifier: String, annotation: String)): Boolean =
-- Check whether the given property tuple applies to the given elem:
-- Check if required
tuple.required
.and(not thisModule.hasComments(elem))
tuple: TupleType(property:String, value:Boolean, modifier: String, annotation: String)): Boolean =
-- Check whether this rule is required
(tuple.value=value)
-- Check the given element has comments
.and(not thisModule.hasComments(elem))
--(not thisModule.hasComments(elem))
-- Check correspondance with modifier
.and(
if (tuple.modifier.isEmpty()) then true
......@@ -44,56 +56,68 @@ helper def: violatesCommentRequiredPropertyRequirements(
.and(
if (tuple.annotation.isEmpty()) then true
else
if (elem.annotations.contains(tuple.annotation)) then true else false endif
-- TODO !! Not working
if (elem.annotations
->exists(annotation | annotation.equals(tuple.annotation)=0)
) then true else false endif
endif)
-- Check correspondance with prefixes
.and(
if (tuple.prefixes.isEmpty()) then true
else
if (tuple.prefixes->exists(p | elem.name.startsWith(p))) then true else false endif
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)
;
-- Returns true if the elem has comments, false otherwise
helper def: hasComments(elem: java!NamedElement): Boolean =
not elem.comments.isEmpty()
;
-- Contains the default configuration for the "Comment required" rule
-- Contains the default configuration for the "Comment value" rule
-- Can add, delete or modify properties here to customize them just like in PMD
helper def: commentRequiredPropertyCustomization() :
Map(String, Set(TupleType(property:String, required:Boolean, modifier: String, annotation: String, prefixes: Set(String)))) = Map {
Map(String, Set(TupleType(property:String, value:String, modifier: String, annotation: String, prefixes: Set(String)))) = Map {
-- Configure comment requirement properties for method declarations
('MethodDeclaration',
Set {
Tuple{property='methodWithOverrideCommentRequirement', required=true, modifier='', annotation='override', prefixes=Set{}},
Tuple{property='publicMethodCommentRequirement', required=true, modifier='public', annotation='', prefixes=Set{}},
Tuple{property='protectedMethodCommentRequirement', required=true, modifier='none', annotation='', prefixes=Set{}}, -- protected in defined as 'none' in the java model
Tuple{property='accessorCommentRequirement', required=true, modifier='', annotation='', prefixes=Set{'get,set'}}
Tuple{property='methodWithOverrideCommentRequirement', value='Ignored', modifier='', annotation='Override', prefixes=Set{}},
Tuple{property='publicMethodCommentRequirement', value='Required', modifier='public', annotation='', prefixes=Set{}},
Tuple{property='protectedMethodCommentRequirement', value='Required', modifier='protected', annotation='', prefixes=Set{}},
Tuple{property='protectedMethodCommentRequirement', value='Required', modifier='none', annotation='', prefixes=Set{}}, -- protected is also defined as 'none' in the java model
Tuple{property='accessorCommentRequirement', value='Ignored', modifier='', annotation='', prefixes=Set{'get','set'}}
}
),
-- Configure comment requirement properties for field declarations
('FieldDeclaration',
Set{
--Tuple{property = 'serialVersionUIDCommentRequired', required=false, modifier='', annotation='', prefixes=Set{}},
--Tuple{property = 'serialPersistentFieldsCommentRequired', required=false, modifier='', annotation='', prefixes=Set{}},
Tuple{property='fieldCommentRequirement', required=true, modifier='', annotation='', prefixes=Set{}}
Tuple{property='fieldCommentRequirement', value='Required', modifier='', annotation='', prefixes=Set{}},
Tuple{property = 'serialVersionUIDCommentRequired', value='Ignored', modifier='', annotation='', prefixes=Set{'serialVersionUID'}},
Tuple{property = 'serialPersistentFieldsCommentRequired', value='Ignored', modifier='', annotation='', prefixes=Set{'serialPersistentFields'}}
}
),
-- Configure comment requirement properties for class declarations
('ClassDeclaration',
Set{
Tuple{property='headerCommentRequirement', required=true, modifier='', annotation='', prefixes=Set{}}
Tuple{property='headerCommentRequirement', value=true, modifier='', annotation='', prefixes=Set{}}
}
),
-- Configure coment requirement properties for enum
('EnumDeclaration',
Set{
Tuple{property='enumCommentRequirement', required=true, modifier='', annotation='', prefixes=Set{}}
Tuple{property='enumCommentRequirement', value=true, modifier='', annotation='', prefixes=Set{}}
}
)
};
......
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