|
20 | 20 | language="java" |
21 | 21 | since="6.5.0" |
22 | 22 | 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"> |
24 | 24 | <description> |
25 | 25 | Injected FXML fields should be suffixed by their type |
26 | 26 | </description> |
|
40 | 40 | ]]></value> |
41 | 41 | </property> |
42 | 42 | </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> |
43 | 50 | </rule> |
44 | 51 |
|
45 | 52 | <!-- FIXME this doesn't work because "fxml" is not part of the patterns for the XML language... --> |
46 | 53 | <rule name="FxmlApiVersion" |
47 | 54 | language="xml" |
48 | 55 | since="6.5.0" |
49 | 56 | 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"> |
51 | 58 | <description> |
52 | 59 | FXML docs for this project should specify an API version of 8. |
53 | 60 | </description> |
|
67 | 74 | language="java" |
68 | 75 | since="6.5.0" |
69 | 76 | 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"> |
71 | 78 | <description> |
72 | 79 | Injected FXML fields should be suffixed by their type |
73 | 80 | </description> |
|
76 | 83 | <property name="xpath"> |
77 | 84 | <value><![CDATA[ |
78 | 85 | //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))] |
81 | 88 | (: 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'))] |
90 | 98 | (: This last clause allows variables to be named the same as their type, modulo Camel case :) |
91 | 99 | (: Ideally we would only allow this for our custom types, but there's currently no easy :) |
92 | 100 | (: way to get the type name of a node to check the package. :) |
93 | 101 | (: 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))] |
96 | 104 | ]]></value> |
97 | 105 | </property> |
98 | 106 | </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> |
99 | 125 | </rule> |
100 | 126 |
|
101 | 127 | </ruleset> |
0 commit comments