Commit 00a72f53 authored by Gerson SUNYE's avatar Gerson SUNYE
Browse files

Merge branch 'master' into 'master'

Fixes #742, #847, #807

Closes #807, #847, and #742

See merge request naomod/mde/projet-2019!147
parents 10023cd0 83dfabf8
This diff is collapsed.
This diff is collapsed.
<?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="NullAssignmentTest">
<ownedElements name="fr">
<ownedPackages name="univnates">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="NullAssignmentTest">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="var" usageInVariableAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.1/@expression/@leftHandSide/@field"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.0" name="NullAssignmentTest">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:SuperConstructorInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0"/>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:FieldAccess" originalCompilationUnit="//@compilationUnits.0">
<field variable="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0"/>
<expression xsi:type="java:ThisExpression" originalCompilationUnit="//@compilationUnits.0"/>
</leftHandSide>
<rightHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0"/>
</expression>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="var" usageInVariableAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.1/@expression/@rightHandSide">
<modifier/>
<type type="//@orphanTypes.0"/>
</parameters>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="method">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this is OK"/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="x" usageInVariableAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@leftHandSide //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@expression/@leftHandSide">
<initializer xsi:type="java:NullLiteral" originalCompilationUnit="//@compilationUnits.0"/>
</fragments>
<modifier/>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
<rightHandSide xsi:type="java:ClassInstanceCreation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</rightHandSide>
</expression>
</statements>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// big, complex piece of code here" prefixOfParent="true"/>
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this is not required"/>
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// big, complex piece of code here"/>
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@fragments.0"/>
<rightHandSide xsi:type="java:NullLiteral" originalCompilationUnit="//@compilationUnits.0"/>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedPackages>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="Object" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@type //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@rightHandSide/@type">
<bodyDeclarations xsi:type="java:ConstructorDeclaration" name="Object" proxy="true" usages="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0 //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@rightHandSide"/>
</ownedElements>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@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/@ownedPackages.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="NullAssignmentTest.java" originalFilePath="C:\Users\leber\eclipse-workspace\IDM-Projet\NullAssignmentTest\src\fr\univnates\NullAssignmentTest.java" commentList="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@comments.0 //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@comments.0 //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@comments.1 //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.2/@comments.2" package="//@ownedElements.0/@ownedPackages.0" types="//@ownedElements.0/@ownedPackages.0/@ownedElements.0"/>
</java:Model>
......@@ -65,6 +65,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.ExcessiveClassLength(),
thisModule.excessiveImports(),
thisModule.excessiveParameterList(),
thisModule.excessivePublicCount(),
thisModule.finalFieldCouldBeStatic(),
thisModule.IfBraces(),
thisModule.longInstantiation(),
......@@ -103,6 +104,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.avoidCatchingThrowable(),
thisModule.AvoidEnumAsIdentifier(),
thisModule.CloneMethodMustBePublic(),
thisModule.detachedTestCase(),
thisModule.doNotCallGarbageCollectionExplicitly(),
thisModule.doNotCallSystemExit(),
thisModule.doNotExtendJavaLangError(),
......@@ -117,6 +119,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.finalizeShouldBeProtected(),
thisModule.importFromSamePackage(),
thisModule.missingBreakInSwitch(),
thisModule.nullAssignment(),
thisModule.suspiciousEqualsMethodName(),
thisModule.testClassWithoutTest(),
thisModule.UnconditionalIfStatement(),
......@@ -1878,3 +1881,69 @@ rule MeasureAvoidReassigningParameters(assignment: java!SingleVariableAccess) {
noc;
}
}
--------------------------------------------- ExcessivePublicCount ---------------------------------------------
-- A Measure instance if the class violates the rule 'ExcessivePublicCount'.
rule MesureExcessivePublicCount(class : java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExcessivePublicCount',
shortDescription <- 'Classes with large numbers of public methods and attributes require disproportionate testing efforts since combinational side effects grow rapidly and increase risk. Refactoring these classes into smaller ones not only increases testability and reliability but also allows new variations to be developed easily.'
),
measurement: smm!DirectMeasurement (
error <- class.originalCompilationUnit.name + ' has excessive public count'
)
do {
noc;
}
}
--------------------------------------------- NullAssignment ---------------------------------------------
-- A Measure instance if the class violates the rule 'NullAssignment'.
rule MesureNullAssignment(assign : java!NullLiteral) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'NullAssignment',
shortDescription <- 'Assigning a "null" to a variable (outside of its declaration) is usually bad form. Sometimes, this type of assignment is an indication that the programmer doesn?t completely understand what is going on in the code.'
),
measurement: smm!DirectMeasurement (
error <- assign.originalCompilationUnit.name + ' has null assignment'
)
do {
noc;
}
}
--------------------------------------------- DetachedTestCase ---------------------------------------------
-- A Measure instance if the class violates the rule 'DetachedTestCase'.
rule MesureDetachedTestCase(comp : java!CompilationUnit) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'DetachedTestCase',
shortDescription <- 'The method appears to be a test case since it has public or default visibility, non-static access, no arguments, no return value, has no annotations, but is a member of a class that has one or more JUnit test cases. If it is a utility method, it should likely have private visibility. If it is an ignored test, it should be annotated with @Test and @Ignore.'
),
measurement: smm!DirectMeasurement (
error <- comp.name + ' has detached test case'
)
do {
noc;
}
}
\ No newline at end of file
......@@ -156,3 +156,17 @@ helper def: excessiveImports() : Set(smm!Measure) =
-> select (i | i.imports <> OclUndefined)
-> select (i | i.imports.size() > 4)
-> collect(i | thisModule.MeasureExcessiveImports(i));
--------------------------------------------- ExcessivePublicCount ---------------------------------------------
-- Helper for issue ExcessivePublicCount : return a Measure for each method that has excessive public count.
helper def: excessivePublicCount() : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> reject(each | each.isProxy())
-> select(each | each.listPublicFieldandMethod()->size()>45)
-> collect(each | thisModule.MesureExcessivePublicCount(each));
-- List public field and method in ClassDeclaration
helper context java!ClassDeclaration def: listPublicFieldandMethod() : java!ClassDeclaration =
self.bodyDeclarations
-> select(bodyDeclaration | bodyDeclaration.oclIsTypeOf(java!FieldDeclaration) or bodyDeclaration.oclIsTypeOf(java!MethodDeclaration))
-> select(bodyDeclaration | bodyDeclaration.modifier.visibility.toString() = 'public');
......@@ -386,3 +386,50 @@ helper context java!MethodInvocation def: isSystemExit(): Boolean =
-- 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';
--------------------------------------------- NullAssignment ---------------------------------------------
-- Helper for issue NullAssignment : return a Measure for each null assignment.
helper def: nullAssignment() : Set(smm!Measure) =
-- Browse through all null assignement
java!NullLiteral.allInstances()
->select(it | it.eContainer().oclIsTypeOf(java!Assignment))
-> select(it | it.eContainer().eContainer().oclIsTypeOf(java!ExpressionStatement))
-> select(it | it.eContainer().operator.toString() = '=')
-> collect(it |thisModule.MesureNullAssignment(it))
;
--------------------------------------------- DetachedTestCase ---------------------------------------------
-- Helper for issue DetachedTestCase : return a Measure for each detached test case.
helper def: detachedTestCase() : Set(smm!Measure) =
java!CompilationUnit.allInstances()
-> select(each | each.imports.size() > 0)
-> select(each | each.hasJunitAnnotation().size()>0)
-> select(it | it.types <> OclUndefined)
->iterate(c; res : Set(smm!Measure) = Set{} |
c.types
->select(it1 | it1.oclIsTypeOf(java!ClassDeclaration))
->iterate(c1; res1 : Set(smm!Measure) = Set{} |
c1.bodyDeclarations
-- select method has public or default visibility, non-static access, no arguments, no return value, has no annotations
-> select(bodyDeclaration | bodyDeclaration.oclIsTypeOf(java!MethodDeclaration))
-> select(bodyDeclaration | bodyDeclaration.modifier.visibility.toString() = 'public' or bodyDeclaration.modifier.visibility.toString() = 'none')
-> select(bodyDeclaration | bodyDeclaration.modifier.static.toString() = 'false')
-> select(bodyDeclaration | bodyDeclaration.returnType.oclIsTypeOf(java!TypeAccess))
-> select(bodyDeclaration | bodyDeclaration.returnType.type.oclIsTypeOf(java!PrimitiveTypeVoid))
-> select(bodyDeclaration | bodyDeclaration.parameters.isEmpty())
-> select(bodyDeclaration | bodyDeclaration.annotations.isEmpty())
-> collect(bodyDeclaration | thisModule.MesureDetachedTestCase(c))
)
)
;
--Indicates whether a CompilationUnit has a Junit Annotation.
helper context java!CompilationUnit def: hasJunitAnnotation() : Boolean =
self.imports
-> select(it | it.oclIsTypeOf(java!ImportDeclaration))
-> select(it | it.importedElement.oclIsTypeOf(java!AnnotationTypeDeclaration))
-> select(it | it.importedElement.package.package.package.name = 'junit')
;
\ 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