Commit 81ab149b authored by Julien AIMONIER-DAVAT's avatar Julien AIMONIER-DAVAT Committed by Gerson SUNYE
Browse files

Fix rules #626 #665 #680 #809

parent 0ab6de45
<?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="AvoidPrefixingMethodParameters">
<ownedElements name="main">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="AvoidPrefixingMethodParameters">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test1">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="in">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="out">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test2">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="inParam">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="outParam">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test3">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param1">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param2">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.1/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.1/@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"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="AvoidPrefixingMethodParameters.java" originalFilePath="/home/asao/eclipse-photon-workspace/AvoidPrefixingMethodParameters/src/main/AvoidPrefixingMethodParameters.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
\ No newline at end of file
<?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="DoNotCallSystemExit">
<ownedElements name="main">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="DoNotCallSystemExit">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test1">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<arguments xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
<expression xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test2">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.1">
<arguments xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.0">
<expression xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test3">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.1">
<arguments xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.0">
<expression xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</expression>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test4">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.1">
<arguments xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.1">
<expression xsi:type="java:TypeAccess" type="//@ownedElements.0/@ownedElements.1"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test5">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.2">
<arguments xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
<expression xsi:type="java:ClassInstanceCreation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.3">
<type type="//@ownedElements.0/@ownedElements.1"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="Class1" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@body/@statements.0/@expression/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.4/@body/@statements.0/@expression/@expression/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@expression/@leftOperand/@qualifier //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@thenStatement/@statements.0/@expression/@leftHandSide/@qualifier //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.1/@expression/@qualifier">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier visibility="private" static="true"/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="instance" usageInVariableAccess="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@expression/@leftOperand //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@thenStatement/@statements.0/@expression/@leftHandSide //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.1/@expression"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="getClass2Instance" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@body/@statements.0/@expression/@expression">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.1">
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.1">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.1" operator="==">
<rightOperand xsi:type="java:NullLiteral" originalCompilationUnit="//@compilationUnits.1"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.0/@ownedElements.1"/>
</leftOperand>
</expression>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.1">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.1">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.1">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.0/@ownedElements.1"/>
</leftHandSide>
<rightHandSide xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.1" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.0">
<expression xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</rightHandSide>
</expression>
</statements>
</thenStatement>
</statements>
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.1">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.0/@ownedElements.1"/>
</expression>
</statements>
</body>
<returnType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="exit" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.4/@body/@statements.0/@expression">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<parameters originalCompilationUnit="//@compilationUnits.1" name="code">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" name="Class1" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.4/@body/@statements.0/@expression/@expression"/>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="System" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression/@expression">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="exit" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression">
<parameters name="arg0" proxy="true">
<type type="//@orphanTypes.0"/>
</parameters>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Runtime" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression/@expression/@expression/@expression //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@thenStatement/@statements.0/@expression/@rightHandSide/@expression">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="getRuntime" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@body/@statements.0/@thenStatement/@statements.0/@expression/@rightHandSide"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" name="exit" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@body/@statements.0/@expression">
<parameters name="arg0" proxy="true">
<type type="//@orphanTypes.0"/>
</parameters>
</bodyDeclarations>
</ownedElements>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.2/@parameters.0/@type //@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type //@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.1/@parameters.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"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.3/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.4/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.2/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="DoNotCallSystemExit.java" originalFilePath="/home/asao/eclipse-photon-workspace/DoNotCallSystemExit/src/main/DoNotCallSystemExit.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="Class1.java" originalFilePath="/home/asao/eclipse-photon-workspace/DoNotCallSystemExit/src/main/Class1.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
<?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="FieldDeclarationsShouldBeAtStartOfClass">
<ownedElements name="main">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="ClassWithoutAllFieldsDeclaredAtTop">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="something">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="x"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ClassWithAllFieldsDeclaredAtTop">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="x"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="something">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.1"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@type //@ownedElements.0/@ownedElements.1/@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"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="ClassWithoutAllFieldsDeclaredAtTop.java" originalFilePath="/home/asao/eclipse-photon-workspace/FieldDeclarationsShouldBeAtStartOfClass/src/main/ClassWithoutAllFieldsDeclaredAtTop.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ClassWithAllFieldsDeclaredAtTop.java" originalFilePath="/home/asao/eclipse-photon-workspace/FieldDeclarationsShouldBeAtStartOfClass/src/main/ClassWithAllFieldsDeclaredAtTop.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
\ No newline at end of file
This diff is collapsed.
......@@ -43,7 +43,9 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Code Style rules
--
thisModule.avoidPrefixingMethodParameters(),
thisModule.extendsObject(),
thisModule.fieldDeclarationsShouldBeAtStartOfClass(),
thisModule.genericsNaming(),
thisModule.longVariable(),
thisModule.misLeadingVariableName(),
......@@ -96,6 +98,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.AvoidEnumAsIdentifier(),
thisModule.CloneMethodMustBePublic(),
thisModule.doNotCallGarbageCollectionExplicitly(),
thisModule.doNotCallSystemExit(),
thisModule.doNotExtendJavaLangError(),
thisModule.doNotExtendJavaLangThrowable(),
thisModule.dontImportSun(),
......@@ -112,6 +115,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.UseProperClassLoader(),
-- Best practices rules
thisModule.forLoopVariableCount(),
thisModule.switchDensity(),
thisModule.useAssertSameInsteadOfAssertTrue(),
thisModule.useAssertTrueInsteadOfAssertEquals()
......@@ -1744,3 +1748,89 @@ rule MesureAddEmptyString(w: java!CompilationUnit) {
noc;
}
}
------------------------------------------- DoNotCallSystemExit----------------------------------------------
-- A Measure instance if the class violates the rule DoNotCallSystemExit.
rule MeasureDoNotCallSystemExit(invocation : java!MethodInvocation) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'DoNotCallSystemExit',
shortDescription <- 'Applications should not call System.exit(), since only the web container or the application server should stop the JVM'
),
measurement: smm!DirectMeasurement (
error<- 'Do not call ' + invocation.method.getMethodClassName() + '.' + invocation.method.name + ' in the file ' + invocation.originalCompilationUnit.name
)
do {
noc;
}
}
------------------------------------------- ForLoopVariableCount----------------------------------------------
-- A Measure instance if the class violates the rule ForLoopVariableCount.
rule MeasureForLoopVariableCount(forStatement: java!ForStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ForLoopVariableCount',
shortDescription <- 'Having a lot of control variables in a "for" loop makes it harder to see what range of values the loop iterates over.'
),
measurement: smm!DirectMeasurement (
error<- 'A "for" loop use more than one local variable in the file ' + forStatement.originalCompilationUnit.name
)
do {
noc;
}
}
------------------------------------------- AvoidPrefixingMethodParameters----------------------------------------------
-- A Measure instance if the class violates the rule AvoidPrefixingMethodParameters.
rule MeasureAvoidPrefixingMethodParameters(method: java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidPrefixingMethodParameters',
shortDescription <- 'Prefixing parameters by ‘in’ or ‘out’ pollutes the name of the parameters and reduces code readability.'
),
measurement: smm!DirectMeasurement (
error<- 'Bad parameters : ' + method.getIncorrectParameters() + ', for the method ' + method.name + ' defined in the file ' + method.originalCompilationUnit.name
)
do {
noc;
}
}
------------------------------------------- FieldDeclarationsShouldBeAtStartOfClass----------------------------------------------
-- A Measure instance if the class violates the rule FieldDeclarationsShouldBeAtStartOfClass.
rule MeasureFieldDeclarationsShouldBeAtStartOfClass(class: java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'FieldDeclarationsShouldBeAtStartOfClass',
shortDescription <- 'Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.'
),
measurement: smm!DirectMeasurement (
error<- 'Some of the fields of the class ' + class.name + ' are not declared at the top'
)
do {
noc;
}
}
\ No newline at end of file
......@@ -96,3 +96,24 @@ helper def: isWrongUseAssertSameInsteadOfAssertTrue(m:java!MethodInvocation) : B
--Browse through all arguments of the method assertTrue and see if == is used
(m.arguments->select(t|t.oclIsTypeOf(java!InfixExpression))->select(t|t.operator.toString() = '==')->collect(t|t).notEmpty());
--------------------------------------------- ForLoopVariableCount ---------------------------------------------
-- Rule for metrics ForLoopVariableCount
helper def: forLoopVariableCount(): Set(smm!Measure) =
java!ForStatement.allInstances()->select(forStatement |
forStatement.nbLocalVariableDeclarations() > 1
)->collect(forStatement | thisModule.MeasureForLoopVariableCount(forStatement));
-- Returns the number of declared local variables in the for loop
helper context java!ForStatement def: nbLocalVariableDeclarations(): Integer =
self.initializers->iterate(expression; acc: Integer = 0 |
acc + expression.nbLocalVariableDeclarations()
);
-- A loop initializer can contains any Expression but we care about only VariableDeclarationExpression
helper context java!Expression def: nbLocalVariableDeclarations(): Integer =
0;
helper context java!VariableDeclarationExpression def: nbLocalVariableDeclarations(): Integer =
self.fragments.size(); -- The fragments collection contains all the variable declarations of an initializer*
-- Initializer* : for(int x = 0; ...), "int x = 0" is the initializer part of the for loop
......@@ -109,3 +109,61 @@ helper def: IfBraces() : Set(smm!Measure) =
-> select(i | i.thenStatement <> OclUndefined)
-> select(i | not i.thenStatement.oclIsTypeOf(java!Block))
-> collect(i | thisModule.MeasureIfStmtsMustUseBraces(i));
--------------------------------------------- AvoidPrefixingMethodParameters ---------------------------------------------
-- Rule for metrics AvoidPrefixingMethodParameters
helper def: avoidPrefixingMethodParameters(): Set(smm!Measure) =
java!MethodDeclaration.allInstances()->select(method |
method.getIncorrectParameters().size() > 0
)->collect(method |
thisModule.MeasureAvoidPrefixingMethodParameters(method)
);
-- Returns the method parameters which are prefixed by "in" or "out"
helper context java!MethodDeclaration def: getIncorrectParameters(): Set(String) =
self.parameters->select(parameter |
parameter.isPrefixedParameter()
)->collect(parameter |
parameter.name
);
helper def: match(regex: String, str: String): Boolean =
str.regexReplaceAll(regex, '') = ''; -- if the whole string has been replaced by the empty string, then it match the regular expression
-- Returns true if the parameter is prefixed by "in" or "out", false otherwise
helper context java!SingleVariableDeclaration def: isPrefixedParameter(): Boolean =
thisModule.match('^in[A-Z].*$', self.name) or
thisModule.match('^out[A-Z].*$', self.name) or
thisModule.match('^in$', self.name) or
thisModule.match('^out$', self.name);
--------------------------------------------- FieldDeclarationsShouldBeAtStartOfClass ---------------------------------------------
-- Rule for metrics FieldDeclarationsShouldBeAtStartOfClass
helper def: fieldDeclarationsShouldBeAtStartOfClass(): Set(smm!Measure) =
java!ClassDeclaration.allInstances()->select(class |
class.isNotAllFieldsDeclaredAtStartOfClass()
)->collect(class |
thisModule.MeasureFieldDeclarationsShouldBeAtStartOfClass(class)
);
-- Returns true if some of the fields are not declared at start of the class, false otherwise
helper context java!ClassDeclaration def: isNotAllFieldsDeclaredAtStartOfClass(): Boolean =
if self.bodyDeclarations.isEmpty() then
true
else
let fieldsDeclaration: Boolean = true in -- true until something other than a field declaration
self.bodyDeclarations->iterate(declaration; error: Boolean = false |
if not declaration.oclIsTypeOf(java!FieldDeclaration) and fieldsDeclaration then
fieldsDeclaration = false -- the first time something other than a field is declared
-- from this point, no more field declaration are accepted
else
if declaration.oclIsTypeOf(java!FieldDeclaration) and not fieldsDeclaration then
error = true -- a field is declared whereas we expected that no more field must be declared
else
error = error -- something needs to happen
endif
endif
)
endif;
\ No newline at end of file
......@@ -360,3 +360,29 @@ helper context java!ClassDeclaration def: nbTestMethod() : Integer =
-> select(bodyDeclaration | bodyDeclaration.name.size() > 4)
-> select(each | each.name.substring(1, 4) = 'test')
-> size();
--------------------------------------------- DoNotCallSystemExit ---------------------------------------------
-- Detects if the method "exit" of the System or Runtime class is called
helper def: doNotCallSystemExit(): Set(smm!Measure) =
java!MethodInvocation.allInstances()->select(invocation |
invocation.isSystemExit() or invocation.isRuntimeExit()
)->collect(invocation |
thisModule.MeasureDoNotCallSystemExit(invocation)
);
-- Returns the name of the class in which the invocated method is defined
helper context java!MethodDeclaration def: getMethodClassName(): String =
if self.abstractTypeDeclaration.oclIsUndefined() then
'Object'
else
self.abstractTypeDeclaration.name
endif;
-- Returns true if the called method is the method "exit" of the System class, false otherwise
helper context java!MethodInvocation def: isSystemExit(): Boolean =
self.method.name = 'exit' and self.method.getMethodClassName() = 'System';
-- Returns true if the called method is the method "exit" of the Runtime class, false otherwise
helper context java!MethodInvocation def: isRuntimeExit(): Boolean =
self.method.name = 'exit' and self.method.getMethodClassName() = 'Runtime';
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