1515import java .util .List ;
1616import javax .swing .JOptionPane ;
1717
18- @ SuppressWarnings ({"PMD.OnlyOneReturn" })
18+ @ SuppressWarnings ({"PMD.OnlyOneReturn" , "PMD.FieldNamingConventions" })
1919public class CreateAPluginDialogValidator {
20+ private static final String NOT_EMPTY = "validator.notEmpty" ;
21+ private static final String PLUGIN_CLASS_NAME = "Plugin Class Name" ;
2022 private static CreateAPluginDialogValidator INSTANCE = null ;
21- private ValidatorBundle validatorBundle ;
22- private CommonBundle commonBundle ;
23+ private final ValidatorBundle validatorBundle ;
24+ private final CommonBundle commonBundle ;
2325 private CreateAPluginDialog dialog ;
2426
2527 /**
@@ -41,7 +43,7 @@ public static CreateAPluginDialogValidator getInstance(CreateAPluginDialog dialo
4143 /**
4244 * Create a plugin dialog validator.
4345 */
44- public CreateAPluginDialogValidator () {
46+ private CreateAPluginDialogValidator () {
4547 this .validatorBundle = new ValidatorBundle ();
4648 this .commonBundle = new CommonBundle ();
4749 }
@@ -53,14 +55,14 @@ public CreateAPluginDialogValidator() {
5355 *
5456 * @return Boolean
5557 */
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 ();
5961
6062 if (!PhpNameUtil .isValidClassName (pluginClassName )) {
61- String errorMessage = this .validatorBundle .message (
63+ final String errorMessage = this .validatorBundle .message (
6264 "validator.class.isNotValid" ,
63- "Plugin Class Name"
65+ PLUGIN_CLASS_NAME
6466 );
6567 JOptionPane .showMessageDialog (
6668 null ,
@@ -73,9 +75,9 @@ public boolean validate(Project project) {
7375 }
7476
7577 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
7981 );
8082 JOptionPane .showMessageDialog (
8183 null ,
@@ -88,9 +90,9 @@ public boolean validate(Project project) {
8890 }
8991
9092 if (!pluginClassName .matches (RegExUtil .ALPHANUMERIC )) {
91- String errorMessage = validatorBundle .message (
93+ final String errorMessage = validatorBundle .message (
9294 "validator.alphaNumericCharacters" ,
93- "Plugin Class Name"
95+ PLUGIN_CLASS_NAME
9496 );
9597 JOptionPane .showMessageDialog (
9698 null ,
@@ -105,9 +107,9 @@ public boolean validate(Project project) {
105107 if (!Character .isUpperCase (pluginClassName .charAt (0 ))
106108 && !Character .isDigit (pluginClassName .charAt (0 ))
107109 ) {
108- String errorMessage = validatorBundle .message (
110+ final String errorMessage = validatorBundle .message (
109111 "validator.startWithNumberOrCapitalLetter" ,
110- "Plugin Class Name"
112+ PLUGIN_CLASS_NAME
111113 );
112114 JOptionPane .showMessageDialog (
113115 null ,
@@ -119,10 +121,10 @@ public boolean validate(Project project) {
119121 return false ;
120122 }
121123
122- String pluginDirectory = dialog .getPluginDirectory ();
124+ final String pluginDirectory = dialog .getPluginDirectory ();
123125 if (pluginDirectory .length () == 0 ) {
124- String errorMessage = validatorBundle .message (
125- "validator.notEmpty" ,
126+ final String errorMessage = validatorBundle .message (
127+ NOT_EMPTY ,
126128 "Plugin Directory"
127129 );
128130 JOptionPane .showMessageDialog (
@@ -136,7 +138,7 @@ public boolean validate(Project project) {
136138 }
137139
138140 if (!pluginDirectory .matches (RegExUtil .DIRECTORY )) {
139- String errorMessage = validatorBundle .message (
141+ final String errorMessage = validatorBundle .message (
140142 "validator.directory.isNotValid" ,
141143 "Plugin Directory"
142144 );
@@ -150,10 +152,10 @@ public boolean validate(Project project) {
150152 return false ;
151153 }
152154
153- String pluginName = dialog .getPluginName ();
155+ final String pluginName = dialog .getPluginName ();
154156 if (pluginName .length () == 0 ) {
155- String errorMessage = validatorBundle .message (
156- "validator.notEmpty" ,
157+ final String errorMessage = validatorBundle .message (
158+ NOT_EMPTY ,
157159 "Plugin Name"
158160 );
159161 JOptionPane .showMessageDialog (
@@ -167,7 +169,7 @@ public boolean validate(Project project) {
167169 }
168170
169171 if (!pluginName .matches (RegExUtil .IDENTIFIER )) {
170- String errorMessage = validatorBundle .message (
172+ final String errorMessage = validatorBundle .message (
171173 "validator.identifier" ,
172174 "Plugin Name"
173175 );
@@ -181,10 +183,10 @@ public boolean validate(Project project) {
181183 return false ;
182184 }
183185
184- String sortOrder = dialog .getPluginSortOrder ();
186+ final String sortOrder = dialog .getPluginSortOrder ();
185187 if (sortOrder .length () == 0 ) {
186- String errorMessage = validatorBundle .message (
187- "validator.notEmpty" ,
188+ final String errorMessage = validatorBundle .message (
189+ NOT_EMPTY ,
188190 "Sort Order"
189191 );
190192 JOptionPane .showMessageDialog (
@@ -198,7 +200,7 @@ public boolean validate(Project project) {
198200 }
199201
200202 if (!sortOrder .matches (RegExUtil .NUMERIC )) {
201- String errorMessage = validatorBundle .message (
203+ final String errorMessage = validatorBundle .message (
202204 "validator.onlyNumbers" ,
203205 "Sort Order"
204206 );
@@ -212,10 +214,10 @@ public boolean validate(Project project) {
212214 return false ;
213215 }
214216
215- String pluginModule = dialog .getPluginModule ();
217+ final String pluginModule = dialog .getPluginModule ();
216218 if (pluginModule .length () == 0 ) {
217- String errorMessage = validatorBundle .message (
218- "validator.notEmpty" ,
219+ final String errorMessage = validatorBundle .message (
220+ NOT_EMPTY ,
219221 "Plugin Module"
220222 );
221223 JOptionPane .showMessageDialog (
@@ -228,9 +230,9 @@ public boolean validate(Project project) {
228230 return false ;
229231 }
230232
231- List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
233+ final List <String > allModulesList = ModuleIndex .getInstance (project ).getEditableModuleNames ();
232234 if (!allModulesList .contains (pluginModule )) {
233- String errorMessage = validatorBundle .message (
235+ final String errorMessage = validatorBundle .message (
234236 "validator.module.noSuchModule" ,
235237 pluginModule
236238 );
0 commit comments