Commit c6d75ed4 authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

Conflict resolution

parents 996f7591 b524aa1e
<?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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="bar">
<modifier/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:TryStatement" originalCompilationUnit="//@compilationUnits.0">
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// do something" enclosedByParent="true"/>
</body>
<catchClauses originalCompilationUnit="//@compilationUnits.0">
<exception originalCompilationUnit="//@compilationUnits.0" name="npe">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</exception>
<body originalCompilationUnit="//@compilationUnits.0"/>
</catchClauses>
</statements>
</body>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="NullPointerException" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@catchClauses.0/@exception/@type">
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="RuntimeException" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superClass">
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Exception" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superClass">
<superClass type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="Throwable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.2/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
</ownedElements>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.3/@superInterfaces.0"/>
</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/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@body/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="A">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration">
<type/>
</bodyDeclarations>
</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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="A.java" originalFilePath="D:\workSpace\Test\src\A.java" types="//@ownedElements.0/@ownedElements.0"/>
</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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="clone">
<annotations originalCompilationUnit="//@compilationUnits.0">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
</annotations>
<modifier visibility="protected"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Violation, must be public"/>
<expression xsi:type="java:NullLiteral" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<returnType type="//@ownedElements.0/@ownedElements.0"/>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Cloneable" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@superInterfaces.0"/>
<ownedElements xsi:type="java:AnnotationTypeDeclaration" name="Override" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@annotations.0/@type"/>
</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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:Initializer" originalCompilationUnit="//@compilationUnits.0">
<modifier static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Why ?"/>
</body>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:Initializer" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Again, why ?"/>
<modifier/>
<body originalCompilationUnit="//@compilationUnits.0"/>
</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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@comments.0 //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
</ownedElements>
</ownedElements>
<ownedElements name="myPackage">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ClassWithPackage">
<modifier visibility="public"/>
</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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ClassWithPackage.java" originalFilePath="D:\workSpace\Test\src\myPackage\ClassWithPackage.java" package="//@ownedElements.1" types="//@ownedElements.1/@ownedElements.0"/>
</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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:BooleanLiteral" originalCompilationUnit="//@compilationUnits.0" value="true"/>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<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.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" types="//@ownedElements.0/@ownedElements.0"/>
</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="Test">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0/@initializer/@expression/@type">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier/>
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="cl">
<initializer xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@bodyDeclarations.0">
<expression xsi:type="java:TypeLiteral" originalCompilationUnit="//@compilationUnits.0">
<type type="//@ownedElements.0/@ownedElements.0"/>
</expression>
</initializer>
</fragments>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="ClassLoader" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type"/>
<ownedElements xsi:type="java:ClassDeclaration" name="Class" proxy="true">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="getClassLoader" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0/@initializer"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedPackages.0/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedPackages.0/@ownedElements.2"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedPackages.0/@ownedElements.1"/>
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedPackages name="reflect" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="GenericDeclaration" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superInterfaces.1">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedPackages.0/@ownedElements.1"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="AnnotatedElement" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedPackages.0/@ownedElements.0/@superInterfaces.0 //@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superInterfaces.3"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Type" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superInterfaces.2"/>
</ownedPackages>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.1/@superInterfaces.0"/>
</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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="Foo.java" originalFilePath="D:\workSpace\Test\src\Foo.java" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
......@@ -30,7 +30,7 @@ rule Java2SMM {
helper def: allMeasures(project : java!Model): Set(smm!Measure) =
Set{
Set{
-- Example rule
--
thisModule.numberOfClasses(),
......@@ -48,7 +48,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.extendsObject(),
thisModule.unnecessaryReturn(),
thisModule.longVariable(),
thisModule.noPackageDeclaration(),
-- Design rules
--
thisModule.tooManyFields(),
......@@ -59,7 +60,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.excessiveParameterList(),
thisModule.finalFieldCouldBeStatic(),
thisModule.signatureDeclareThrowsException(),
thisModule.ExcessiveClassLength(),
-- Performance rules
--
thisModule.uselessStringValueOf(),
......@@ -87,8 +89,13 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.dontImportSun(),
thisModule.emptySwitchStatement(),
thisModule.emptySynchronizedBlock(),
thisModule.UnconditionalIfStatement(),
thisModule.EmptyInitializer(),
thisModule.CloneMethodMustBePublic(),
thisModule.AvoidEnumAsIdentifier(),
thisModule.AvoidCatchingNPE(),
thisModule.UseProperClassLoader(),
-- Best practices rules
thisModule.useAssertTrueInsteadOfAssertEquals(),
thisModule.useAssertSameInsteadOfAssertTrue(),
......@@ -1227,3 +1234,159 @@ rule MesureUseAssertSameInsteadOfAssertTrue(tab :java!Package) {
noc;
}
}
-- A Measure instance if the class violates the rule AvoidNoPackageDeclaration.
rule MesureAvoidNoPackageDeclaration(class : java!CompilationUnit) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidNoPackageDeclaration',
shortDescription <- 'you need to declare some package.'
),
measurement: smm!DirectMeasurement (
error <- class.name + ' class have no package declaration'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule UnconditionalIfStatement.
rule MeasureUnconditionalIfStatement(w: java!IfStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'UnconditionalIfStatement',
shortDescription <- ': UnconditionalIfStatement'
),
measurement: smm!DirectMeasurement (
error <- 'UnconditionalIfStatement is detected in ' + w.originalCompilationUnit.name
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule EmptyInitializer.
rule MeasureEmptyInitializer(w: java!Initializer) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'EmptyInitializer',
shortDescription <- ': EmptyInitializer'
),
measurement: smm!DirectMeasurement (
error <- ' class '+w.originalCompilationUnit.name +' hase an empty Initializer! do not declare an EmptyInitializer, EmptyInitializer! this block need to be deleted'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule ExcessiveClassLength.
rule MeasureExcessiveClassLength(w: java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ExcessiveClassLength',
shortDescription <- ': class file lengths are usually indications that the class may be burdened with excessive responsibilities that could be provided by external classes or functions'
),
measurement: smm!DirectMeasurement (
error <- ' class '+w.originalCompilationUnit.name+ ' has a block with more than 1000 line of code per a method it may need a separation in the code'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule CloneMethodMustBePublic.
rule MeasureCloneMethodMustBePublic(w: java!MethodDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'CloneMethodMustBePublic',
shortDescription <- ': Clone Method Must Be Public'
),
measurement: smm!DirectMeasurement (
error <- ' class '+w.originalCompilationUnit.name+ ' has a clone methode witch need to be public '
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule AvoidEnumAsIdentifier.
rule MeasureAvoidEnumAsIdentifier(w: java!VariableDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidEnumAsIdentifier',
shortDescription <- ': Avoid Enum As Identifier'
),
measurement: smm!DirectMeasurement (
error <- ' class '+w.originalCompilationUnit.name+ ' has a variable named to enum witch is a reserved name'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule AvoidCatchingNPE.
rule MeasureAvoidCatchingNPE(w: java!CatchClause) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidCatchingNPE',
shortDescription <- ': Avoid Catching NullPointerExceptions'
),
measurement: smm!DirectMeasurement (
error <- ' class '+w.originalCompilationUnit.name+ ' has a Code that should never
throw NullPointerExceptions under normal circumstances. A catch block may hide the
original error, causing other, more subtle problems later on.'
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule UseProperClassLoader.
rule MeasureUseProperClassLoader(w: java!MethodInvocation) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'UseProperClassLoader',
shortDescription <- ': Use ProperClassLoader'
),
measurement: smm!DirectMeasurement (
error <- ' class'+ w.originalCompilationUnit.name+ ' Use a statement with getClassLoader(),
use Thread.currentThread().getContextClassLoader() instead '
)
do {
noc;
}
}
\ No newline at end of file
......@@ -72,3 +72,21 @@ helper def: shortVariableName() : Set(smm!Measure) =
-> select( i | i.name.size() < 3)
)
-> collect (i | thisModule.MesureShortVariableName(i));
----- Fix Issues #699
--- helper noPackageDeclaration
--- get all the compilation units
--- check if this units contains a defined package or not
--- if there is make a call for MesureAvoidNoPackageDeclaration rule
--- with the detected units
helper def: noPackageDeclaration() : Set(smm!Measure) =
java!CompilationUnit.allInstances()
->select(compUnit | compUnit.package.oclIsUndefined())
->collect(err | thisModule.MesureAvoidNoPackageDeclaration(err));
......@@ -112,4 +112,24 @@ helper def: signatureDeclareThrowsException() : Set (smm!Measure) =
helper def: avoidThrowingNullPointerException() : Set(smm!Measure) =
java!ClassInstanceCreation.allInstances()
->select(c | c.method.name = 'NullPointerException')
->collect(c | thisModule.MeasureAvoidThrowingNullPointerException(c));
\ No newline at end of file
->collect(c | thisModule.MeasureAvoidThrowingNullPointerException(c));
--- Issue #738
--- helper ExcessiveClassLength
--- get all the declaredMethods inside the class
--- check if theire body is defined or not
--- if it is check if this body containes a declared statements or not
--- if it is check if the number of this statement is bigger than 1000
--- in this case make a collection and make call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: ExcessiveClassLength() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.body <> OclUndefined )
->select (w | w.body.statements <> OclUndefined )
->select (w| w.body.statements.size() > 1000)
->collect(w | thisModule.MeasureExcessiveClassLength(w));
......@@ -216,11 +216,82 @@ helper def: emptyfinalizeMethod() : Set(smm!Measure) =
--- Issues #780, #784, #799, #819, #862, #871
--- helper AvoidCatchingNPE
--- get all the catchClause inside the class
--- check if the name of type for the typeAccess is equals to 'NullPointerException'
--- if it is the case make collection and make a call for MeasureAvoidCatchingNPE rule
--- with the detected VariableDeclaration
helper def: AvoidCatchingNPE() : Set(smm!Measure) =
java!CatchClause.allInstances()
->select (w | w.exception.type.type.name = 'NullPointerException')
->collect(w | thisModule.MeasureAvoidCatchingNPE(w));
--- helper AvoidEnumAsIdentifier
-- modisco do not allow to convert a class with error
-- and a field with enum decleration is already detected by Java compiler
-- so we need at least to change the name of enum to Enum to work
--- get all the declared variable inside the class
--- check if their name are defined and
--- if it's different than reserved key word 'enum''
--- if it is not the case make collection and make a call for MeasureAvoidEnumAsIdentifier rule
--- with the detected VariableDeclaration
helper def: AvoidEnumAsIdentifier() : Set(smm!Measure) =
java!VariableDeclaration.allInstances()
->select (w | w.name <> OclUndefined )
->select (w | w.name = 'enum')
->collect(w | thisModule.MeasureAvoidEnumAsIdentifier(w));
--- helper CloneMethodMustBePublic
--- get all the declaredMethods inside the class
--- check if is clone methode or not
--- check if its modifier is defined
--- check if its visibilty access is different from public
--- if it is the case make collection and make a call for MeasureExcessiveClassLength rule
--- with the detected MethodDeclaration
helper def: CloneMethodMustBePublic() : Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select (w | w.modifier <> OclUndefined )
->select (w | w.name = 'clone')
->select (w | w.modifier <> 'public')
->collect(w | thisModule.MeasureCloneMethodMustBePublic(w));
--- helper EmptyInitializer
--- get all the the used Initializer make a selection on all those that
--- has nothing inside theire body (empty initialize),
--- check if the contained statments size equals to 0
--- if there is collect them and make a call for MeasureEmptyInitializer rule
--- with the detected Initializer
helper def: EmptyInitializer() : Set(smm!Measure) =
java!Initializer.allInstances()
->select( w | w.body.statements.size() = 0)
->collect(w | thisModule.MeasureEmptyInitializer(w));
--- helper UnconditionalIfStatement
--- get all the the used ifstatements and make a selection on all those that contains
--- an only expression in which its type is BooleanLiteral type like (true) or (false)
--- if there is collect them and make a call for MeasureUnconditionalIfStatement rule
--- with the detected ifstatments
helper def: UnconditionalIfStatement() : Set(smm!Measure) =
java!IfStatement.allInstances()
->select( w | w.expression.oclIsTypeOf(java!BooleanLiteral))
->collect(w | thisModule.MeasureUnconditionalIfStatement(w));
--- helper UseProperClassLoader
--- get all the MethodInvocation inside the class
--- check if the invocked method name is equals to getClassLoader
--- if it is the case make collection and make a call for MeasureUseProperClassLoader rule
--- with the detected MethodInvocation
helper def: UseProperClassLoader() : Set(smm!Measure) =
java!MethodInvocation.allInstances()
->select (w | w.method.name='getClassLoader')
->collect(w | thisModule.MeasureUseProperClassLoader(w));
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