Search in sources :

Example 1 with Options

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

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

the class LanguageCompiler method instance.

/**
 * Get the JavaCompiler instance for this context.
 */
public static JavaCompiler instance(Context context) {
    Options options = Options.instance(context);
    options.put("-Xprefer", "source");
    // make sure it's registered
    // Log log = CeylonLog.instance(context);
    CeylonEnter.instance(context);
    CeylonClassWriter.instance(context);
    JavaCompiler instance = context.get(compilerKey);
    if (instance == null)
        instance = new LanguageCompiler(context);
    return instance;
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options) JavaCompiler(org.eclipse.ceylon.langtools.tools.javac.main.JavaCompiler)

Example 3 with Options

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

the class CeyloncCompilerDelegate method getModuleSourceMapper.

@Override
public ModuleSourceMapper getModuleSourceMapper() {
    if (moduleSourceMapper == null) {
        org.eclipse.ceylon.compiler.typechecker.context.Context ceylonContext = LanguageCompiler.getCeylonContextInstance(context);
        Options options = Options.instance(context);
        boolean verbose = options.isSet(Option.VERBOSE);
        CeylonLog log = (CeylonLog) CeylonLog.instance(context);
        moduleSourceMapper = new LazyModuleSourceMapper(ceylonContext, getModuleManager(), getStatusPrinter(), verbose, log);
    }
    return moduleSourceMapper;
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options) LazyModuleSourceMapper(org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper)

Example 4 with Options

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

the class CompilerConfig method instance.

public static CeylonConfig instance(Context context) {
    CeylonConfig instance = context.get(CeylonConfig.class);
    if (instance == null) {
        Options options = Options.instance(context);
        String cwd = options.get(Option.CEYLONCWD);
        if (cwd == null) {
            cwd = ".";
        }
        instance = CeylonConfig.createFromLocalDir(new File(cwd));
        context.put(CeylonConfig.class, instance);
    }
    return instance;
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options) CeylonConfig(org.eclipse.ceylon.common.config.CeylonConfig) File(java.io.File)

Example 5 with Options

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

the class JavacProcessingEnvironment method initProcessorOptions.

private Map<String, String> initProcessorOptions(Context context) {
    Options options = Options.instance(context);
    Set<String> keySet = options.keySet();
    Map<String, String> tempOptions = new LinkedHashMap<String, String>();
    for (String key : keySet) {
        if (key.startsWith("-A") && key.length() > 2) {
            int sepIndex = key.indexOf('=');
            String candidateKey = null;
            String candidateValue = null;
            if (sepIndex == -1)
                candidateKey = key.substring(2);
            else if (sepIndex >= 3) {
                candidateKey = key.substring(2, sepIndex);
                candidateValue = (sepIndex < key.length() - 1) ? key.substring(sepIndex + 1) : null;
            }
            tempOptions.put(candidateKey, candidateValue);
        }
    }
    return Collections.unmodifiableMap(tempOptions);
}
Also used : Options(org.eclipse.ceylon.langtools.tools.javac.util.Options)

Aggregations

Options (org.eclipse.ceylon.langtools.tools.javac.util.Options)6 File (java.io.File)1 CeylonConfig (org.eclipse.ceylon.common.config.CeylonConfig)1 LazyModuleSourceMapper (org.eclipse.ceylon.compiler.java.loader.model.LazyModuleSourceMapper)1 JavaCompiler (org.eclipse.ceylon.langtools.tools.javac.main.JavaCompiler)1 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