public List<OptFlag.Arg<?>> filterArgs(Set<OptFlag<?>> flags) { List<Arg<?>> matches = new ArrayList<>(); for (Arg<?> arg : arguments) { if (arg.flag != null && flags.contains(arg.flag())) matches.add(arg); } return matches; }
/** * Iterates over arguments parsed from the command line and applies them to this object. Any * source arguments are added to {@code source}. * * @param source The set of source filenames provided on the command line. */ public void printCommandLine(PrintStream out) { Set<OptFlag<?>> seen = new LinkedHashSet<>(); for (Arg<?> arg : arguments) { if (arg.flag != null) { seen.add(arg.flag); } out.print(" " + arg.toString()); } for (OptFlag<?> flag : flags) { if (seen.contains(flag)) continue; else { Arg<?> arg = flag.defaultArg(arguments); if (arg != null) out.print(" " + arg.toString()); } } out.println(); }
/** * Parse a command * * @return the next index to process. i.e., if calling this method processes two commands, then * the return value should be index+2 */ protected int parseCommand(String args[], int index, Set<String> source) throws UsageError, Main.TerminationException { // Find a flag whose id matches args[index] and let it process the // arguments. for (OptFlag<?> flag : flags) { if (flag.ids.contains(args[index])) { Arg<?> arg = flag.handle(args, index + 1); arguments.add(arg); return arg.next(); } } if (!args[index].startsWith("-")) { index = parseSourceArg(args, index); } return index; }
/** * Iterates over arguments parsed from the command line and applies them to this object. Any * source arguments are added to {@code source}. * * @param source The set of source filenames provided on the command line. */ protected final void applyArgs(Set<String> source) throws UsageError { // Set up defaults first. for (OptFlag<?> flag : flags) { Arg<?> arg = flag.defaultArg(arguments); if (arg != null) handleArg(arg); } // Let user-specified arguments override the defaults. for (Arg<?> arg : arguments) { if (arg.flag == null) { handleSourceArg(arg, source); } else { try { handleArg(arg); } catch (UsageError e) { throw e; } catch (Throwable e) { throw new InternalCompilerError( "Error while handling arg " + arg + " created by " + arg.flag().getClass(), e); } } } }
protected int parseSourceArg(String[] args, int index) { Arg<String> src = new Arg<>(index + 1, args[index]); arguments.add(src); return src.next(); }
/** * Process a source argument and add it to the source collection. * * @param source The set of filenames to compile. */ protected void handleSourceArg(Arg<?> arg, Set<String> source) { String filename = (String) arg.value(); source.add(filename); }
/** Process the option specified by {@code arg} */ protected void handleArg(Arg<?> arg) throws UsageError { assert arg.flag != null; Set<String> ids = arg.flag().ids(); if (ids.contains("-d")) { setClassOutput((File) arg.value()); } else if (ids.contains("-D")) { setSourceOutput((File) arg.value()); } else if (ids.contains("-classpath")) { setClasspath(this.<List<File>, File>sccast(arg.value(), File.class)); } else if (ids.contains("-bootclasspath")) { setBootclasspath(this.<List<File>, File>sccast(arg.value(), File.class)); } else if (ids.contains("-addbootcp")) { addBootCP(this.<List<File>, File>sccast(arg.value(), File.class)); } else if (ids.contains("-sourcepath")) { setSourcepath(this.<List<File>, File>sccast(arg.value(), File.class)); } else if (ids.contains("-commandlineonly")) { setCommandLineOnly((Boolean) arg.value()); } else if (ids.contains("-preferclassfiles")) { setIgnoreModTimes((Boolean) arg.value()); } else if (ids.contains("-assert")) { setAssertions((Boolean) arg.value()); } else if (ids.contains("-fqcn")) { setFullyQualifiedNames((Boolean) arg.value()); } else if (ids.contains("-g")) { setGenerateDebugInfo((Boolean) arg.value()); } else if (ids.contains("-c")) { setOutputOnly((Boolean) arg.value()); } else if (ids.contains("-errors")) { setErrorCount((Integer) arg.value()); } else if (ids.contains("-w")) { setOutputWidth((Integer) arg.value()); } else if (ids.contains("-postcompiler")) { setPostCompiler((String) arg.value()); } else if (ids.contains("-postopts")) { setPostCompilerOpts((String) arg.value()); } else if (ids.contains("-stdout")) { setOutputStdOut((Boolean) arg.value()); } else if (ids.contains("-sx")) { addSourceExtension((String) arg.value()); } else if (ids.contains("-ox")) { setOutputExtension((String) arg.value()); } else if (ids.contains("-noserial")) { setNoSerializedTypes((Boolean) arg.value()); } else if (ids.contains("-dump")) { addDumpAST((String) arg.value()); } else if (ids.contains("-print")) { addPrintAST((String) arg.value()); } else if (ids.contains("-disable")) { addDisablePass((String) arg.value()); } else if (ids.contains("-nooutput")) { setNoOutput((Boolean) arg.value()); } else if (ids.contains("-verbose")) { setVerbose((Boolean) arg.value()); } else if (ids.contains("-report")) { @SuppressWarnings("unchecked") Pair<String, Integer> pair = (Pair<String, Integer>) arg.value(); addReportTopic(pair.part1(), pair.part2()); } else if (ids.contains("-debugpositions")) { setDebugPositions((Boolean) arg.value()); } else if (ids.contains("-simpleoutput")) { setSimpleOutput((Boolean) arg.value()); } else if (ids.contains("-mergestrings")) { setMergeStrings((Boolean) arg.value()); } else if (ids.contains("-print-arguments")) { print_args = (Boolean) arg.value(); } else if (ids.contains("-no-output-to-fs")) { noOutputToFS = (Boolean) arg.value(); } else throw new UnhandledArgument(arg); }