Commit 51b92fda authored by Charles BEQUET--ERMOY's avatar Charles BEQUET--ERMOY Committed by BuildTools
Browse files

Fix issue #839

parent adcb314b
<?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="MethodWithSameNameAsEnclosingClass">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="MyClass">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.0" name="MyClass">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this is OK because it is a constructor"/>
</body>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="MyClass">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// this is bad because it is a method"/>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="otherMethod">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int"/>
<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.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="MyClass.java" originalFilePath="C:\Users\Charles\Desktop\travail\M2\ATL\MethodWithSameNameAsEnclosingClass\src\MyClass.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
......@@ -102,6 +102,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.doNotCallGarbageCollectionExplicitly(),
thisModule.emptyCatchBlock(),
thisModule.importFromSamePackage(),
thisModule.methodWithSameNameAsEnclosingClass(),
-- Best practices rules
thisModule.useAssertTrueInsteadOfAssertEquals(),
......@@ -1527,4 +1528,23 @@ rule MeasureImportFromSamePackage(import : java!ImportDeclaration) {
do {
noc;
}
}
-------------------------------------------MethodWithSameNameAsEnclosingClass----------------------------------------------
-- A Measure instance if the class violate the rule MethodWithSameNameAsEnclosingClass
rule MeasureMethodWithSameNameAsEnclosingClass(method : java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'MethodWithSameNameAsEnclosingClass',
shortDescription <- 'Non-constructor methods should not have the same name as the enclosing class.'
),
measurement: smm!DirectMeasurement (
error<- 'Method ' + method.name + ' has the same name as ' + method.originalCompilationUnit.name + ' and is not a contructor.'
)
do {
noc;
}
}
\ No newline at end of file
......@@ -321,4 +321,11 @@ helper def: emptyCatchBlock() : Set(smm!Measure) =
helper def: importFromSamePackage() : Set(smm!Measure) =
java!ImportDeclaration.allInstances()
->select(import | import.importedElement = import.originalCompilationUnit.package)
->collect(import | thisModule.MeasureImportFromSamePackage(import));
\ No newline at end of file
->collect(import | thisModule.MeasureImportFromSamePackage(import));
-----------------------------------------MethodWithSameNameAsEnclosingClass----------------------------------------------
-- Rule for metrics MethodWithSameNameAsEnclosingClass
helper def: methodWithSameNameAsEnclosingClass() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select(method | method.name = method.abstractTypeDeclaration.name)
->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