Commit 9a988ef3 authored by Ronan GUEGUEN's avatar Ronan GUEGUEN Committed by Gerson SUNYE
Browse files

Fix #814

parent 0dfd16c7
<?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="Count">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="main">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="START" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@initializers.0/@fragments.0/@initializer //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@expression/@rightOperand/@leftOperand">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2000000000"/>
</fragments>
<modifier inheritance="final"/>
</statements>
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="count" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@body/@expression/@operand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@expression/@arguments.0">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="0"/>
</fragments>
<modifier/>
</statements>
<statements xsi:type="java:ForStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="&lt;">
<rightOperand xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="+">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="50"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@fragments.0"/>
</rightOperand>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@initializers.0/@fragments.0"/>
</expression>
<updaters xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@initializers.0/@fragments.0"/>
</updaters>
<initializers xsi:type="java:VariableDeclarationExpression" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.2"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="f" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@updaters.0/@operand">
<initializer xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@fragments.0"/>
</fragments>
<modifier/>
</initializers>
<body xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@fragments.0"/>
</expression>
</body>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="//Prints 0 because (float) START == (float) (START + 50)." prefixOfParent="true"/>
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="//The termination test misbehaves due to floating point granularity."/>
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@fragments.0"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.1/@ownedPackages.0/@ownedElements.3/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
</expression>
</expression>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="args">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
<ownedElements xsi:type="java:ClassDeclaration" name="System" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@expression/@expression/@qualifier">
<bodyDeclarations xsi:type="java:FieldDeclaration" proxy="true">
<fragments name="out" proxy="true" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@expression/@expression"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="AutoCloseable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.4/@superInterfaces.0"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Appendable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superInterfaces.0"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
<ownedElements xsi:type="java:ClassDeclaration" name="PrintStream" proxy="true">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="println" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@expression">
<parameters name="arg0" proxy="true">
<type type="//@orphanTypes.0"/>
</parameters>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="FilterOutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superClass">
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="OutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.2/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.5"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Closeable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superInterfaces.0 //@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superInterfaces.1">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Flushable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superInterfaces.1"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@type //@ownedElements.1/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0/@parameters.0/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.2/@initializers.0/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Count.java" originalFilePath="/comptes/E134932Q/MDE/Jerk/src/Count.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.3/@comments.1" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
...@@ -100,6 +100,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = ...@@ -100,6 +100,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.emptySynchronizedBlock(), thisModule.emptySynchronizedBlock(),
thisModule.emptyTryBlock(), thisModule.emptyTryBlock(),
thisModule.importFromSamePackage(), thisModule.importFromSamePackage(),
thisModule.methodWithSameNameAsEnclosingClass(),
thisModule.dontUseFloatTypeForLoopIndices(),
thisModule.missingBreakInSwitch(), thisModule.missingBreakInSwitch(),
thisModule.suspiciousEqualsMethodName(), thisModule.suspiciousEqualsMethodName(),
thisModule.UnconditionalIfStatement(), thisModule.UnconditionalIfStatement(),
...@@ -678,7 +680,7 @@ rule MeasureCommentRequired(element: java!BodyDeclaration, violatedProperties: S ...@@ -678,7 +680,7 @@ rule MeasureCommentRequired(element: java!BodyDeclaration, violatedProperties: S
commentRequired; commentRequired;
} }
} }
-- Creates a measure instance when a bad word is found in a comment
rule MeasureCommentContent(element: Sequence(String)){ rule MeasureCommentContent(element: Sequence(String)){
to to
om: smm!ObservedMeasure ( om: smm!ObservedMeasure (
...@@ -698,6 +700,26 @@ rule MeasureCommentContent(element: Sequence(String)){ ...@@ -698,6 +700,26 @@ rule MeasureCommentContent(element: Sequence(String)){
} }
-- Creates a measure instance when a for loop uses a float as loop indice
rule MeasureDontUseFloatTypeForLoopIndices(){
to
om: smm!ObservedMeasure (
measure <- dontUseFloatTypeForLoopIndices,
measurements <- measurement
),
dontUseFloatTypeForLoopIndices: smm!DimensionalMeasure (
name <- 'DontUseFloatTypeForLoopIndices()',
shortDescription <- 'Don’t use floating point for loop indices.'
),
measurement: smm!DirectMeasurement (
error <- 'Use integer instead of floats as loop indice'
)
do {
dontUseFloatTypeForLoopIndices;
}
}
--- Returns the name of a BodyDeclaration --- Returns the name of a BodyDeclaration
helper context java!BodyDeclaration def: getBodyDeclarationName() : String = helper context java!BodyDeclaration def: getBodyDeclarationName() : String =
self.name; self.name;
......
...@@ -180,6 +180,20 @@ helper def: finalizeShouldBeProtected() : Set(smm!Measure) = ...@@ -180,6 +180,20 @@ helper def: finalizeShouldBeProtected() : Set(smm!Measure) =
->select(m | m.name = 'finalize' and m.modifier.visibility.toString() <> 'protected') ->select(m | m.name = 'finalize' and m.modifier.visibility.toString() <> 'protected')
->collect(m | thisModule.MesureFinalizeShouldBeProtected(m)); ->collect(m | thisModule.MesureFinalizeShouldBeProtected(m));
--------------------------------------------------------------------------------------------------------------
--------------------------------------------DontUseFloatTypeForLoopIndices------------------------------------
helper def: dontUseFloatTypeForLoopIndices() : Set(smm!Measure) =
java!ForStatement.allInstances()
-> select(loop | loop.initializers.type.type = '//@orphanType.2')
-> collect(loop | thisModule.MeasureDontUseFloatTypeForLoopIndices())
;
--------------------------------------------- EmptySwitchStatement --------------------------------------------- --------------------------------------------- EmptySwitchStatement ---------------------------------------------
...@@ -328,4 +342,4 @@ helper def: importFromSamePackage() : Set(smm!Measure) = ...@@ -328,4 +342,4 @@ helper def: importFromSamePackage() : Set(smm!Measure) =
helper def: methodWithSameNameAsEnclosingClass() : Set(smm!Measure) = helper def: methodWithSameNameAsEnclosingClass() : Set(smm!Measure) =
java!MethodDeclaration.allInstances() java!MethodDeclaration.allInstances()
->select(method | method.name = method.abstractTypeDeclaration.name) ->select(method | method.name = method.abstractTypeDeclaration.name)
->collect(method | thisModule.MeasureMethodWithSameNameAsEnclosingClass(method)); ->collect(method | thisModule.MeasureMethodWithSameNameAsEnclosingClass(method));
\ No newline at end of file
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