Skip to content

Commit 7cb3721

Browse files
committed
Fix PMD UnnecessaryFullyQualifiedName issues
1 parent cb25153 commit 7cb3721

4 files changed

Lines changed: 34 additions & 48 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<action type="fix" issue="CLI-331" dev="ggregory" due-to="Claude Warren, Gary Gregory">Handle reporting of deprecated options when parameters are not String type. #270.</action>
3131
<action type="fix" dev="ggregory" due-to="Claude Warren, Gary Gregory">Avoid throwing NullPointerException when calling CommandLineParser will null array elements.</action>
3232
<action type="fix" dev="ggregory" due-to="Claude Warren">Cleanup deprecation issues #272.</action>
33+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix PMD UnnecessaryFullyQualifiedName issues.</action>
3334
<!-- UPDATE -->
3435
</release>
3536
<release version="1.7.0" date="2024-04-13" description="This release contains new features and bug fixes and requires Java 8 or above.">

src/main/java/org/apache/commons/cli/Option.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public Builder hasArg() {
199199
*/
200200
public Builder hasArg(final boolean hasArg) {
201201
// set to UNINITIALIZED when no arg is specified to be compatible with OptionBuilder
202-
argCount = hasArg ? 1 : Option.UNINITIALIZED;
202+
argCount = hasArg ? 1 : UNINITIALIZED;
203203
return this;
204204
}
205205

@@ -209,7 +209,7 @@ public Builder hasArg(final boolean hasArg) {
209209
* @return this builder.
210210
*/
211211
public Builder hasArgs() {
212-
argCount = Option.UNLIMITED_VALUES;
212+
argCount = UNLIMITED_VALUES;
213213
return this;
214214
}
215215

src/main/java/org/apache/commons/cli/OptionBuilder.java

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3131
@Deprecated
3232
public final class OptionBuilder {
3333

34-
3534
/** Long option */
3635
private static String longOption;
3736

@@ -72,7 +71,7 @@ public final class OptionBuilder {
7271
*/
7372
public static Option create() throws IllegalArgumentException {
7473
if (longOption == null) {
75-
OptionBuilder.reset();
74+
reset();
7675
throw new IllegalArgumentException("must specify longopt");
7776
}
7877

@@ -114,7 +113,7 @@ public static Option create(final String opt) throws IllegalArgumentException {
114113
option.setArgName(argName);
115114
} finally {
116115
// reset the OptionBuilder properties
117-
OptionBuilder.reset();
116+
reset();
118117
}
119118

120119
// return the Option instance
@@ -127,8 +126,7 @@ public static Option create(final String opt) throws IllegalArgumentException {
127126
* @return the OptionBuilder instance
128127
*/
129128
public static OptionBuilder hasArg() {
130-
OptionBuilder.argCount = 1;
131-
129+
argCount = 1;
132130
return INSTANCE;
133131
}
134132

@@ -139,8 +137,7 @@ public static OptionBuilder hasArg() {
139137
* @return the OptionBuilder instance
140138
*/
141139
public static OptionBuilder hasArg(final boolean hasArg) {
142-
OptionBuilder.argCount = hasArg ? 1 : Option.UNINITIALIZED;
143-
140+
argCount = hasArg ? 1 : Option.UNINITIALIZED;
144141
return INSTANCE;
145142
}
146143

@@ -150,8 +147,7 @@ public static OptionBuilder hasArg(final boolean hasArg) {
150147
* @return the OptionBuilder instance
151148
*/
152149
public static OptionBuilder hasArgs() {
153-
OptionBuilder.argCount = Option.UNLIMITED_VALUES;
154-
150+
argCount = Option.UNLIMITED_VALUES;
155151
return INSTANCE;
156152
}
157153

@@ -162,8 +158,7 @@ public static OptionBuilder hasArgs() {
162158
* @return the OptionBuilder instance
163159
*/
164160
public static OptionBuilder hasArgs(final int num) {
165-
OptionBuilder.argCount = num;
166-
161+
argCount = num;
167162
return INSTANCE;
168163
}
169164

@@ -173,9 +168,8 @@ public static OptionBuilder hasArgs(final int num) {
173168
* @return the OptionBuilder instance
174169
*/
175170
public static OptionBuilder hasOptionalArg() {
176-
OptionBuilder.argCount = 1;
177-
OptionBuilder.optionalArg = true;
178-
171+
argCount = 1;
172+
optionalArg = true;
179173
return INSTANCE;
180174
}
181175

@@ -185,9 +179,8 @@ public static OptionBuilder hasOptionalArg() {
185179
* @return the OptionBuilder instance
186180
*/
187181
public static OptionBuilder hasOptionalArgs() {
188-
OptionBuilder.argCount = Option.UNLIMITED_VALUES;
189-
OptionBuilder.optionalArg = true;
190-
182+
argCount = Option.UNLIMITED_VALUES;
183+
optionalArg = true;
191184
return INSTANCE;
192185
}
193186

@@ -198,9 +191,8 @@ public static OptionBuilder hasOptionalArgs() {
198191
* @return the OptionBuilder instance
199192
*/
200193
public static OptionBuilder hasOptionalArgs(final int numArgs) {
201-
OptionBuilder.argCount = numArgs;
202-
OptionBuilder.optionalArg = true;
203-
194+
argCount = numArgs;
195+
optionalArg = true;
204196
return INSTANCE;
205197
}
206198

@@ -210,8 +202,7 @@ public static OptionBuilder hasOptionalArgs(final int numArgs) {
210202
* @return the OptionBuilder instance
211203
*/
212204
public static OptionBuilder isRequired() {
213-
OptionBuilder.required = true;
214-
205+
required = true;
215206
return INSTANCE;
216207
}
217208

@@ -222,8 +213,7 @@ public static OptionBuilder isRequired() {
222213
* @return the OptionBuilder instance
223214
*/
224215
public static OptionBuilder isRequired(final boolean newRequired) {
225-
OptionBuilder.required = newRequired;
226-
216+
required = newRequired;
227217
return INSTANCE;
228218
}
229219

@@ -248,8 +238,7 @@ private static void reset() {
248238
* @return the OptionBuilder instance
249239
*/
250240
public static OptionBuilder withArgName(final String name) {
251-
OptionBuilder.argName = name;
252-
241+
argName = name;
253242
return INSTANCE;
254243
}
255244

@@ -260,8 +249,7 @@ public static OptionBuilder withArgName(final String name) {
260249
* @return the OptionBuilder instance
261250
*/
262251
public static OptionBuilder withDescription(final String newDescription) {
263-
OptionBuilder.description = newDescription;
264-
252+
description = newDescription;
265253
return INSTANCE;
266254
}
267255

@@ -272,8 +260,7 @@ public static OptionBuilder withDescription(final String newDescription) {
272260
* @return the OptionBuilder instance
273261
*/
274262
public static OptionBuilder withLongOpt(final String newLongopt) {
275-
OptionBuilder.longOption = newLongopt;
276-
263+
longOption = newLongopt;
277264
return INSTANCE;
278265
}
279266

@@ -285,8 +272,7 @@ public static OptionBuilder withLongOpt(final String newLongopt) {
285272
* @since 1.3
286273
*/
287274
public static OptionBuilder withType(final Class<?> newType) {
288-
OptionBuilder.type = newType;
289-
275+
type = newType;
290276
return INSTANCE;
291277
}
292278

@@ -311,7 +297,7 @@ public static OptionBuilder withType(final Object newType) {
311297
* <b>Example:</b>
312298
*
313299
* <pre>
314-
* Option opt = OptionBuilder.withValueSeparator().create('D');
300+
* Option opt = withValueSeparator().create('D');
315301
*
316302
* CommandLine line = parser.parse(args);
317303
* String propertyName = opt.getValue(0);
@@ -321,8 +307,7 @@ public static OptionBuilder withType(final Object newType) {
321307
* @return the OptionBuilder instance
322308
*/
323309
public static OptionBuilder withValueSeparator() {
324-
OptionBuilder.valueSeparator = Char.EQUAL;
325-
310+
valueSeparator = Char.EQUAL;
326311
return INSTANCE;
327312
}
328313

@@ -345,8 +330,7 @@ public static OptionBuilder withValueSeparator() {
345330
* @return the OptionBuilder instance
346331
*/
347332
public static OptionBuilder withValueSeparator(final char sep) {
348-
OptionBuilder.valueSeparator = sep;
349-
333+
valueSeparator = sep;
350334
return INSTANCE;
351335
}
352336

src/main/java/org/apache/commons/cli/PatternOptionBuilder.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
7373
* </p>
7474
*/
7575
public class PatternOptionBuilder {
76+
7677
/** String class */
7778
public static final Class<String> STRING_VALUE = String.class;
7879

@@ -131,23 +132,23 @@ public static Object getValueClass(final char ch) {
131132
public static Class<?> getValueType(final char ch) {
132133
switch (ch) {
133134
case '@':
134-
return PatternOptionBuilder.OBJECT_VALUE;
135+
return OBJECT_VALUE;
135136
case ':':
136-
return PatternOptionBuilder.STRING_VALUE;
137+
return STRING_VALUE;
137138
case '%':
138-
return PatternOptionBuilder.NUMBER_VALUE;
139+
return NUMBER_VALUE;
139140
case '+':
140-
return PatternOptionBuilder.CLASS_VALUE;
141+
return CLASS_VALUE;
141142
case '#':
142-
return PatternOptionBuilder.DATE_VALUE;
143+
return DATE_VALUE;
143144
case '<':
144-
return PatternOptionBuilder.EXISTING_FILE_VALUE;
145+
return EXISTING_FILE_VALUE;
145146
case '>':
146-
return PatternOptionBuilder.FILE_VALUE;
147+
return FILE_VALUE;
147148
case '*':
148-
return PatternOptionBuilder.FILES_VALUE;
149+
return FILES_VALUE;
149150
case '/':
150-
return PatternOptionBuilder.URL_VALUE;
151+
return URL_VALUE;
151152
}
152153

153154
return null;

0 commit comments

Comments
 (0)