Search in sources :

Example 1 with GrumpyHelper

use of org.eclipse.ceylon.langtools.tools.javac.main.OptionHelper.GrumpyHelper in project ceylon by eclipse.

the class JavacTool method processOptions.

public static void processOptions(Context context, JavaFileManager fileManager, Iterable<String> options) {
    if (options == null)
        return;
    final Options optionTable = Options.instance(context);
    Log log = Log.instance(context);
    Option[] recognizedOptions = Option.getJavacToolOptions().toArray(new Option[0]);
    OptionHelper optionHelper = new GrumpyHelper(log) {

        @Override
        public String get(Option option) {
            return optionTable.get(option.getText());
        }

        @Override
        public java.util.List<String> getMulti(Option option) {
            return optionTable.getMulti(option);
        }

        @Override
        public void put(String name, String value) {
            optionTable.put(name, value);
        }

        @Override
        public void addMulti(String name, String value) {
            optionTable.addMulti(name, value);
        }

        @Override
        public void remove(String name) {
            optionTable.remove(name);
        }
    };
    Iterator<String> flags = options.iterator();
    while (flags.hasNext()) {
        String flag = flags.next();
        int j;
        for (j = 0; j < recognizedOptions.length; j++) {
            Option ro = recognizedOptions[j];
            if (ro.matches(flag))
                break;
        }
        if (j == recognizedOptions.length) {
            if (fileManager.handleOption(flag, flags)) {
                continue;
            } else {
                String msg = log.localize(PrefixKind.JAVAC, "err.invalid.flag", flag);
                throw new IllegalArgumentException(msg);
            }
        }
        Option option = recognizedOptions[j];
        if (option.hasArg()) {
            if (!flags.hasNext()) {
                String msg = log.localize(PrefixKind.JAVAC, "err.req.arg", flag);
                throw new IllegalArgumentException(msg);
            }
            String operand = flags.next();
            if (option.process(optionHelper, flag, operand))
                // in case of errors
                throw new IllegalArgumentException(flag + " " + operand);
        } else {
            if (option.process(optionHelper, flag))
                // in case of errors
                throw new IllegalArgumentException(flag);
        }
    }
    optionTable.notifyListeners();
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options) OptionHelper(org.eclipse.ceylon.langtools.tools.javac.main.OptionHelper) Log(org.eclipse.ceylon.langtools.tools.javac.util.Log) Option(org.eclipse.ceylon.langtools.tools.javac.main.Option) GrumpyHelper(org.eclipse.ceylon.langtools.tools.javac.main.OptionHelper.GrumpyHelper)

Aggregations

Option (org.eclipse.ceylon.langtools.tools.javac.main.Option)1 OptionHelper (org.eclipse.ceylon.langtools.tools.javac.main.OptionHelper)1 GrumpyHelper (org.eclipse.ceylon.langtools.tools.javac.main.OptionHelper.GrumpyHelper)1 Log (org.eclipse.ceylon.langtools.tools.javac.util.Log)1 Options (org.eclipse.ceylon.langtools.tools.javac.util.Options)1