Skip to content

Commit 406930b

Browse files
egonwrajarshi
authored andcommitted
Introducing PMD test for CDK specific issues:
* "Molecule mol = ..." -> "IMolecule mol = ..." * "ac instanceof Molecule" -> "ac instanceof IMolecule" Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
1 parent d6b6c65 commit 406930b

2 files changed

Lines changed: 361 additions & 0 deletions

File tree

pmd/cdkinterfaces.xml

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="cdkinterfaces">
3+
4+
<description>
5+
This ruleset checks for programming against implementations instead
6+
of interfaces.
7+
</description>
8+
9+
<rule name="MoleculeFieldType"
10+
language="java"
11+
message="Use the IMolecule interfaces instead of the Molecule implementation"
12+
class="net.sourceforge.pmd.rules.XPathRule">
13+
<description>
14+
Programming against the CDK interfaces allows users to pick their favorite
15+
implementation (nonotify, datadebug).
16+
</description>
17+
<priority>2</priority>
18+
<properties>
19+
<property name="xpath">
20+
<value>
21+
<![CDATA[
22+
//Type/ReferenceType/ClassOrInterfaceType[@Image='Molecule']
23+
]]>
24+
</value>
25+
</property>
26+
</properties>
27+
<example>
28+
<![CDATA[
29+
Molecule mol = builder.newInstance(IMolecule.class);
30+
// better:
31+
// IMolecule mol = builder.newInstance(IMolecule.class);
32+
]]>
33+
</example>
34+
</rule>
35+
36+
<rule name="AtomFieldType"
37+
language="java"
38+
message="Use the IAtom interfaces instead of the Atom implementation"
39+
class="net.sourceforge.pmd.rules.XPathRule">
40+
<description>
41+
Programming against the CDK interfaces allows users to pick their favorite
42+
implementation (nonotify, datadebug).
43+
</description>
44+
<priority>2</priority>
45+
<properties>
46+
<property name="xpath">
47+
<value>
48+
<![CDATA[
49+
//Type/ReferenceType/ClassOrInterfaceType[@Image='Atom']
50+
]]>
51+
</value>
52+
</property>
53+
</properties>
54+
<example>
55+
<![CDATA[
56+
Atom mol = builder.newInstance(IAtom.class);
57+
// better:
58+
// IAtom mol = builder.newInstance(IAtom.class);
59+
]]>
60+
</example>
61+
</rule>
62+
63+
<rule name="BondFieldType"
64+
language="java"
65+
message="Use the IBond interfaces instead of the Bond implementation"
66+
class="net.sourceforge.pmd.rules.XPathRule">
67+
<description>
68+
Programming against the CDK interfaces allows users to pick their favorite
69+
implementation (nonotify, datadebug).
70+
</description>
71+
<priority>2</priority>
72+
<properties>
73+
<property name="xpath">
74+
<value>
75+
<![CDATA[
76+
//Type/ReferenceType/ClassOrInterfaceType[@Image='Bond']
77+
]]>
78+
</value>
79+
</property>
80+
</properties>
81+
<example>
82+
<![CDATA[
83+
Bond mol = builder.newInstance(IBond.class);
84+
// better:
85+
// IBond mol = builder.newInstance(IBond.class);
86+
]]>
87+
</example>
88+
</rule>
89+
90+
<rule name="InstanceOfMolecule"
91+
language="java"
92+
message="Use instanceof against interfaces not implementations"
93+
class="net.sourceforge.pmd.rules.XPathRule">
94+
<description>
95+
Programming against the CDK interfaces allows users to pick their favorite
96+
implementation (nonotify, datadebug).
97+
</description>
98+
<priority>1</priority>
99+
<properties>
100+
<property name="xpath">
101+
<value>
102+
<![CDATA[
103+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='Molecule']
104+
]]>
105+
</value>
106+
</property>
107+
</properties>
108+
<example>
109+
<![CDATA[
110+
if (atomContainer instanceof Molecule) {}
111+
// use instead:
112+
// if (atomContainer instanceof IMolecule) {}
113+
]]>
114+
</example>
115+
</rule>
116+
117+
<rule name="InstanceOfAtom"
118+
language="java"
119+
message="Use instanceof against interfaces not implementations"
120+
class="net.sourceforge.pmd.rules.XPathRule">
121+
<description>
122+
Programming against the CDK interfaces allows users to pick their favorite
123+
implementation (nonotify, datadebug).
124+
</description>
125+
<priority>1</priority>
126+
<properties>
127+
<property name="xpath">
128+
<value>
129+
<![CDATA[
130+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='Atom']
131+
]]>
132+
</value>
133+
</property>
134+
</properties>
135+
<example>
136+
<![CDATA[
137+
if (atomContainer instanceof Atom) {}
138+
// use instead:
139+
// if (atomContainer instanceof IAtom) {}
140+
]]>
141+
</example>
142+
</rule>
143+
144+
<rule name="InstanceOfPseudoAtom"
145+
language="java"
146+
message="Use instanceof against interfaces not implementations"
147+
class="net.sourceforge.pmd.rules.XPathRule">
148+
<description>
149+
Programming against the CDK interfaces allows users to pick their favorite
150+
implementation (nonotify, datadebug).
151+
</description>
152+
<priority>1</priority>
153+
<properties>
154+
<property name="xpath">
155+
<value>
156+
<![CDATA[
157+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='PseudoAtom']
158+
]]>
159+
</value>
160+
</property>
161+
</properties>
162+
<example>
163+
<![CDATA[
164+
if (atomContainer instanceof PseudoAtom) {}
165+
// use instead:
166+
// if (atomContainer instanceof IPseudoAtom) {}
167+
]]>
168+
</example>
169+
</rule>
170+
171+
<rule name="InstanceOfBond"
172+
language="java"
173+
message="Use instanceof against interfaces not implementations"
174+
class="net.sourceforge.pmd.rules.XPathRule">
175+
<description>
176+
Programming against the CDK interfaces allows users to pick their favorite
177+
implementation (nonotify, datadebug).
178+
</description>
179+
<priority>1</priority>
180+
<properties>
181+
<property name="xpath">
182+
<value>
183+
<![CDATA[
184+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='Bond']
185+
]]>
186+
</value>
187+
</property>
188+
</properties>
189+
<example>
190+
<![CDATA[
191+
if (atomContainer instanceof Bond) {}
192+
// use instead:
193+
// if (atomContainer instanceof IBond) {}
194+
]]>
195+
</example>
196+
</rule>
197+
198+
<rule name="InstanceOfLonePair"
199+
language="java"
200+
message="Use instanceof against interfaces not implementations"
201+
class="net.sourceforge.pmd.rules.XPathRule">
202+
<description>
203+
Programming against the CDK interfaces allows users to pick their favorite
204+
implementation (nonotify, datadebug).
205+
</description>
206+
<priority>1</priority>
207+
<properties>
208+
<property name="xpath">
209+
<value>
210+
<![CDATA[
211+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='LonePair']
212+
]]>
213+
</value>
214+
</property>
215+
</properties>
216+
<example>
217+
<![CDATA[
218+
if (atomContainer instanceof LonePair) {}
219+
// use instead:
220+
// if (atomContainer instanceof ILonePair) {}
221+
]]>
222+
</example>
223+
</rule>
224+
225+
<rule name="InstanceOfSingleElectron"
226+
language="java"
227+
message="Use instanceof against interfaces not implementations"
228+
class="net.sourceforge.pmd.rules.XPathRule">
229+
<description>
230+
Programming against the CDK interfaces allows users to pick their favorite
231+
implementation (nonotify, datadebug).
232+
</description>
233+
<priority>1</priority>
234+
<properties>
235+
<property name="xpath">
236+
<value>
237+
<![CDATA[
238+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='SingleElectron']
239+
]]>
240+
</value>
241+
</property>
242+
</properties>
243+
<example>
244+
<![CDATA[
245+
if (atomContainer instanceof SingleElectron) {}
246+
// use instead:
247+
// if (atomContainer instanceof ISingleElectron) {}
248+
]]>
249+
</example>
250+
</rule>
251+
252+
<rule name="InstanceOfIsotope"
253+
language="java"
254+
message="Use instanceof against interfaces not implementations"
255+
class="net.sourceforge.pmd.rules.XPathRule">
256+
<description>
257+
Programming against the CDK interfaces allows users to pick their favorite
258+
implementation (nonotify, datadebug).
259+
</description>
260+
<priority>1</priority>
261+
<properties>
262+
<property name="xpath">
263+
<value>
264+
<![CDATA[
265+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='Isotope']
266+
]]>
267+
</value>
268+
</property>
269+
</properties>
270+
<example>
271+
<![CDATA[
272+
if (atomContainer instanceof Isotope) {}
273+
// use instead:
274+
// if (atomContainer instanceof IIsotope) {}
275+
]]>
276+
</example>
277+
</rule>
278+
279+
<rule name="InstanceOfAtomType"
280+
language="java"
281+
message="Use instanceof against interfaces not implementations"
282+
class="net.sourceforge.pmd.rules.XPathRule">
283+
<description>
284+
Programming against the CDK interfaces allows users to pick their favorite
285+
implementation (nonotify, datadebug).
286+
</description>
287+
<priority>1</priority>
288+
<properties>
289+
<property name="xpath">
290+
<value>
291+
<![CDATA[
292+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='AtomType']
293+
]]>
294+
</value>
295+
</property>
296+
</properties>
297+
<example>
298+
<![CDATA[
299+
if (atomContainer instanceof AtomType) {}
300+
// use instead:
301+
// if (atomContainer instanceof IAtomType) {}
302+
]]>
303+
</example>
304+
</rule>
305+
306+
<rule name="InstanceOfElement"
307+
language="java"
308+
message="Use instanceof against interfaces not implementations"
309+
class="net.sourceforge.pmd.rules.XPathRule">
310+
<description>
311+
Programming against the CDK interfaces allows users to pick their favorite
312+
implementation (nonotify, datadebug).
313+
</description>
314+
<priority>1</priority>
315+
<properties>
316+
<property name="xpath">
317+
<value>
318+
<![CDATA[
319+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='Element']
320+
]]>
321+
</value>
322+
</property>
323+
</properties>
324+
<example>
325+
<![CDATA[
326+
if (atomContainer instanceof Element) {}
327+
// use instead:
328+
// if (atomContainer instanceof IElement) {}
329+
]]>
330+
</example>
331+
</rule>
332+
333+
<rule name="InstanceOfAtomContainer"
334+
language="java"
335+
message="Use instanceof against interfaces not implementations"
336+
class="net.sourceforge.pmd.rules.XPathRule">
337+
<description>
338+
Programming against the CDK interfaces allows users to pick their favorite
339+
implementation (nonotify, datadebug).
340+
</description>
341+
<priority>1</priority>
342+
<properties>
343+
<property name="xpath">
344+
<value>
345+
<![CDATA[
346+
//InstanceOfExpression/Type/ReferenceType/ClassOrInterfaceType[@Image='AtomContainer']
347+
]]>
348+
</value>
349+
</property>
350+
</properties>
351+
<example>
352+
<![CDATA[
353+
if (atomContainer instanceof AtomContainer) {}
354+
// use instead:
355+
// if (atomContainer instanceof IAtomContainer) {}
356+
]]>
357+
</example>
358+
</rule>
359+
360+
</ruleset>

pmd/custom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727

2828
<rule ref="pmd/customCDK.xml"/>
2929
<rule ref="pmd/customOptimization.xml"/>
30+
<rule ref="pmd/cdkinterfaces.xml"/>
3031

3132
</ruleset>

0 commit comments

Comments
 (0)