Commit 25e797a3 authored by Thorrigan's avatar Thorrigan
Browse files

fix issue 836 JUnitSpelling

parent 27803354
<?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="JUnitSpelling">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="JUnitSpelling">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="setup">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// oops, should be setUp"/>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;no empty block statement&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="TearDown">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// oops, should be tearDown"/>
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;no empty block statement&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="TEARdOwn">
<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.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;no empty block statement&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="SETup">
<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.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;no empty block statement&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="tearDown">
<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.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;no empty block statement&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.2/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
</expression>
</expression>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="junit" proxy="true">
<ownedPackages name="framework" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="TestCase" proxy="true" usagesInImports="//@compilationUnits.0/@imports.0" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Assert" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superClass"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Test" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</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/@bodyDeclarations.0/@body/@statements.0/@expression/@expression/@qualifier //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.1/@body/@statements.0/@expression/@expression/@qualifier //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.2/@body/@statements.0/@expression/@expression/@qualifier //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.3/@body/@statements.0/@expression/@expression/@qualifier //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.4/@body/@statements.0/@expression/@expression/@qualifier">
<bodyDeclarations xsi:type="java:FieldDeclaration" proxy="true">
<fragments name="out" proxy="true" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.0/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.1/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.2/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.3/@body/@statements.0/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.4/@body/@statements.0/@expression/@expression"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0/@parameters.0/@type">
<superInterfaces type="//@ownedElements.2/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.2"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.1/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.1/@superInterfaces.2"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="AutoCloseable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.4/@superInterfaces.0"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Appendable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.1/@superInterfaces.0"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.0/@ownedElements.1/@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/@bodyDeclarations.0/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.1/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.2/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.3/@body/@statements.0/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.4/@body/@statements.0/@expression">
<parameters name="arg0" proxy="true">
<type type="//@ownedElements.2/@ownedPackages.0/@ownedElements.1"/>
</parameters>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.1/@ownedElements.4"/>
<superClass type="//@ownedElements.2/@ownedPackages.1/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="FilterOutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.1/@superClass">
<superClass type="//@ownedElements.2/@ownedPackages.1/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="OutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.2/@superClass">
<superInterfaces type="//@ownedElements.2/@ownedPackages.1/@ownedElements.4"/>
<superInterfaces type="//@ownedElements.2/@ownedPackages.1/@ownedElements.5"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Closeable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.3/@superInterfaces.0 //@ownedElements.2/@ownedPackages.1/@ownedElements.1/@superInterfaces.1">
<superInterfaces type="//@ownedElements.2/@ownedPackages.0/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Flushable" proxy="true" usagesInTypeAccess="//@ownedElements.2/@ownedPackages.1/@ownedElements.3/@superInterfaces.1"/>
</ownedPackages>
</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.0/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.1/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.2/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.3/@returnType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.4/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="JUnitSpelling.java" originalFilePath="C:\Users\Thorrigan\Documents\Master\workspace\JUnitSpelling\src\JUnitSpelling.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.0/@body/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@bodyDeclarations.1/@body/@comments.0" types="//@ownedElements.0/@ownedElements.0">
<imports originalCompilationUnit="//@compilationUnits.0" importedElement="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</compilationUnits>
</java:Model>
......@@ -124,6 +124,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.emptyWhileStmt(),
thisModule.finalizeShouldBeProtected(),
thisModule.importFromSamePackage(),
thisModule.junitSpelling(),
thisModule.missingBreakInSwitch(),
thisModule.nullAssignment(),
thisModule.suspiciousEqualsMethodName(),
......@@ -1176,6 +1177,27 @@ rule MeasureIntegerInstantiation(variable : java!CompilationUnit) {
}
}
-- ------------------------------------------- JUnitSpelling ---------------------------------------------
--- return a Measure for if "tearDown" or "setUp" arent spelled with a capital D and U and the rest is in lower case
rule MeasureJUnitSpelling(i : java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'JUnitSpelling',
shortDescription <- 'Some JUnit framework methods are easy to misspell.'
),
measurement: smm!DirectMeasurement (
error<-'The method Junit ' + i.name + ' is not spelled correctly.',
name<- i.name + ' is not spelled correctly'
)
do {
noc;
}
}
-- ------------------------------------------- LongInstantiation ---------------------------------------------
--- A Measure instance if the class violates the rule 'LongInstantiation'.
rule MeasureLongInstantiation(variable : java!CompilationUnit) {
......
......@@ -339,6 +339,14 @@ helper def: importFromSamePackage() : Set(smm!Measure) =
->select(import | import.importedElement = import.originalCompilationUnit.package)
->collect(import | thisModule.MeasureImportFromSamePackage(import));
-- ------------------------------------------- JUnitSpelling ---------------------------------------------
--- Helper for issue JUnitSpelling : Some JUnit framework methods are easy to misspell !("tearDown", "setUp").
helper def: junitSpelling() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
-> select(i | ((i.name <> 'tearDown' and i.name <> 'setUp') and (i.name.toLower() = 'teardown' or i.name.toLower() = 'setup')))
-> collect(i | thisModule.MeasureJUnitSpelling(i));
-----------------------------------------MethodWithSameNameAsEnclosingClass----------------------------------------------
-- Rule for metrics MethodWithSameNameAsEnclosingClass
helper def: methodWithSameNameAsEnclosingClass() : Set(smm!Measure) =
......
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