15
15
import java .util .List ;
16
16
import javax .swing .JOptionPane ;
17
17
18
- @ SuppressWarnings ({"PMD.OnlyOneReturn" })
18
+ @ SuppressWarnings ({"PMD.OnlyOneReturn" , "PMD.FieldNamingConventions" })
19
19
public class CreateAPluginDialogValidator {
20
+ private static final String NOT_EMPTY = "validator.notEmpty" ;
21
+ private static final String PLUGIN_CLASS_NAME = "Plugin Class Name" ;
20
22
private static CreateAPluginDialogValidator INSTANCE = null ;
21
- private ValidatorBundle validatorBundle ;
22
- private CommonBundle commonBundle ;
23
+ private final ValidatorBundle validatorBundle ;
24
+ private final CommonBundle commonBundle ;
23
25
private CreateAPluginDialog dialog ;
24
26
25
27
/**
@@ -41,7 +43,7 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
41
43
/**
42
44
* Create a plugin dialog validator.
43
45
*/
44
- public CreateAPluginDialogValidator () {
46
+ private CreateAPluginDialogValidator () {
45
47
this .validatorBundle = new ValidatorBundle ();
46
48
this .commonBundle = new CommonBundle ();
47
49
}
@@ -53,14 +55,14 @@ public CreateAPluginDialogValidator() {
53
55
*
54
56
* @return Boolean
55
57
*/
56
- public boolean validate (Project project ) {
57
- String errorTitle = commonBundle .message ("common.error" );
58
- String pluginClassName = dialog .getPluginClassName ();
58
+ public boolean validate (final Project project ) {
59
+ final String errorTitle = commonBundle .message ("common.error" );
60
+ final String pluginClassName = dialog .getPluginClassName ();
59
61
60
62
if (!PhpNameUtil .isValidClassName (pluginClassName )) {
61
- String errorMessage = this .validatorBundle .message (
63
+ final String errorMessage = this .validatorBundle .message (
62
64
"validator.class.isNotValid" ,
63
- "Plugin Class Name"
65
+ PLUGIN_CLASS_NAME
64
66
);
65
67
JOptionPane .showMessageDialog (
66
68
null ,
@@ -73,9 +75,9 @@ public boolean validate(Project project) {
73
75
}
74
76
75
77
if (pluginClassName .length () == 0 ) {
76
- String errorMessage = validatorBundle .message (
77
- "validator.notEmpty" ,
78
- "Plugin Class Name"
78
+ final String errorMessage = validatorBundle .message (
79
+ NOT_EMPTY ,
80
+ PLUGIN_CLASS_NAME
79
81
);
80
82
JOptionPane .showMessageDialog (
81
83
null ,
@@ -88,9 +90,9 @@ public boolean validate(Project project) {
88
90
}
89
91
90
92
if (!pluginClassName .matches (RegExUtil .ALPHANUMERIC )) {
91
- String errorMessage = validatorBundle .message (
93
+ final String errorMessage = validatorBundle .message (
92
94
"validator.alphaNumericCharacters" ,
93
- "Plugin Class Name"
95
+ PLUGIN_CLASS_NAME
94
96
);
95
97
JOptionPane .showMessageDialog (
96
98
null ,
@@ -105,9 +107,9 @@ public boolean validate(Project project) {
105
107
if (!Character .isUpperCase (pluginClassName .charAt (0 ))
106
108
&& !Character .isDigit (pluginClassName .charAt (0 ))
107
109
) {
108
- String errorMessage = validatorBundle .message (
110
+ final String errorMessage = validatorBundle .message (
109
111
"validator.startWithNumberOrCapitalLetter" ,
110
- "Plugin Class Name"
112
+ PLUGIN_CLASS_NAME
111
113
);
112
114
JOptionPane .showMessageDialog (
113
115
null ,
@@ -119,10 +121,10 @@ public boolean validate(Project project) {
119
121
return false ;
120
122
}
121
123
122
- String pluginDirectory = dialog .getPluginDirectory ();
124
+ final String pluginDirectory = dialog .getPluginDirectory ();
123
125
if (pluginDirectory .length () == 0 ) {
124
- String errorMessage = validatorBundle .message (
125
- "validator.notEmpty" ,
126
+ final String errorMessage = validatorBundle .message (
127
+ NOT_EMPTY ,
126
128
"Plugin Directory"
127
129
);
128
130
JOptionPane .showMessageDialog (
@@ -136,7 +138,7 @@ public boolean validate(Project project) {
136
138
}
137
139
138
140
if (!pluginDirectory .matches (RegExUtil .DIRECTORY )) {
139
- String errorMessage = validatorBundle .message (
141
+ final String errorMessage = validatorBundle .message (
140
142
"validator.directory.isNotValid" ,
141
143
"Plugin Directory"
142
144
);
@@ -150,10 +152,10 @@ public boolean validate(Project project) {
150
152
return false ;
151
153
}
152
154
153
- String pluginName = dialog .getPluginName ();
155
+ final String pluginName = dialog .getPluginName ();
154
156
if (pluginName .length () == 0 ) {
155
- String errorMessage = validatorBundle .message (
156
- "validator.notEmpty" ,
157
+ final String errorMessage = validatorBundle .message (
158
+ NOT_EMPTY ,
157
159
"Plugin Name"
158
160
);
159
161
JOptionPane .showMessageDialog (
@@ -167,7 +169,7 @@ public boolean validate(Project project) {
167
169
}
168
170
169
171
if (!pluginName .matches (RegExUtil .IDENTIFIER )) {
170
- String errorMessage = validatorBundle .message (
172
+ final String errorMessage = validatorBundle .message (
171
173
"validator.identifier" ,
172
174
"Plugin Name"
173
175
);
@@ -181,10 +183,10 @@ public boolean validate(Project project) {
181
183
return false ;
182
184
}
183
185
184
- String sortOrder = dialog .getPluginSortOrder ();
186
+ final String sortOrder = dialog .getPluginSortOrder ();
185
187
if (sortOrder .length () == 0 ) {
186
- String errorMessage = validatorBundle .message (
187
- "validator.notEmpty" ,
188
+ final String errorMessage = validatorBundle .message (
189
+ NOT_EMPTY ,
188
190
"Sort Order"
189
191
);
190
192
JOptionPane .showMessageDialog (
@@ -198,7 +200,7 @@ public boolean validate(Project project) {
198
200
}
199
201
200
202
if (!sortOrder .matches (RegExUtil .NUMERIC )) {
201
- String errorMessage = validatorBundle .message (
203
+ final String errorMessage = validatorBundle .message (
202
204
"validator.onlyNumbers" ,
203
205
"Sort Order"
204
206
);
@@ -212,10 +214,10 @@ public boolean validate(Project project) {
212
214
return false ;
213
215
}
214
216
215
- String pluginModule = dialog .getPluginModule ();
217
+ final String pluginModule = dialog .getPluginModule ();
216
218
if (pluginModule .length () == 0 ) {
217
- String errorMessage = validatorBundle .message (
218
- "validator.notEmpty" ,
219
+ final String errorMessage = validatorBundle .message (
220
+ NOT_EMPTY ,
219
221
"Plugin Module"
220
222
);
221
223
JOptionPane .showMessageDialog (
@@ -228,9 +230,9 @@ public boolean validate(Project project) {
228
230
return false ;
229
231
}
230
232
231
- List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
233
+ final List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
232
234
if (!allModulesList .contains (pluginModule )) {
233
- String errorMessage = validatorBundle .message (
235
+ final String errorMessage = validatorBundle .message (
234
236
"validator.module.noSuchModule" ,
235
237
pluginModule
236
238
);
0 commit comments