MCPcopy Create free account
hub / github.com/antlr/codebuff / handleArgs

Method handleArgs

corpus/java/training/antlr4-tool/org/antlr/v4/Tool.java:222–297  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220 }
221
222 protected void handleArgs() {
223 int i=0;
224 while ( args!=null && i<args.length ) {
225 String arg = args[i];
226 i++;
227 if ( arg.startsWith("-D") ) { // -Dlanguage=Java syntax
228 handleOptionSetArg(arg);
229 continue;
230 }
231 if ( arg.charAt(0)!='-' ) { // file name
232 if ( !grammarFiles.contains(arg) ) grammarFiles.add(arg);
233 continue;
234 }
235 boolean found = false;
236 for (Option o : optionDefs) {
237 if ( arg.equals(o.name) ) {
238 found = true;
239 String argValue = null;
240 if ( o.argType==OptionArgType.STRING ) {
241 argValue = args[i];
242 i++;
243 }
244 // use reflection to set field
245 Class<? extends Tool> c = this.getClass();
246 try {
247 Field f = c.getField(o.fieldName);
248 if ( argValue==null ) {
249 if ( arg.startsWith("-no-") ) f.setBoolean(this, false);
250 else f.setBoolean(this, true);
251 }
252 else f.set(this, argValue);
253 }
254 catch (Exception e) {
255 errMgr.toolError(ErrorType.INTERNAL_ERROR, "can't access field "+o.fieldName);
256 }
257 }
258 }
259 if ( !found ) {
260 errMgr.toolError(ErrorType.INVALID_CMDLINE_ARG, arg);
261 }
262 }
263 if ( outputDirectory!=null ) {
264 if (outputDirectory.endsWith("/") ||
265 outputDirectory.endsWith("\\")) {
266 outputDirectory =
267 outputDirectory.substring(0, outputDirectory.length() - 1);
268 }
269 File outDir = new File(outputDirectory);
270 haveOutputDir = true;
271 if (outDir.exists() && !outDir.isDirectory()) {
272 errMgr.toolError(ErrorType.OUTPUT_DIR_IS_FILE, outputDirectory);
273 libDirectory = ".";
274 }
275 }
276 else {
277 outputDirectory = ".";
278 }
279 if ( libDirectory!=null ) {

Callers 1

ToolMethod · 0.95

Calls 9

handleOptionSetArgMethod · 0.95
toolErrorMethod · 0.80
containsMethod · 0.65
addMethod · 0.65
equalsMethod · 0.65
setMethod · 0.65
getFieldMethod · 0.45
lengthMethod · 0.45
isDirectoryMethod · 0.45

Tested by

no test coverage detected