summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-03-20 18:04:42 +0000
committerTom Tromey <tromey@redhat.com>2008-03-20 18:04:42 +0000
commit97e9966276c4c69cc632a58bb81ef87f3e369d06 (patch)
treeff3b3c81308eefd3afe235e68f4b496aedce0761 /tools
parent4a47af06c3c29f0b1ccc304d3ace37aa5cdbeeb3 (diff)
downloadclasspath-97e9966276c4c69cc632a58bb81ef87f3e369d06.tar.gz
* tools/gnu/classpath/tools/getopt/Parser.java (options): Don't
initialize. (add, addFinal): Don't update options. (requireOptions): New method. (printHelp): Synchronize. Call requireOptions. (parse): Call requireOptions.
Diffstat (limited to 'tools')
-rw-r--r--tools/gnu/classpath/tools/getopt/Parser.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/tools/gnu/classpath/tools/getopt/Parser.java b/tools/gnu/classpath/tools/getopt/Parser.java
index b142836a5..5b18ecb37 100644
--- a/tools/gnu/classpath/tools/getopt/Parser.java
+++ b/tools/gnu/classpath/tools/getopt/Parser.java
@@ -1,5 +1,5 @@
/* Parser.java - parse command line options
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -66,7 +66,9 @@ public class Parser
private boolean longOnly;
- private ArrayList options = new ArrayList();
+ // All of the options. This is null initially; users must call
+ // requireOptions before access.
+ private ArrayList options;
private ArrayList optionGroups = new ArrayList();
@@ -218,7 +220,6 @@ public class Parser
*/
public synchronized void add(Option opt)
{
- options.add(opt);
defaultGroup.add(opt);
}
@@ -230,7 +231,6 @@ public class Parser
*/
protected synchronized void addFinal(Option opt)
{
- options.add(opt);
finalGroup.add(opt);
}
@@ -242,7 +242,6 @@ public class Parser
*/
public synchronized void add(OptionGroup group)
{
- options.addAll(group.options);
// This ensures that the final group always appears at the end
// of the options.
if (optionGroups.isEmpty())
@@ -251,13 +250,29 @@ public class Parser
optionGroups.add(optionGroups.size() - 1, group);
}
+ // Make sure the 'options' field is properly initialized.
+ private void requireOptions()
+ {
+ if (options != null)
+ return;
+ options = new ArrayList();
+ Iterator it = optionGroups.iterator();
+ while (it.hasNext())
+ {
+ OptionGroup group = (OptionGroup) it.next();
+ options.addAll(group.options);
+ }
+ }
+
public void printHelp()
{
this.printHelp(System.out);
}
- void printHelp(PrintStream out)
+ synchronized void printHelp(PrintStream out)
{
+ requireOptions();
+
if (headerText != null)
{
formatText(out, headerText);
@@ -417,6 +432,7 @@ public class Parser
*/
public synchronized void parse(String[] inArgs, FileArgumentCallback files)
{
+ requireOptions();
try
{
args = inArgs;