codestyle.atl 4.02 KB
Newer Older
1
2
3
4
library codestyle;

------------------------------------------------------------------------------------------

5
6
7
-- Rule for metrics AvoidDollarSigns : return the set of class Measures that violates the rule.
helper def: avoidDollarSigns() : Set(smm!Measure) =
	-- Browse through all variable/method/class/interface. 
8
9
	java!TypeDeclaration.allInstances()->union(java!MethodDeclaration.allInstances())->union(java!VariableDeclaration.allInstances())->select(i | i.name.indexOf('$') <> -1)
	->collect(i | thisModule.MesureAvoidDollarSigns(i));
10

11
12
13
14
15
-- Rule for metrics shortMethodName : return the set of method Measures that violates the rule.
helper def: shortMethodName() : Set(smm!Measure) =
	-- Browse through all method, add a new measurement if the size of the method name is less than 3.
	java!MethodDeclaration.allInstances() -> reject(each | each.isProxy())->select(i|i.name.size() < 3)->collect(j|thisModule.MesureShortMethodName(j));

Marion HUNAULT's avatar
Marion HUNAULT committed
16
17
18
19
20
21
22
--------------------------------------------- ShortClassName ---------------------------------------------
-- Rule for metrics shortClassName : return the set of class Measures that violates the rule.
helper def: shortClassName() : Set(smm!Measure) =
    java!ClassDeclaration.allInstances() -> reject(each | each.isProxy())
		-> select( i | i.name.size() < 4)
		-> collect (i | thisModule.MesureShortClassName(i));

23
24
25
26
--------------------------------------------- TooManyStaticImports ---------------------------------------------

-- Rule for metrics TooManyStaticImports : return the set of class Measures that violates the rule.
helper def: tooManyStaticImports() : Set(smm!Measure) =
27
28
29
	java!CompilationUnit.allInstances()
		-- Add a new measurement if there are more than 4 static imports in the file.
	    -> select (c | c.types.first().oclIsTypeOf(java!ClassDeclaration) and c.imports->select(i | i.static)->size() > 4)
Marion HUNAULT's avatar
Marion HUNAULT committed
30
	    -> collect(c | thisModule.MesureTooManyStaticImports(c));
Louis QUESTEL's avatar
Louis QUESTEL committed
31
32
33
		
		
--------------------------------------------- ExtendsObject ---------------------------------------------
Marion HUNAULT's avatar
Marion HUNAULT committed
34

Louis QUESTEL's avatar
Louis QUESTEL committed
35
36
37
38
39
40
41
42
43
-- Rule for metrics ExtendsObject
helper def: extendsObject() : Set(smm!Measure) =
	-- select all class with a superTyper
	java!ClassDeclaration.allInstances()->select(it | (it.superClass <> OclUndefined))
		-- select all class create by the user
		->select(it2| it2.proxy = false)
		-- select all class who extend Object
		->select(it3| it3.superClass.type.name = 'java.lang.Object' or it3.superClass.type.name = 'Object')
		-- collect all results and send an error message
44
		->collect(it4|thisModule.MeasureExtendsObject(it4))
Louis QUESTEL's avatar
Louis QUESTEL committed
45
	;
46
47
48
49
50
51
52
53

--------------------------------------------- UnnecessaryReturn  ---------------------------------------------
-- Rule for metrics UnnecessaryReturn :
helper def: unnecessaryReturn() : Set (smm!Measure) = 
	-- Browse through all method declarations
	java!ReturnStatement.allInstances()
		->select(state | not state.expression.oclIsTypeOf(java!SingleVariableAccess))
		->collect(state | thisModule.MeasureUnnecessaryReturn(state));
54
55
56
57
58
59
60
61

--------------------------------------------- LongVariable  ---------------------------------------------
-- Rule for metrics LongVariable
helper def: longVariable() : Set(smm!Measure) =
    java!VariableDeclarationFragment.allInstances()
		-> select( variable | variable.name.size() > 17)
		-> collect (variable | thisModule.MeasureLongVariable(variable));

62
63
64
65
66
67
68
69
70
71
72
73
74


--------------------------------------------- ShortVariableName ---------------------------------------------
-- Rule for metrics shortVariableName : return the set of variables measures that violates the rule.
helper def: shortVariableName() : Set(smm!Measure) =
    java!SingleVariableDeclaration.allInstances()
		-> reject(each | each.isProxy() or not each.catchClause->oclIsUndefined() or not each.enhancedForStatement->oclIsUndefined())
		-> select( i | i.name.size() < 3)
		-> union( java!VariableDeclarationFragment.allInstances()
			-> reject(each | each.isProxy() or each.variablesContainer.oclIsTypeOf(java!VariableDeclarationExpression))
			-> select( i | i.name.size() < 3)
		)
		-> collect (i | thisModule.MesureShortVariableName(i));