Search in sources :

Example 1 with Log

use of org.eclipse.ceylon.langtools.tools.javac.util.Log 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)

Example 2 with Log

use of org.eclipse.ceylon.langtools.tools.javac.util.Log in project ceylon by eclipse.

the class JavacProcessingEnvironment method initProcessorIterator.

private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
    Log log = Log.instance(context);
    Iterator<? extends Processor> processorIterator;
    if (options.isSet(XPRINT)) {
        try {
            Processor processor = PrintingProcessor.class.newInstance();
            processorIterator = List.of(processor).iterator();
        } catch (Throwable t) {
            AssertionError assertError = new AssertionError("Problem instantiating PrintingProcessor.");
            assertError.initCause(t);
            throw assertError;
        }
    } else if (processors != null) {
        processorIterator = processors.iterator();
    } else {
        String processorNames = options.get(PROCESSOR);
        if (processorClassLoaderException == null) {
            /*
                 * If the "-processor" option is used, search the appropriate
                 * path for the named class.  Otherwise, use a service
                 * provider mechanism to create the processor iterator.
                 */
            if (processorNames != null) {
                processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log);
            } else {
                processorIterator = new ServiceIterator(processorClassLoader, log);
            }
        } else {
            /*
                 * A security exception will occur if we can't create a classloader.
                 * Ignore the exception if, with hindsight, we didn't need it anyway
                 * (i.e. no processor was specified either explicitly, or implicitly,
                 * in service configuration file.) Otherwise, we cannot continue.
                 */
            processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", processorClassLoaderException);
        }
    }
    discoveredProcs = new DiscoveredProcessors(processorIterator);
}
Also used : Log(org.eclipse.ceylon.langtools.tools.javac.util.Log)

Aggregations

Log (org.eclipse.ceylon.langtools.tools.javac.util.Log)2 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 Options (org.eclipse.ceylon.langtools.tools.javac.util.Options)1