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

Merge branch 'commentContent' into 'master'

issue #769 CommentContent

See merge request naomod/mde/projet-2019!71
parents d567ba76 0b765466
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="Jerk">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Jerk">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this variable is named counter" prefixOfParent="true"/>
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="counter" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression/@leftHandSide"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this one is named idiot" prefixOfParent="true"/>
<modifier visibility="private"/>
<type type="//@orphanTypes.4"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="idiot" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@leftHandSide"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Jerk">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// whoever named these variables is a jerk" prefixOfParent="true"/>
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0"/>
<rightHandSide xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
</expression>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// you shouldn't name variable like that you cunt, tapir" prefixOfParent="true"/>
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@fragments.0"/>
<rightHandSide xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
</expression>
</statements>
</body>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Jerk.java" originalFilePath="/comptes/E134932Q/MDE/Jerk/src/Jerk.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
......@@ -77,7 +77,9 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Documentation rules
--
thisModule.commentContent(),
thisModule.commentRequired(),
-- Error prone rules
--
......@@ -607,6 +609,25 @@ rule MeasureCommentRequired(element: java!BodyDeclaration, violatedProperties: S
}
}
rule MeasureCommentContent(element: Sequence(String)){
to
om: smm!ObservedMeasure (
measure <- commentContent,
measurements <- measurement
),
commentContent: smm!DimensionalMeasure (
name <- 'CommentContent',
shortDescription <- 'A rule for the politically correct… we don’t want to offend anyone.'
),
measurement: smm!DirectMeasurement (
error <- 'The words ' + element +' were found in a comment '
)
do {
commentContent;
}
}
--- Returns the name of a BodyDeclaration
helper context java!BodyDeclaration def: getBodyDeclarationName() : String =
self.name;
......
......@@ -129,4 +129,36 @@ helper def: commentRequiredPropertyDefinitions() :
};
-------------------------------------------------------------------------------------------------------------------
-----------------------------------CommentContent------------------------------
helper def: badWordDefinition(): Set(String) =
-- Returns a set of forbidden words
Set{'jerk','idiot','slut','whore','anus','assfucker','tapir','motherfucker','fuck','lardass','cumslut','cunt','shit','Rob Schneider'}
;
helper def: matchedBadWord(elem : Sequence(String)): Sequence(String) =
-- Returns true if the string is one of the bad words
elem -> select(word | thisModule.badWordDefinition().includes(word.toLowerCase())) -- Returns every bad words found
;
helper def: commentContent(): Set(smm!Measure) =
java!ASTNode.allInstances()
-> reject (node | node.comments.isEmpty()) -- Rejects all instances that do not contain comments
-> collect (node | thisModule.violatedCommentContent(node))
-> reject(seq | seq.isEmpty())
-> collect (elem | thisModule.MeasureCommentContent(elem)) -- Select all instances that contains a bad word in one of its comments
;
helper def: violatedCommentContent(node : java!ASTNode): Sequence(String) =
node.comments
-> reject (comment | comment.content.isEmpty())
-> collect (comment | comment.content.split('[ ,.:!?;/]'))
-> collect (words | thisModule.matchedBadWord(words))
-> reject (words | words.isEmpty()) -> flatten()
;
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