Commit 275dd973 authored by ArthuurT's avatar ArthuurT
Browse files

Revert "Projet ATL"

This reverts commit 9761d492.
parent 9761d492
<?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="AvoidProtectedFieldInFinalClass">
<ownedElements name="main">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FinalClassWithNoProtectedField">
<modifier visibility="public" inheritance="final"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="x"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier visibility="private"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="y"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.0" name="FinalClassWithNoProtectedField">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="FinalClassWithProtectedField">
<modifier visibility="public" inheritance="final"/>
<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:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier visibility="protected"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="y"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" originalCompilationUnit="//@compilationUnits.1" name="FinalClassWithProtectedField">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.1"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="FinalClassWithNoProtectedField.java" originalFilePath="/home/asao/eclipse-photon-workspace/AvoidProtectedFieldInFinalClass/src/main/FinalClassWithNoProtectedField.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="FinalClassWithProtectedField.java" originalFilePath="/home/asao/eclipse-photon-workspace/AvoidProtectedFieldInFinalClass/src/main/FinalClassWithProtectedField.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="ConstantsInterface">
<ownedElements name="main">
<ownedElements xsi:type="java:InterfaceDeclaration" originalCompilationUnit="//@compilationUnits.0" name="CorrectInterface">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="method1">
<modifier visibility="public"/>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" originalCompilationUnit="//@compilationUnits.1" name="ConstantsInterface" usagesInTypeAccess="//@ownedElements.0/@ownedElements.2/@superInterfaces.0">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier visibility="public" inheritance="final" static="true"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="const_1">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.1" tokenValue="0"/>
</fragments>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier visibility="public" inheritance="final"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="const_2">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.1" tokenValue="0"/>
</fragments>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier inheritance="final"/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="const_3">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.1" tokenValue="0"/>
</fragments>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.1">
<modifier/>
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.1" name="const_4">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.1" tokenValue="0"/>
</fragments>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="method1">
<modifier visibility="public"/>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.1" name="method2">
<modifier visibility="public"/>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.2" name="ConstantsInterfaceImpl">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.2" name="method1">
<annotations originalCompilationUnit="//@compilationUnits.2">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</annotations>
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.2">
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.2">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.2" content="// TODO Auto-generated method stub" prefixOfParent="true"/>
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.2" tokenValue="0"/>
</statements>
</body>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.2" name="method2">
<annotations originalCompilationUnit="//@compilationUnits.2">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</annotations>
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.2">
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.2">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.2" content="// TODO Auto-generated method stub" prefixOfParent="true"/>
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.2" tokenValue="0"/>
</statements>
</body>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.0/@ownedElements.1"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" originalCompilationUnit="//@compilationUnits.3" name="EmptyInterface">
<modifier visibility="public"/>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:AnnotationTypeDeclaration" name="Override" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.2/@bodyDeclarations.0/@annotations.0/@type //@ownedElements.0/@ownedElements.2/@bodyDeclarations.1/@annotations.0/@type"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.1/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.2/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.3/@type //@ownedElements.0/@ownedElements.1/@bodyDeclarations.4/@returnType //@ownedElements.0/@ownedElements.1/@bodyDeclarations.5/@returnType //@ownedElements.0/@ownedElements.2/@bodyDeclarations.0/@returnType //@ownedElements.0/@ownedElements.2/@bodyDeclarations.1/@returnType"/>
<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="CorrectInterface.java" originalFilePath="/home/asao/eclipse-photon-workspace/ConstantsInterface/src/main/CorrectInterface.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="ConstantsInterface.java" originalFilePath="/home/asao/eclipse-photon-workspace/ConstantsInterface/src/main/ConstantsInterface.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.1"/>
<compilationUnits name="ConstantsInterfaceImpl.java" originalFilePath="/home/asao/eclipse-photon-workspace/ConstantsInterface/src/main/ConstantsInterfaceImpl.java" commentList="//@ownedElements.0/@ownedElements.2/@bodyDeclarations.0/@body/@statements.0/@comments.0 //@ownedElements.0/@ownedElements.2/@bodyDeclarations.1/@body/@statements.0/@comments.0" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.2"/>
<compilationUnits name="EmptyInterface.java" originalFilePath="/home/asao/eclipse-photon-workspace/ConstantsInterface/src/main/EmptyInterface.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.3"/>
</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="DefaultLabelNotLastInSwitchStmt">
<ownedElements name="main">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="DefaultLabelNotLastInSwitchStmt">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="test1">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:SwitchStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0" default="true"/>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression">
<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">
<statements xsi:type="java:SwitchStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0" default="true"/>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression">
<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">
<statements xsi:type="java:SwitchStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@parameters.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="1"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
<statements xsi:type="java:SwitchCase" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="2"/>
</statements>
<statements xsi:type="java:BreakStatement" originalCompilationUnit="//@compilationUnits.0"/>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression">
<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.1/@parameters.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.2/@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"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<compilationUnits name="DefaultLabelNotLastInSwitchStmt.java" originalFilePath="/home/asao/eclipse-photon-workspace/DefaultLabelNotLastInSwitchStmt/src/main/DefaultLabelNotLastInSwitchStmt.java" package="//@ownedElements.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
......@@ -50,7 +50,6 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.extendsObject(),
thisModule.unnecessaryReturn(),
thisModule.longVariable(),
thisModule.avoidProtectedFieldInFinalClass(),
-- Design rules
--
......@@ -98,9 +97,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Best practices rules
thisModule.avoidThrowingNewInstanceOfSameException(),
thisModule.useAssertTrueInsteadOfAssertEquals(),
thisModule.switchDensity(),
thisModule.defaultLabelNotLastInSwitchStmt(),
thisModule.constantsInInterface()
thisModule.switchDensity()
--thisModule.avoidStringBufferField()
};
......@@ -1098,71 +1095,6 @@ rule MesureFinalizeShouldBeProtected(m : java!MethodDeclaration) {
}
}
------------------------------------------- ConstantsInInterface----------------------------------------------
-- A Measure instance if the class violates the rule ConstantsInInterface.
rule MeasureConstantsInInterface(interface: java!InterfaceDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ConstantsInInterface',
shortDescription <- 'Avoid constants in interfaces. Interfaces should define types, constants are implementation details better placed in classes or enums'
),
measurement: smm!DirectMeasurement (
error<- 'Interface ' + interface.name + ' should not define types'
)
do {
noc;
}
}
------------------------------------------- DefaultLabelNotLastInSwitchStmt----------------------------------------------
-- A Measure instance if the class violates the rule DefaultLabelNotLastInSwitchStmt.
rule MeasureDefaultLabelNotLastInSwitchStmt(switchStmt: java!SwitchStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'DefaultLabelNotLastInSwitchStmt',
shortDescription <- 'By convention, the default label should be the last label in a switch statement'
),
measurement: smm!DirectMeasurement (
error<- 'Incorrect switch statement in the file ' + switchStmt.originalCompilationUnit.name
)
do {
noc;
}
}
------------------------------------------- AvoidProtectedFieldInFinalClass----------------------------------------------
-- A Measure instance if the class violates the rule AvoidProtectedFieldInFinalClass.
rule MeasureAvoidProtectedFieldInFinalClass(class: java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidProtectedFieldInFinalClass',
shortDescription <- 'Do not use protected fields in final classes since they cannot be subclassed.'
),
measurement: smm!DirectMeasurement (
error<- 'The final class ' + class.name + ' has at least one protected field !'
)
do {
noc;
}
}
......
......@@ -94,69 +94,3 @@ helper def: avoidStringBufferField() : Set(smm!Measure) =
java!FieldDeclaration.allInstances()
->select(dec | dec.type.type.name = 'StringBuffer' or dec.type.type.name = 'StringBuilder')
->collect(dec | thisModule.MeasureAvoidStringBufferField(dec));
------------------------------------------- ConstantsInInterface----------------------------------------------
-- A Measure instance if the class violates the rule ConstantsInInterface.
rule MeasureConstantsInInterface(interface: java!InterfaceDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ConstantsInInterface',
shortDescription <- 'Avoid constants in interfaces. Interfaces should define types, constants are implementation details better placed in classes or enums'
),
measurement: smm!DirectMeasurement (
error<- 'Interface ' + interface.name + ' should not define types'
)
do {
noc;
}
}
------------------------------------------- DefaultLabelNotLastInSwitchStmt----------------------------------------------
-- A Measure instance if the class violates the rule DefaultLabelNotLastInSwitchStmt.
rule MeasureDefaultLabelNotLastInSwitchStmt(switchStmt: java!SwitchStatement) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'DefaultLabelNotLastInSwitchStmt',
shortDescription <- 'By convention, the default label should be the last label in a switch statement'
),
measurement: smm!DirectMeasurement (
error<- 'Incorrect switch statement in the file ' + switchStmt.originalCompilationUnit.name
)
do {
noc;
}
}
------------------------------------------- AvoidProtectedFieldInFinalClass----------------------------------------------
-- A Measure instance if the class violates the rule AvoidProtectedFieldInFinalClass.
rule MeasureAvoidProtectedFieldInFinalClass(class: java!ClassDeclaration) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidProtectedFieldInFinalClass',
shortDescription <- 'Do not use protected fields in final classes since they cannot be subclassed.'
),
measurement: smm!DirectMeasurement (
error<- 'The final class ' + class.name + ' has at least one protected field !'
)
do {
noc;
}
}
......@@ -64,32 +64,3 @@ helper def: longVariable() : Set(smm!Measure) =
-> select( variable | variable.name.size() > 17)
-> collect (variable | thisModule.MeasureLongVariable(variable));
--------------------------------------------- AvoidProtectedFieldInFinalClass ---------------------------------------------
-- Rule for metrics AvoidProtectedFieldInFinalClass
helper def: avoidProtectedFieldInFinalClass(): Set(smm!Measure) =
java!ClassDeclaration.allInstances()->select(class |
if class.isFinal() then
class.hasProtectedField()
else
false
endif
)->collect(class |
thisModule.MeasureAvoidProtectedFieldInFinalClass(class)
);
-- Returns true if the class has a protected field, false otherwise
helper context java!ClassDeclaration def: hasProtectedField(): Boolean =
if self.bodyDeclarations.isEmpty() then
false
else
self.bodyDeclarations->exists(declaration |
declaration.modifier.visibility = #protected
)
endif;
-- Returns true if the class is final, false otherwise
helper context java!ClassDeclaration def: isFinal(): Boolean =
self.modifier.inheritance = #final;
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