errorProne.atl 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
library errorProne;

---------------------------------- Missing break in switch---------------------------------------------

-- Returns a set of measures for each switch statement that violates the rule : missing break in switch
helper def: missingBreakInSwitch(): Set(smm!Measure) = 
	java!SwitchStatement.allInstances()
		-> select (switchStatement | thisModule.switchStatementContainsMissingBreaks(switchStatement))
		-> collect (switchStatement | thisModule.createMeasureForMissingBreakInSwitch(switchStatement))
;

-- Returns true if the switch statement contains missing breaks, false otherwise 
helper def: switchStatementContainsMissingBreaks(ss: java!SwitchStatement): Boolean = 
	-- If the number of switch cases (omitting those that empty => indicates intentional fallout) is bigger than
	-- the number of break statements => we don't have a break statement for every switch case 
	-- in that case, return true, else false
	(thisModule.nbBranchesOfASwitchStatement(ss) - thisModule.nbIntentionalFallThroughOfASwitchStatement(ss)) > thisModule.nbBreakStatementOfASwitchStatement(ss)
;

20
21
22
23
24
25
--------------------------------------------- DoNotExtendJavaLangThrowable ---------------------------------------------

-- Rule for metrics DoNotExtendJavaLangThrowable
helper def: doNotExtendJavaLangThrowable() : Set(smm!Measure) =
	-- select all class with a superTyper
	java!ClassDeclaration.allInstances()->select(it | it.superClass <> OclUndefined)
26
27
		-- select all class create by the user
		->select(it2| it2.proxy = false)
28
		-- select all class who extend Throwable
29
		->select(it3| it3.superClass.type.name = 'Throwable')
30
		-- collect all results and send an error message
31
32
		->collect(it4|thisModule.MeasureDoNotExtendJavaLangThrowable(it4))
	;