Repository navigation
Expand file tree
/
Copy pathcodesize.xml
More file actions
202 lines (185 loc) · 6 KB
/
Copy pathcodesize.xml
File metadata and controls
202 lines (185 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?xml version="1.0"?>
<ruleset name="Code Size Rules" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../etc/ruleset_xml_schema.xml">
<description>
The Code Size Ruleset contains a collection of rules that find code size related problems.
</description>
<rule name="ExcessiveMethodLength"
message="Avoid really long methods."
class="net.sourceforge.pmd.rules.design.LongMethodRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#ExcessiveMethodLength">
<description>
Violations of this rule usually indicate that the method is doing
too much. Try to reduce the method size by creating helper methods and removing any copy/pasted code.
</description>
<priority>3</priority>
<properties>
<property name="minimum" description="The method size reporting threshold" value="100"/>
</properties>
<example>
<![CDATA[
public class Foo {
public void doSomething() {
System.out.println("Hello world!");
System.out.println("Hello world!");
// 98 copies omitted for brevity.
}
}
]]>
</example>
</rule>
<rule name="ExcessiveParameterList"
message="Avoid really long parameter lists."
class="net.sourceforge.pmd.rules.design.LongParameterListRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#ExcessiveParameterList">
<description>
Long parameter lists can indicate that a new object should be created to
wrap the numerous parameters. Basically, try to group the parameters together.
</description>
<priority>3</priority>
<properties>
<property name="minimum" description="The parameter count reporting threshold" value="10"/>
</properties>
<example>
<![CDATA[
public class Foo {
public void addData(
int p0, int p1, int p2, int p3, int p4, int p5,
int p5, int p6, int p7, int p8, int p9, int p10) {
}
}
}
]]>
</example>
</rule>
<rule name="ExcessiveClassLength"
message="Avoid really long classes."
class="net.sourceforge.pmd.rules.design.LongClassRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#ExcessiveClassLength">
<description>
Long Class files are indications that the class may be trying to
do too much. Try to break it down, and reduce the size to something
manageable.
</description>
<priority>3</priority>
<properties>
<property name="minimum" description="The class size reporting threshold" value="1000"/>
</properties>
<example>
<![CDATA[
public class Foo {
public void bar() {
// 1000 lines of code
}
}
]]>
</example>
</rule>
<rule name="CyclomaticComplexity"
message = "The {0} ''{1}'' has a Cyclomatic Complexity of {2}."
class="net.sourceforge.pmd.rules.CyclomaticComplexity"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#CyclomaticComplexity">
<description>
Complexity is determined by the number of decision points in a method plus one for the
method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally,
1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity,
and 11+ is very high complexity.
</description>
<priority>3</priority>
<properties>
<property name="reportLevel" description="The Cyclomatic Complexity reporting threshold" value="10"/>
</properties>
<example>
<![CDATA[
// Cyclomatic Complexity = 12
public class Foo {
1 public void example() {
2 if (a == b) {
3 if (a1 == b1) {
fiddle();
4 } else if a2 == b2) {
fiddle();
} else {
fiddle();
}
5 } else if (c == d) {
6 while (c == d) {
fiddle();
}
7 } else if (e == f) {
8 for (int n = 0; n < h; n++) {
fiddle();
}
} else{
switch (z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
12 default:
fiddle();
break;
}
}
}
}
]]>
</example>
</rule>
<rule name="ExcessivePublicCount"
message="This class has a bunch of public methods and attributes"
class="net.sourceforge.pmd.rules.ExcessivePublicCount"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#ExcessivePublicCount">
<description>
A large number of public methods and attributes declared in a class can indicate the
class may need to be broken up as increased effort will be required to thoroughly test it.
</description>
<priority>3</priority>
<properties>
<property name="minimum" description="The public item reporting threshold" value="45"/>
</properties>
<example>
<![CDATA[
public class Foo {
public String value;
public Bar something;
public Variable var;
// [... more more public attributes ...]
public void doWork() {}
public void doMoreWork() {}
public void doWorkAgain() {}
// [... more more public methods ...]
}
]]>
</example>
</rule>
<rule name="TooManyFields"
message="Too many fields"
class="net.sourceforge.pmd.rules.design.TooManyFields"
externalInfoUrl="http://pmd.sourceforge.net/rules/codesize.html#TooManyFields">
<description>
Classes that have too many fields could be redesigned to have fewer fields, possibly
through some nested object grouping of some of the information. For example, a class with
city/state/zip fields could instead have one Address field.
</description>
<priority>3</priority>
<properties>
<property name="maxfields" description="The field count reporting threshold " value="15"/>
</properties>
<example>
<![CDATA[
public class Person {
String one;
int two;
int three;
[... many more public fields ...]
}
]]>
</example>
</rule>
</ruleset>