- Timestamp:
- 2018-11-20T01:51:27+01:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/ProjectionCLI.java
r14415 r14435 29 29 public class ProjectionCLI implements CLIModule { 30 30 31 /** The unique instance **/ 31 32 public static final ProjectionCLI INSTANCE = new ProjectionCLI(); 32 33 … … 43 44 public void processArguments(String[] argArray) { 44 45 List<String> positionalArguments = new OptionParser("JOSM projection") 45 .addFlagParameter("help", this::showHelp)46 .addFlagParameter("help", ProjectionCLI::showHelp) 46 47 .addShortAlias("help", "h") 47 48 .addFlagParameter("inverse", () -> argInverse = true) … … 84 85 * Displays help on the console 85 86 */ 86 private void showHelp() {87 private static void showHelp() { 87 88 System.out.println(getHelp()); 88 89 System.exit(0); -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r14418 r14435 676 676 }); 677 677 678 addPropertyChangeListener(DIVIDER_LOCATION_PROPERTY, e -> { 679 heightAdjustedExplicitly = true; 680 }); 678 addPropertyChangeListener(DIVIDER_LOCATION_PROPERTY, e -> heightAdjustedExplicitly = true); 681 679 } 682 680 -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r14428 r14435 1776 1776 1777 1777 /** 1778 * Constructs a new {@code PrecacheTask}. 1778 1779 * @param progressMonitor that will be notified about progess of the task 1779 1780 * @param bufferY buffer Y in degrees around which to download tiles -
trunk/src/org/openstreetmap/josm/tools/OptionParser.java
r14419 r14435 168 168 parameter = split[1]; 169 169 } else { 170 if (toHandle.isEmpty() || toHandle.getFirst().equals("--")) {170 if (toHandle.isEmpty() || "--".equals(toHandle.getFirst())) { 171 171 throw new OptionParseException(tr("{0}: option ''{1}'' requires an argument", program)); 172 172 } … … 198 198 option.option.runFor(option.parameter); 199 199 } catch (OptionParseException e) { 200 String message;200 StringBuilder message = new StringBuilder(); 201 201 // Just add a nicer error message 202 202 if (option.parameter == null) { 203 message = tr("{0}: Error while handling option ''{1}''", program, option.optionName);203 message.append(tr("{0}: Error while handling option ''{1}''", program, option.optionName)); 204 204 } else { 205 message =tr("{0}: Invalid value {2} for option ''{1}''", program, option.optionName,206 option.parameter) ;205 message.append(tr("{0}: Invalid value {2} for option ''{1}''", program, option.optionName, 206 option.parameter)); 207 207 } 208 208 if (!e.getLocalizedMessage().isEmpty()) { 209 message += ": " + e.getLocalizedMessage().isEmpty();209 message.append(": ").append(e.getLocalizedMessage().isEmpty()); 210 210 } 211 throw new OptionParseException(message , e);211 throw new OptionParseException(message.toString(), e); 212 212 } 213 213 } … … 261 261 } 262 262 263 protected abstract static class AvailableOption { 264 265 public boolean requiresParameter() { 263 protected interface AvailableOption { 264 265 /** 266 * Determines if this option requires a parameter. 267 * @return {@code true} if this option requires a parameter ({@code false} by default) 268 */ 269 default boolean requiresParameter() { 266 270 return false; 267 271 } 268 272 269 public OptionCount getRequiredCount() { 273 /** 274 * Determines how often this option may / must be specified on the command line. 275 * @return how often this option may / must be specified on the command line 276 */ 277 default OptionCount getRequiredCount() { 270 278 return OptionCount.OPTIONAL; 271 279 } … … 275 283 * @param parameter The parameter if {@link #requiresParameter()} is true, <code>null</code> otherwise. 276 284 */ 277 public abstract void runFor(String parameter); 278 285 void runFor(String parameter); 279 286 } 280 287 … … 292 299 293 300 /** 301 * Exception thrown when an option cannot be parsed. 294 302 * @author Michael Zangl 295 303 */ … … 307 315 308 316 /** 317 * Create an error with a localized description 309 318 * @param localizedMessage The message to display to the user. 310 319 */ … … 315 324 316 325 /** 326 * Create an error with a localized description and a root cause 317 327 * @param localizedMessage The message to display to the user. 318 328 * @param t The error that caused this message to be displayed. -
trunk/test/unit/org/openstreetmap/josm/tools/OptionParserTest.java
r14415 r14435 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertTrue; 5 7 6 8 import java.util.ArrayList; … … 20 22 public class OptionParserTest { 21 23 22 // A reason for moving to jup ter...24 // A reason for moving to jupiter... 23 25 @Test(expected = OptionParseException.class) 24 26 public void testEmptyParserRejectsLongopt() { … … 43 45 44 46 @Test 45 public void test parserOption() {47 public void testParserOption() { 46 48 AtomicReference<String> argFound = new AtomicReference<>(); 47 49 OptionParser parser = new OptionParser("test") … … 53 55 54 56 @Test(expected = OptionParseException.class) 55 public void test parserOptionFailsIfMissing() {57 public void testParserOptionFailsIfMissing() { 56 58 AtomicReference<String> argFound = new AtomicReference<>(); 57 59 OptionParser parser = new OptionParser("test") … … 62 64 63 65 @Test(expected = OptionParseException.class) 64 public void test parserOptionFailsIfMissingArgument() {66 public void testParserOptionFailsIfMissingArgument() { 65 67 AtomicReference<String> argFound = new AtomicReference<>(); 66 68 OptionParser parser = new OptionParser("test") … … 71 73 72 74 @Test(expected = OptionParseException.class) 73 public void test parserOptionFailsIfMissing2() {75 public void testParserOptionFailsIfMissing2() { 74 76 AtomicReference<String> argFound = new AtomicReference<>(); 75 77 OptionParser parser = new OptionParser("test") … … 80 82 81 83 @Test(expected = OptionParseException.class) 82 public void test parserOptionFailsIfTwice() {84 public void testParserOptionFailsIfTwice() { 83 85 AtomicReference<String> argFound = new AtomicReference<>(); 84 86 OptionParser parser = new OptionParser("test") … … 89 91 90 92 @Test(expected = OptionParseException.class) 91 public void test parserOptionFailsIfTwiceForAlias() {93 public void testParserOptionFailsIfTwiceForAlias() { 92 94 AtomicReference<String> argFound = new AtomicReference<>(); 93 95 OptionParser parser = new OptionParser("test") … … 226 228 assertEquals("arg", argFound.get()); 227 229 assertEquals(Arrays.asList("m1", "m2"), multiFound); 228 assert Equals(true,usedFlag.get());229 assert Equals(false,unusedFlag.get());230 assertTrue(usedFlag.get()); 231 assertFalse(unusedFlag.get()); 230 232 } 231 233 … … 245 247 assertEquals(Arrays.asList(), remaining); 246 248 assertEquals("arg", argFound.get()); 247 assert Equals(true,usedFlag.get());248 assert Equals(false,unusedFlag.get());249 } 250 251 @Test(expected = OptionParseException.class) 252 public void testA bigiousAlternatives() {249 assertTrue(usedFlag.get()); 250 assertFalse(unusedFlag.get()); 251 } 252 253 @Test(expected = OptionParseException.class) 254 public void testAmbiguousAlternatives() { 253 255 AtomicReference<String> argFound = new AtomicReference<>(); 254 256 AtomicBoolean usedFlag = new AtomicBoolean(); … … 280 282 assertEquals(Arrays.asList("x"), remaining); 281 283 assertEquals("arg", argFound.get()); 282 assert Equals(true,usedFlag.get());283 assert Equals(false,unusedFlag.get());284 assertTrue(usedFlag.get()); 285 assertFalse(unusedFlag.get()); 284 286 285 287 remaining = parser.parseOptions(Arrays.asList("-ft", "arg", "x")); … … 287 289 assertEquals(Arrays.asList("x"), remaining); 288 290 assertEquals("arg", argFound.get()); 289 assert Equals(true,usedFlag.get());290 assert Equals(false,unusedFlag.get());291 assertTrue(usedFlag.get()); 292 assertFalse(unusedFlag.get()); 291 293 292 294 remaining = parser.parseOptions(Arrays.asList("-f", "-t=arg", "x")); … … 294 296 assertEquals(Arrays.asList("x"), remaining); 295 297 assertEquals("arg", argFound.get()); 296 assert Equals(true,usedFlag.get());297 assert Equals(false,unusedFlag.get());298 assertTrue(usedFlag.get()); 299 assertFalse(unusedFlag.get()); 298 300 } 299 301 … … 319 321 320 322 @Test(expected = IllegalArgumentException.class) 321 public void testDup plicateOptionName() {323 public void testDuplicateOptionName() { 322 324 new OptionParser("test").addFlagParameter("test", this::nop).addFlagParameter("test", this::nop); 323 325 } 324 326 325 327 @Test(expected = IllegalArgumentException.class) 326 public void testDup plicateOptionName2() {328 public void testDuplicateOptionName2() { 327 329 new OptionParser("test").addFlagParameter("test", this::nop) 328 330 .addArgumentParameter("test", OptionCount.OPTIONAL, this::nop); … … 345 347 346 348 @Test(expected = IllegalArgumentException.class) 347 public void testDup plicateShortAlias() {349 public void testDuplicateShortAlias() { 348 350 new OptionParser("test").addFlagParameter("test", this::nop) 349 351 .addFlagParameter("test2", this::nop)
Note:
See TracChangeset
for help on using the changeset viewer.