-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-imports.xml
More file actions
145 lines (129 loc) · 4.94 KB
/
java-imports.xml
File metadata and controls
145 lines (129 loc) · 4.94 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
<?xml version="1.0"?>
<ruleset name="Import Statements"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
These rules deal with different problems that can occur with import statements.
</description>
<rule name="DuplicateImports"
since="0.5"
message="Avoid duplicate imports such as ''{0}''"
class="net.sourceforge.pmd.lang.java.rule.imports.DuplicateImportsRule"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#DuplicateImports">
<description>
Duplicate or overlapping import statements should be avoided.
</description>
<priority>4</priority>
<example>
<![CDATA[
import java.lang.String;
import java.lang.*;
public class Foo {}
]]>
</example>
</rule>
<rule name="DontImportJavaLang"
since="0.5"
message="Avoid importing anything from the package 'java.lang'"
class="net.sourceforge.pmd.lang.java.rule.imports.DontImportJavaLangRule"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#DontImportJavaLang">
<description>
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
</description>
<priority>4</priority>
<example>
<![CDATA[
import java.lang.String; // this is unnecessary
public class Foo {}
// --- in another source code file...
import java.lang.*; // this is bad
public class Foo {}
]]>
</example>
</rule>
<rule name="UnusedImports"
since="1.0"
message="Avoid unused imports such as ''{0}''"
class="net.sourceforge.pmd.lang.java.rule.imports.UnusedImportsRule"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#UnusedImports">
<description>
Avoid the use of unused import statements to prevent unwanted dependencies.
</description>
<priority>4</priority>
<example>
<![CDATA[
// this is bad
import java.io.File;
public class Foo {}
]]>
</example>
</rule>
<rule name="ImportFromSamePackage"
since="1.02"
message="No need to import a type that lives in the same package"
class="net.sourceforge.pmd.lang.java.rule.imports.ImportFromSamePackageRule"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#ImportFromSamePackage">
<description>
There is no need to import a type that lives in the same package.
</description>
<priority>3</priority>
<example>
<![CDATA[
package foo;
import foo.Buz; // no need for this
import foo.*; // or this
public class Bar{}
]]>
</example>
</rule>
<rule name="TooManyStaticImports"
language="java"
since="4.1"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="Too many static imports may lead to messy code"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#TooManyStaticImports">
<description><![CDATA[
If you overuse the static import feature, it can make your program unreadable and
unmaintainable, polluting its namespace with all the static members you import.
Readers of your code (including you, a few months after you wrote it) will not know
which class a static member comes from (Sun 1.5 Language Guide).
]]></description>
<priority>3</priority>
<properties>
<property name="maximumStaticImports" type="Integer"
description="All static imports can be disallowed by setting this to 0" min="0" max="100" value="4"/>
<property name="xpath">
<value><![CDATA[
.[count(ImportDeclaration[@Static = 'true']) > $maximumStaticImports]
]]></value>
</property>
</properties>
<example><![CDATA[
import static Lennon;
import static Ringo;
import static George;
import static Paul;
import static Yoko; // Too much !
]]></example>
</rule>
<rule name="UnnecessaryFullyQualifiedName"
language="java"
since="5.0"
class="net.sourceforge.pmd.lang.java.rule.imports.UnnecessaryFullyQualifiedNameRule"
message="Unnecessary use of fully qualified name ''{0}'' due to existing {2}import ''{1}''"
externalInfoUrl="https://pmd.github.io/pmd-5.5.1/pmd-java/rules/java/imports.html#UnnecessaryFullyQualifiedName">
<description><![CDATA[
Import statements allow the use of non-fully qualified names. The use of a fully qualified name
which is covered by an import statement is redundant. Consider using the non-fully qualified name.
]]></description>
<priority>4</priority>
<example><![CDATA[
import java.util.List;
public class Foo {
private java.util.List list1; // Unnecessary FQN
private List list2; // More appropriate given import of 'java.util.List'
}
]]></example>
</rule>
</ruleset>