Skip to content

Commit 99f9b17

Browse files
committed
Update custom pmd rules for PMD 7
1 parent 804fc90 commit 99f9b17

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

config/pmd-check.xml

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
language="java"
2121
since="6.5.0"
2222
message="This module should not use pmd-core''s internal API"
23-
class="net.sourceforge.pmd.lang.rule.XPathRule">
23+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
2424
<description>
2525
Injected FXML fields should be suffixed by their type
2626
</description>
@@ -40,14 +40,21 @@
4040
]]></value>
4141
</property>
4242
</properties>
43+
<example><![CDATA[
44+
import net.sourceforge.pmd.lang.InternalApiBridge; // violation
45+
import net.sourceforge.pmd.lang.ast.internal.StreamImpl; // violation
46+
import net.sourceforge.pmd.lang.ast.Node; // ok
47+
48+
public class Foo {}
49+
]]></example>
4350
</rule>
4451

4552
<!-- FIXME this doesn't work because "fxml" is not part of the patterns for the XML language... -->
4653
<rule name="FxmlApiVersion"
4754
language="xml"
4855
since="6.5.0"
4956
message='FXML docs for this project should specify an API version of 8: xmlns="http://javafx.com/javafx/8"'
50-
class="net.sourceforge.pmd.lang.rule.XPathRule">
57+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
5158
<description>
5259
FXML docs for this project should specify an API version of 8.
5360
</description>
@@ -67,7 +74,7 @@
6774
language="java"
6875
since="6.5.0"
6976
message="Injected FXML fields should be suffixed by their type, eg ''HelloButton'', here it''s ''{0}''"
70-
class="net.sourceforge.pmd.lang.rule.XPathRule">
77+
class="net.sourceforge.pmd.lang.rule.xpath.XPathRule">
7178
<description>
7279
Injected FXML fields should be suffixed by their type
7380
</description>
@@ -76,26 +83,45 @@
7683
<property name="xpath">
7784
<value><![CDATA[
7885
//FieldDeclaration[ModifierList/Annotation[pmd-java:typeIs('javafx.fxml.FXML')]]
79-
/VariableDeclarator/VariableDeclaratorId
80-
[not(ends-with(@Name, ../../ClassOrInterfaceType/@SimpleName))]
86+
/VariableDeclarator/VariableId
87+
[not(ends-with(@Name, ../../ClassType/@SimpleName))]
8188
(: The following are the exceptions to the rule :)
82-
[not(ends-with(@Name, 'Controller') and ends-with(../../ClassOrInterfaceType/@SimpleName, 'Controller'))]
83-
[not(../../ClassOrInterfaceType/@SimpleName = 'TextField' and ends-with(@Name, 'Field'))]
84-
[not(../../ClassOrInterfaceType/@SimpleName = 'ToggleButton' and ends-with(@Name, 'Toggle'))]
85-
[not(../../ClassOrInterfaceType/@SimpleName = 'TextArea' or ends-with(../../ClassOrInterfaceType/@SimpleName, 'CodeArea') and ends-with(@Name, 'Area'))]
86-
[not(../../ClassOrInterfaceType/@SimpleName = 'TableColumn' and ends-with(@Name, 'Column'))]
87-
[not(../../ClassOrInterfaceType/@SimpleName = 'MenuItem' and ends-with(@Name, 'Button'))]
88-
[not(ends-with(../../ClassOrInterfaceType/@SimpleName, 'Choicebox') and ends-with(@Name, 'Choicebox'))]
89-
[not(ends-with(../../ClassOrInterfaceType/@SimpleName, 'TitledPane') and ends-with(@Name, 'Pane'))]
89+
[not(ends-with(@Name, 'Controller') and ends-with(../../ClassType/@SimpleName, 'Controller'))]
90+
[not(../../ClassType/@SimpleName = 'TextField' and ends-with(@Name, 'Field'))]
91+
[not(../../ClassType/@SimpleName = 'ToggleButton' and ends-with(@Name, 'Toggle'))]
92+
[not(../../ClassType/@SimpleName = 'TextArea' or ends-with(../../ClassOrInterfaceType/@SimpleName, 'CodeArea') and ends-with(@Name, 'Area'))]
93+
[not(../../ClassType/@SimpleName = 'TableColumn' and ends-with(@Name, 'Column'))]
94+
[not(../../ClassType/@SimpleName = 'MenuItem' and ends-with(@Name, 'Button'))]
95+
[not(../../ClassType/@SimpleName = 'SyntaxHighlightingCodeArea' and ends-with(@Name, 'Area'))]
96+
[not(ends-with(../../ClassType/@SimpleName, 'Choicebox') and ends-with(@Name, 'Choicebox'))]
97+
[not(ends-with(../../ClassType/@SimpleName, 'TitledPane') and ends-with(@Name, 'Pane'))]
9098
(: This last clause allows variables to be named the same as their type, modulo Camel case :)
9199
(: Ideally we would only allow this for our custom types, but there's currently no easy :)
92100
(: way to get the type name of a node to check the package. :)
93101
(: We should create a function for that, eg typeNameOf :)
94-
[not(string-length(../../ClassOrInterfaceType/@SimpleName) = string-length(@Name)
95-
and substring(../../ClassOrInterfaceType/@SimpleName, 2) = substring(@Name, 2))]
102+
[not(string-length(../../ClassType/@SimpleName) = string-length(@Name)
103+
and substring(../../ClassType/@SimpleName, 2) = substring(@Name, 2))]
96104
]]></value>
97105
</property>
98106
</properties>
107+
<example><![CDATA[
108+
import javafx.fxml.FXML;
109+
import javafx.scene.control.MenuItem;
110+
111+
public class MyController {
112+
@FXML
113+
private MenuItem about; // violation
114+
115+
@FXML
116+
private MenuItem aboutMenuItem; // ok
117+
118+
@FXML
119+
private TextField nameField; // ok, exception
120+
121+
@FXML
122+
private MenuItem aboutButton; // ok, exception
123+
}
124+
]]></example>
99125
</rule>
100126

101127
</ruleset>

0 commit comments

Comments
 (0)