1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
package com.sun.tools.javafx.main; |
27 | |
|
28 | |
import com.sun.tools.javac.util.Log; |
29 | |
import com.sun.tools.javac.util.Options; |
30 | |
import java.io.PrintWriter; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public interface JavafxOption { |
41 | |
|
42 | |
OptionKind getKind(); |
43 | |
|
44 | |
|
45 | |
boolean hasArg(); |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
boolean matches(String arg); |
51 | |
|
52 | |
|
53 | |
|
54 | |
boolean process(Options options, String option, String arg); |
55 | |
|
56 | |
|
57 | |
|
58 | |
boolean process(Options options, String option); |
59 | |
|
60 | |
OptionName getName(); |
61 | |
|
62 | 0 | enum OptionKind { |
63 | 0 | NORMAL, |
64 | 0 | EXTENDED, |
65 | 0 | HIDDEN, |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
static class Option implements JavafxOption { |
71 | |
|
72 | |
|
73 | |
|
74 | |
OptionName name; |
75 | |
|
76 | |
|
77 | |
|
78 | |
String argsNameKey; |
79 | |
|
80 | |
|
81 | |
|
82 | |
String descrKey; |
83 | |
|
84 | |
|
85 | |
|
86 | |
boolean hasSuffix; |
87 | |
|
88 | 26568 | Option(OptionName name, String argsNameKey, String descrKey) { |
89 | 26568 | this.name = name; |
90 | 26568 | this.argsNameKey = argsNameKey; |
91 | 26568 | this.descrKey = descrKey; |
92 | 26568 | char lastChar = name.optionName.charAt(name.optionName.length()-1); |
93 | 26568 | hasSuffix = lastChar == ':' || lastChar == '='; |
94 | 26568 | } |
95 | |
Option(OptionName name, String descrKey) { |
96 | 4920 | this(name, null, descrKey); |
97 | 4920 | } |
98 | |
|
99 | |
@Override |
100 | |
public String toString() { |
101 | 0 | return name.optionName; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
public boolean hasArg() { |
107 | 1737 | return argsNameKey != null && !hasSuffix; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public boolean matches(String arg) { |
114 | 22568 | return hasSuffix ? arg.startsWith(name.optionName) : arg.equals(name.optionName); |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
void help(PrintWriter out) { |
120 | 0 | String s = " " + helpSynopsis(); |
121 | 0 | out.print(s); |
122 | 0 | for (int j = s.length(); j < 29; j++) out.print(" "); |
123 | 0 | Log.printLines(out, Main.getLocalizedString(descrKey)); |
124 | 0 | } |
125 | |
String helpSynopsis() { |
126 | 0 | return name + |
127 | |
(argsNameKey == null ? "" : |
128 | |
((hasSuffix ? "" : " ") + |
129 | |
Main.getLocalizedString(argsNameKey))); |
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | 0 | void xhelp(PrintWriter out) {} |
135 | |
|
136 | |
|
137 | |
|
138 | |
public boolean process(Options options, String option, String arg) { |
139 | 1196 | if (options != null) |
140 | 1196 | options.put(option, arg); |
141 | 1196 | return false; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
public boolean process(Options options, String option) { |
147 | 58 | if (hasSuffix) |
148 | 0 | return process(options, name.optionName, option.substring(name.optionName.length())); |
149 | |
else |
150 | 58 | return process(options, option, option); |
151 | |
} |
152 | |
|
153 | 0 | public OptionKind getKind() { return OptionKind.NORMAL; } |
154 | |
|
155 | 26568 | public OptionName getName() { return name; } |
156 | |
}; |
157 | |
|
158 | |
|
159 | |
|
160 | |
static class XOption extends Option { |
161 | |
XOption(OptionName name, String argsNameKey, String descrKey) { |
162 | 6888 | super(name, argsNameKey, descrKey); |
163 | 6888 | } |
164 | |
XOption(OptionName name, String descrKey) { |
165 | 2952 | this(name, null, descrKey); |
166 | 2952 | } |
167 | |
@Override |
168 | 0 | void help(PrintWriter out) {} |
169 | |
@Override |
170 | 0 | void xhelp(PrintWriter out) { super.help(out); } |
171 | |
@Override |
172 | 0 | public OptionKind getKind() { return OptionKind.EXTENDED; } |
173 | |
}; |
174 | |
|
175 | |
|
176 | |
|
177 | |
static class HiddenOption extends Option { |
178 | |
HiddenOption(OptionName name) { |
179 | 7380 | super(name, null, null); |
180 | 7380 | } |
181 | |
HiddenOption(OptionName name, String argsNameKey) { |
182 | 0 | super(name, argsNameKey, null); |
183 | 0 | } |
184 | |
@Override |
185 | 0 | void help(PrintWriter out) {} |
186 | |
@Override |
187 | 0 | void xhelp(PrintWriter out) {} |
188 | |
@Override |
189 | 0 | public OptionKind getKind() { return OptionKind.HIDDEN; } |
190 | |
}; |
191 | |
|
192 | |
|
193 | |
|
194 | |
static class FXOption extends Option { |
195 | |
FXOption(OptionName name, String argsNameKey, String descrKey) { |
196 | 492 | super(name, argsNameKey, descrKey); |
197 | 492 | } |
198 | |
|
199 | |
@Override |
200 | |
void help(PrintWriter out) { |
201 | 0 | String s = " " + helpSynopsis(); |
202 | 0 | out.print(s); |
203 | 0 | for (int j = s.length(); j < 29; j++) out.print(" "); |
204 | 0 | Log.printLines(out, Main.getJavafxLocalizedString(descrKey)); |
205 | 0 | } |
206 | |
|
207 | |
@Override |
208 | |
String helpSynopsis() { |
209 | 0 | return name + |
210 | |
(argsNameKey == null ? "" : |
211 | |
((hasSuffix ? "" : " ") + |
212 | |
Main.getJavafxLocalizedString(argsNameKey))); |
213 | |
} |
214 | |
} |
215 | |
} |