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

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

5
6
7
8
9
10
11
-- 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. 
	java!TypeDeclaration.allInstances()->union(java!MethodDeclaration.allInstances())->union(java!VariableDeclaration.allInstances())->iterate(i; res : Set(smm!Measure) = Set{} |
		-- Add a new measurement if the name contains a dollar.
		if i.name.indexOf('$') <> -1
		then res->union(Set{thisModule.MesureAvoidDollarSigns(i)})
12
13
14
15
		else res
		endif
	);

16
17
18
19
20
-- 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
21
22
23
24
25
26
27
--------------------------------------------- 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));

28
29
30
31
--------------------------------------------- TooManyStaticImports ---------------------------------------------

-- Rule for metrics TooManyStaticImports : return the set of class Measures that violates the rule.
helper def: tooManyStaticImports() : Set(smm!Measure) =
32
33
34
	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
35
	    -> collect(c | thisModule.MesureTooManyStaticImports(c));
Louis QUESTEL's avatar
Louis QUESTEL committed
36
37
38
		
		
--------------------------------------------- ExtendsObject ---------------------------------------------
Marion HUNAULT's avatar
Marion HUNAULT committed
39

Louis QUESTEL's avatar
Louis QUESTEL committed
40
41
42
43
44
45
46
47
48
49
50
-- 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
		->collect(it4|thisModule.MeasureDoNotExtendJavaLangError(it4))
	;