Search in sources :

Example 16 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

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
    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(com.sun.tools.javac.util.Options) JavaCompiler(com.sun.tools.javac.main.JavaCompiler)

Example 17 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

the class Start method parseAndExecute.

/**
     * Main program - internal
     */
private boolean parseAndExecute(String... argv) throws IOException {
    long tm = System.currentTimeMillis();
    ListBuffer<String> javaNames = new ListBuffer<String>();
    // Preprocess @file arguments
    try {
        argv = CommandLine.parse(argv);
    } catch (FileNotFoundException e) {
        messager.error(null, "main.cant.read", e.getMessage());
        exit();
    } catch (IOException e) {
        e.printStackTrace();
        exit();
    }
    setDocletInvoker(argv);
    ListBuffer<String> subPackages = new ListBuffer<String>();
    ListBuffer<String> excludedPackages = new ListBuffer<String>();
    Context context = new Context();
    // Setup a new Messager, using the same initial parameters as the
    // existing Messager, except that this one will be able to use any
    // options that may be set up below.
    Messager.preRegister(context, messager.programName, messager.errWriter, messager.warnWriter, messager.noticeWriter);
    Options compOpts = Options.instance(context);
    boolean docClasses = false;
    // Parse arguments
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];
        if (arg.equals("-subpackages")) {
            oneArg(argv, i++);
            addToList(subPackages, argv[i]);
        } else if (arg.equals("-exclude")) {
            oneArg(argv, i++);
            addToList(excludedPackages, argv[i]);
        } else if (arg.equals("-verbose")) {
            setOption(arg);
            compOpts.put("-verbose", "");
        } else if (arg.equals("-encoding")) {
            oneArg(argv, i++);
            encoding = argv[i];
            compOpts.put("-encoding", argv[i]);
        } else if (arg.equals("-breakiterator")) {
            breakiterator = true;
            setOption("-breakiterator");
        } else if (arg.equals("-quiet")) {
            quiet = true;
            setOption("-quiet");
        } else if (arg.equals("-help")) {
            usage();
            exit();
        } else if (arg.equals("-Xclasses")) {
            setOption(arg);
            docClasses = true;
        } else if (arg.equals("-Xwerror")) {
            setOption(arg);
            rejectWarnings = true;
        } else if (arg.equals("-private")) {
            setOption(arg);
            setFilter(ModifierFilter.ALL_ACCESS);
        } else if (arg.equals("-package")) {
            setOption(arg);
            setFilter(PUBLIC | PROTECTED | ModifierFilter.PACKAGE);
        } else if (arg.equals("-protected")) {
            setOption(arg);
            setFilter(PUBLIC | PROTECTED);
        } else if (arg.equals("-public")) {
            setOption(arg);
            setFilter(PUBLIC);
        } else if (arg.equals("-source")) {
            oneArg(argv, i++);
            if (compOpts.get("-source") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-source", argv[i]);
        } else if (arg.equals("-prompt")) {
            compOpts.put("-prompt", "-prompt");
            messager.promptOnError = true;
        } else if (arg.equals("-sourcepath")) {
            oneArg(argv, i++);
            if (compOpts.get("-sourcepath") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-sourcepath", argv[i]);
        } else if (arg.equals("-classpath")) {
            oneArg(argv, i++);
            if (compOpts.get("-classpath") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-classpath", argv[i]);
        } else if (arg.equals("-sysclasspath")) {
            oneArg(argv, i++);
            if (compOpts.get("-bootclasspath") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-bootclasspath", argv[i]);
        } else if (arg.equals("-bootclasspath")) {
            oneArg(argv, i++);
            if (compOpts.get("-bootclasspath") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-bootclasspath", argv[i]);
        } else if (arg.equals("-extdirs")) {
            oneArg(argv, i++);
            if (compOpts.get("-extdirs") != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put("-extdirs", argv[i]);
        } else if (arg.equals("-overview")) {
            oneArg(argv, i++);
        } else if (arg.equals("-doclet")) {
            // handled in setDocletInvoker
            i++;
        } else if (arg.equals("-docletpath")) {
            // handled in setDocletInvoker
            i++;
        } else if (arg.equals("-locale")) {
            if (i != 0)
                usageError("main.locale_first");
            oneArg(argv, i++);
            docLocale = argv[i];
        } else if (arg.equals("-Xmaxerrs") || arg.equals("-Xmaxwarns")) {
            oneArg(argv, i++);
            if (compOpts.get(arg) != null) {
                usageError("main.option.already.seen", arg);
            }
            compOpts.put(arg, argv[i]);
        } else if (arg.equals("-X")) {
            Xusage();
            exit();
        } else if (arg.startsWith("-XD")) {
            String s = arg.substring("-XD".length());
            int eq = s.indexOf('=');
            String key = (eq < 0) ? s : s.substring(0, eq);
            String value = (eq < 0) ? s : s.substring(eq + 1);
            compOpts.put(key, value);
        } else // other arg starts with - is invalid
        if (arg.startsWith("-")) {
            int optionLength;
            optionLength = docletInvoker.optionLength(arg);
            if (optionLength < 0) {
                // error already displayed
                exit();
            } else if (optionLength == 0) {
                // option not found
                usageError("main.invalid_flag", arg);
            } else {
                // doclet added option
                if ((i + optionLength) > argv.length) {
                    usageError("main.requires_argument", arg);
                }
                ListBuffer<String> args = new ListBuffer<String>();
                for (int j = 0; j < optionLength - 1; ++j) {
                    args.append(argv[++i]);
                }
                setOption(arg, args.toList());
            }
        } else {
            javaNames.append(arg);
        }
    }
    if (javaNames.isEmpty() && subPackages.isEmpty()) {
        usageError("main.No_packages_or_classes_specified");
    }
    if (!docletInvoker.validOptions(options.toList())) {
        // error message already displayed
        exit();
    }
    JavadocTool comp = JavadocTool.make0(context);
    if (comp == null)
        return false;
    if (showAccess == null) {
        setFilter(defaultFilter);
    }
    LanguageVersion languageVersion = docletInvoker.languageVersion();
    RootDocImpl root = comp.getRootDocImpl(docLocale, encoding, showAccess, javaNames.toList(), options.toList(), breakiterator, subPackages.toList(), excludedPackages.toList(), docClasses, // legacy?
    languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1, quiet);
    // pass off control to the doclet
    boolean ok = root != null;
    if (ok)
        ok = docletInvoker.start(root);
    Messager docletMessager = Messager.instance0(context);
    messager.nwarnings += docletMessager.nwarnings;
    messager.nerrors += docletMessager.nerrors;
    // We're done.
    if (compOpts.get("-verbose") != null) {
        tm = System.currentTimeMillis() - tm;
        messager.notice("main.done_in", Long.toString(tm));
    }
    return ok;
}
Also used : Context(com.sun.tools.javac.util.Context) Options(com.sun.tools.javac.util.Options) ListBuffer(com.sun.tools.javac.util.ListBuffer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 18 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

the class RecognizedOptions method getAll.

/**
     * Get all the recognized options.
     * @param helper an {@code OptionHelper} to help when processing options
     * @return an array of options
     */
public static Option[] getAll(final OptionHelper helper) {
    return new Option[] { new Option(G, "opt.g"), new Option(G_NONE, "opt.g.none") {

        @Override
        public boolean process(Options options, String option) {
            options.put("-g:", "none");
            return false;
        }
    }, new Option(G_CUSTOM, "opt.g.lines.vars.source", Option.ChoiceKind.ANYOF, "lines", "vars", "source"), new XOption(XLINT, "opt.Xlint"), new XOption(XLINT_CUSTOM, "opt.Xlint.suboptlist", Option.ChoiceKind.ANYOF, getXLintChoices()), // -nowarn is retained for command-line backward compatibility
    new Option(NOWARN, "opt.nowarn") {

        @Override
        public boolean process(Options options, String option) {
            options.put("-Xlint:none", option);
            return false;
        }
    }, new Option(VERBOSE, "opt.verbose"), new Option(VERBOSE_CUSTOM, "opt.verbose.suboptlist") {

        public boolean matches(String s) {
            return s.startsWith("-verbose:");
        }

        public boolean process(Options options, String option) {
            String suboptions = option.substring(9);
            options.put("-verbose:", suboptions);
            // enter all the -verbose suboptions as "-verbose:suboption"
            for (StringTokenizer t = new StringTokenizer(suboptions, ","); t.hasMoreTokens(); ) {
                String tok = t.nextToken();
                // make sure all is an alias for --verbose
                if (tok.equals("all"))
                    options.put(VERBOSE, "true");
                String opt = "-verbose:" + tok;
                options.put(opt, opt);
            }
            return false;
        }
    }, // -deprecation is retained for command-line backward compatibility
    new Option(DEPRECATION, "opt.deprecation") {

        @Override
        public boolean process(Options options, String option) {
            options.put("-Xlint:deprecation", option);
            return false;
        }
    }, new Option(CLASSPATH, "opt.arg.path", "opt.classpath"), new Option(CP, "opt.arg.path", "opt.classpath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-classpath", arg);
        }
    }, new COption(CEYLONCWD, "opt.arg.path", "opt.ceyloncwd"), new COption(CEYLONREPO, "opt.arg.url", "opt.ceylonrepo") {

        @Override
        public boolean process(Options options, String option, String arg) {
            if (options != null)
                options.addMulti(CEYLONREPO, arg);
            return false;
        }
    }, new COption(CEYLONSYSTEMREPO, "opt.arg.url", "opt.ceylonsystemrepo"), new COption(CEYLONCACHEREPO, "opt.arg.url", "opt.ceyloncacherepo"), new COption(CEYLONNODEFREPOS, "opt.ceylonnodefrepos"), new COption(CEYLONUSER, "opt.arg.value", "opt.ceylonuser"), new COption(CEYLONPASS, "opt.arg.value", "opt.ceylonpass"), new COption(CEYLONNOOSGI, "opt.ceylonnoosgi"), new COption(CEYLONOSGIPROVIDEDBUNDLES, "opt.arg.value", "opt.ceylonosgiprovidedbundles"), new COption(CEYLONNOPOM, "opt.ceylonnopom"), new COption(CEYLONPACK200, "opt.ceylonpack200"), new COption(CEYLONRESOURCEROOT, "opt.arg.path", "opt.ceylonresourceroot"), new COption(CEYLONDISABLEOPT, "opt.ceylondisableopt"), new COption(CEYLONDISABLEOPT_CUSTOM, "opt.ceylondisableopt.suboptlist"), new COption(CEYLONSUPPRESSWARNINGS, "opt.arg.value", "opt.ceylonsuppresswarnings"), new Option(SOURCEPATH, "opt.arg.path", "opt.sourcepath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            if (options != null)
                options.addMulti(SOURCEPATH, arg);
            return false;
        }
    }, new COption(CEYLONSOURCEPATH, "opt.arg.directory", "opt.ceylonsourcepath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            if (options != null)
                options.addMulti(SOURCEPATH, arg);
            return false;
        }
    }, new COption(CEYLONRESOURCEPATH, "opt.arg.url", "opt.ceylonresourcepath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            if (options != null)
                options.addMulti(CEYLONRESOURCEPATH, arg);
            return false;
        }
    }, new Option(BOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            options.remove("-Xbootclasspath/p:");
            options.remove("-Xbootclasspath/a:");
            return super.process(options, option, arg);
        }
    }, new XOption(XBOOTCLASSPATH_PREPEND, "opt.arg.path", "opt.Xbootclasspath.p"), new XOption(XBOOTCLASSPATH_APPEND, "opt.arg.path", "opt.Xbootclasspath.a"), new XOption(XBOOTCLASSPATH, "opt.arg.path", "opt.bootclasspath") {

        @Override
        public boolean process(Options options, String option, String arg) {
            options.remove("-Xbootclasspath/p:");
            options.remove("-Xbootclasspath/a:");
            return super.process(options, "-bootclasspath", arg);
        }
    }, new Option(EXTDIRS, "opt.arg.dirs", "opt.extdirs"), new XOption(DJAVA_EXT_DIRS, "opt.arg.dirs", "opt.extdirs") {

        @Override
        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-extdirs", arg);
        }
    }, new Option(ENDORSEDDIRS, "opt.arg.dirs", "opt.endorseddirs"), new XOption(DJAVA_ENDORSED_DIRS, "opt.arg.dirs", "opt.endorseddirs") {

        @Override
        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-endorseddirs", arg);
        }
    }, new Option(PROC, "opt.proc.none.only", Option.ChoiceKind.ONEOF, "none", "only"), new Option(PROCESSOR, "opt.arg.class.list", "opt.processor"), new Option(PROCESSORPATH, "opt.arg.path", "opt.processorpath"), new Option(D, "opt.arg.directory", "opt.d"), new COption(CEYLONOUT, "opt.arg.url", "opt.ceylonout") {

        @Override
        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-d", arg);
        }
    }, new COption(CEYLONOFFLINE, "opt.ceylonoffline"), new COption(CEYLONTIMEOUT, "opt.arg.number", "opt.ceylontimeout"), new COption(CEYLONCONTINUE, "opt.ceyloncontinue"), new COption(CEYLONPROGRESS, "opt.ceylonprogress"), new COption(CEYLONAUTOEXPORTMAVENDEPENDENCIES, "opt.ceylonautoexportmavendependencies"), new COption(CEYLONFLATCLASSPATH, "opt.ceylonflatclasspath"), new COption(CEYLONOVERRIDES, "opt.arg.url", "opt.ceylonoverrides"), // backwards-compat
    new COption(CEYLONMAVENOVERRIDES, "opt.arg.url", "opt.ceylonoverrides") {

        @Override
        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-overrides", arg);
        }
    }, new Option(S, "opt.arg.directory", "opt.sourceDest"), new Option(IMPLICIT, "opt.implicit", Option.ChoiceKind.ONEOF, "none", "class"), new Option(ENCODING, "opt.arg.encoding", "opt.encoding") {

        @Override
        public boolean process(Options options, String option, String operand) {
            try {
                Charset.forName(operand);
                options.put(option, operand);
                return false;
            } catch (UnsupportedCharsetException e) {
                helper.error("err.unsupported.encoding", operand);
                return true;
            } catch (IllegalCharsetNameException e) {
                helper.error("err.unsupported.encoding", operand);
                return true;
            }
        }
    }, new Option(SOURCE, "opt.arg.release", "opt.source") {

        @Override
        public boolean process(Options options, String option, String operand) {
            Source source = Source.lookup(operand);
            if (source == null) {
                helper.error("err.invalid.source", operand);
                return true;
            }
            return super.process(options, option, operand);
        }
    }, new Option(TARGET, "opt.arg.release", "opt.target") {

        @Override
        public boolean process(Options options, String option, String operand) {
            Target target = Target.lookup(operand);
            if (target == null) {
                helper.error("err.invalid.target", operand);
                return true;
            }
            return super.process(options, option, operand);
        }
    }, new COption(VERSION, "opt.version") {

        @Override
        public boolean process(Options options, String option) {
            helper.printVersion();
            return super.process(options, option);
        }
    }, new HiddenOption(FULLVERSION) {

        @Override
        public boolean process(Options options, String option) {
            helper.printFullVersion();
            return super.process(options, option);
        }
    }, new HiddenOption(DIAGS) {

        @Override
        public boolean process(Options options, String option) {
            Option xd = getOptions(helper, EnumSet.of(XD))[0];
            option = option.substring(option.indexOf('=') + 1);
            String diagsOption = option.contains("%") ? "-XDdiagsFormat=" : "-XDdiags=";
            diagsOption += option;
            if (xd.matches(diagsOption))
                return xd.process(options, diagsOption);
            else
                return false;
        }
    }, new COption(HELP, "opt.help") {

        @Override
        public boolean process(Options options, String option) {
            helper.printHelp();
            return super.process(options, option);
        }
    }, new Option(A, "opt.arg.key.equals.value", "opt.A") {

        @Override
        String helpSynopsis() {
            hasSuffix = true;
            return super.helpSynopsis();
        }

        @Override
        public boolean matches(String arg) {
            return arg.startsWith("-A");
        }

        @Override
        public boolean hasArg() {
            return false;
        }

        // Mapping for processor options created in
        // JavacProcessingEnvironment
        @Override
        public boolean process(Options options, String option) {
            int argLength = option.length();
            if (argLength == 2) {
                helper.error("err.empty.A.argument");
                return true;
            }
            int sepIndex = option.indexOf('=');
            String key = option.substring(2, (sepIndex != -1 ? sepIndex : argLength));
            if (!JavacProcessingEnvironment.isValidOptionName(key)) {
                helper.error("err.invalid.A.key", option);
                return true;
            }
            return process(options, option, option);
        }
    }, new Option(X, "opt.X") {

        @Override
        public boolean process(Options options, String option) {
            helper.printXhelp();
            return super.process(options, option);
        }
    }, // It's actually implemented by the launcher.
    new Option(J, "opt.arg.flag", "opt.J") {

        @Override
        String helpSynopsis() {
            hasSuffix = true;
            return super.helpSynopsis();
        }

        @Override
        public boolean process(Options options, String option) {
            throw new AssertionError("the -J flag should be caught by the launcher.");
        }
    }, // new Option("-moreinfo",                                      "opt.moreinfo") {
    new HiddenOption(MOREINFO) {

        @Override
        public boolean process(Options options, String option) {
            Type.moreInfo = true;
            return super.process(options, option);
        }
    }, // treat warnings as errors
    new Option(WERROR, "opt.Werror"), new Option(SRC, "opt.arg.src", "opt.src") {

        public boolean process(Options options, String option, String arg) {
            return super.process(options, "-src", arg);
        }
    }, // use complex inference from context in the position of a method call argument
    new HiddenOption(COMPLEXINFERENCE), // new Option("-prompt",                                        "opt.prompt"),
    new HiddenOption(PROMPT), // dump stack on error
    new HiddenOption(DOE), // new Option("-s",                                     "opt.s"),
    new HiddenOption(PRINTSOURCE), // allow us to compile ceylon.language
    new HiddenOption(BOOTSTRAPCEYLON), // display warnings for generic unchecked operations
    new HiddenOption(WARNUNCHECKED) {

        @Override
        public boolean process(Options options, String option) {
            options.put("-Xlint:unchecked", option);
            return false;
        }
    }, new XOption(XMAXERRS, "opt.arg.number", "opt.maxerrs"), new XOption(XMAXWARNS, "opt.arg.number", "opt.maxwarns"), new XOption(XSTDOUT, "opt.arg.file", "opt.Xstdout") {

        @Override
        public boolean process(Options options, String option, String arg) {
            try {
                helper.setOut(new PrintWriter(new FileWriter(arg), true));
            } catch (java.io.IOException e) {
                helper.error("err.error.writing.file", arg, e);
                return true;
            }
            return super.process(options, option, arg);
        }
    }, new XOption(XPRINT, "opt.print"), new XOption(XPRINTROUNDS, "opt.printRounds"), new XOption(XPRINTPROCESSORINFO, "opt.printProcessorInfo"), new XOption(XPREFER, "opt.prefer", Option.ChoiceKind.ONEOF, "source", "newer"), new XOption(XPKGINFO, "opt.pkginfo", Option.ChoiceKind.ONEOF, "always", "legacy", "nonempty"), /* -O is a no-op, accepted for backward compatibility. */
    new HiddenOption(O), /* -Xjcov produces tables to support the code coverage tool jcov. */
    new HiddenOption(XJCOV), /* This is a back door to the compiler's option table.
         * -XDx=y sets the option x to the value y.
         * -XDx sets the option x to the value x.
         */
    new HiddenOption(XD) {

        String s;

        @Override
        public boolean matches(String s) {
            this.s = s;
            return s.startsWith(name.optionName);
        }

        @Override
        public boolean process(Options options, String option) {
            s = s.substring(name.optionName.length());
            int eq = s.indexOf('=');
            String key = (eq < 0) ? s : s.substring(0, eq);
            String value = (eq < 0) ? s : s.substring(eq + 1);
            options.put(key, value);
            return false;
        }
    }, // It's actually implemented by the CommandLine class.
    new Option(AT, "opt.arg.file", "opt.AT") {

        @Override
        String helpSynopsis() {
            hasSuffix = true;
            return super.helpSynopsis();
        }

        @Override
        public boolean process(Options options, String option) {
            throw new AssertionError("the @ flag should be caught by CommandLine.");
        }
    }, /*
         * TODO: With apt, the matches method accepts anything if
         * -XclassAsDecls is used; code elsewhere does the lookup to
         * see if the class name is both legal and found.
         *
         * In apt, the process method adds the candidate class file
         * name to a separate list.
         */
    new HiddenOption(SOURCEFILE) {

        String s;

        @Override
        public boolean matches(String s) {
            this.s = s;
            return // Java source file
            s.endsWith(".java") || // FIXME: Should be a FileManager query
            s.endsWith(".ceylon") || // FIX for ceylon because default is not a valid name for Java
            "default".equals(s) || // Legal type name for Ceylon
            isCeylonName(s) || // Possibly a resource file
            (new File(s)).isFile();
        }

        @Override
        public boolean process(Options options, String option) {
            File f = new File(s);
            if (s.endsWith(".java") || // FIXME: Should be a FileManager query
            s.endsWith(".ceylon")) {
                // Most likely a source file
                if (!f.isFile()) {
                    // -sourcepath not -src because the COption for 
                    // CEYLONSOURCEPATH puts it in the options map as -sourcepath
                    List<String> sourcePaths = options.getMulti("-sourcepath");
                    if (sourcePaths.isEmpty())
                        sourcePaths = FileUtil.filesToPathList(DefaultToolOptions.getCompilerSourceDirs());
                    if (checkIfModule(sourcePaths, s)) {
                        // A Ceylon module name that ends with .ceylon or .java
                        helper.addClassName(s);
                        return false;
                    }
                    if (f.exists()) {
                        helper.error("err.file.not.file", f);
                        return true;
                    }
                }
                if (!f.exists()) {
                    helper.error("err.file.not.found", f);
                    return true;
                }
                helper.addFile(f);
            }
            if (f.isFile()) {
                // Most likely a resource file
                helper.addFile(f);
            } else {
                // the default module is always allowed, it doesn't need to have any folder
                if (s.equals(Module.DEFAULT_MODULE_NAME)) {
                    helper.addClassName(s);
                    return false;
                }
                // find a corresponding physical module in the source path
                List<String> sourcePaths = options.getMulti("-sourcepath");
                if (sourcePaths.isEmpty())
                    sourcePaths = FileUtil.filesToPathList(DefaultToolOptions.getCompilerSourceDirs());
                if (checkIfModule(sourcePaths, s)) {
                    helper.addClassName(s);
                    return false;
                }
                String paths = sourcePaths.toString();
                helper.error("err.module.not.found", s, paths.substring(1, paths.length() - 1));
                return true;
            }
            return false;
        }

        private boolean checkIfModule(List<String> paths, String moduleName) {
            String moduleDirName = moduleName.replace(".", File.separator);
            // walk every path arg
            for (String path : paths) {
                // split the path
                for (String part : path.split("\\" + File.pathSeparator)) {
                    // try to see if it's a module folder
                    File moduleFolder = new File(part, moduleDirName);
                    if (moduleFolder.isDirectory()) {
                        return true;
                    }
                }
            }
            return false;
        }
    } };
}
Also used : DefaultToolOptions(com.redhat.ceylon.common.config.DefaultToolOptions) Options(com.sun.tools.javac.util.Options) FileWriter(java.io.FileWriter) COption(com.sun.tools.javac.main.JavacOption.COption) Source(com.sun.tools.javac.code.Source) Lint(com.sun.tools.javac.code.Lint) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) StringTokenizer(java.util.StringTokenizer) Target(com.sun.tools.javac.jvm.Target) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Option(com.sun.tools.javac.main.JavacOption.Option) HiddenOption(com.sun.tools.javac.main.JavacOption.HiddenOption) COption(com.sun.tools.javac.main.JavacOption.COption) XOption(com.sun.tools.javac.main.JavacOption.XOption) List(java.util.List) HiddenOption(com.sun.tools.javac.main.JavacOption.HiddenOption) File(java.io.File) XOption(com.sun.tools.javac.main.JavacOption.XOption) PrintWriter(java.io.PrintWriter)

Example 19 with Options

use of com.sun.tools.javac.util.Options in project ceylon-compiler by ceylon.

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(com.sun.tools.javac.util.Options)

Aggregations

Options (com.sun.tools.javac.util.Options)19 Context (com.sun.tools.javac.util.Context)8 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)4 DefaultToolOptions (com.redhat.ceylon.common.config.DefaultToolOptions)3 JavacOption (com.sun.tools.javac.main.JavacOption)3 RecognizedOptions (com.sun.tools.javac.main.RecognizedOptions)3 File (java.io.File)3 IOException (java.io.IOException)3 ListBuffer (com.sun.tools.javac.util.ListBuffer)2 FileNotFoundException (java.io.FileNotFoundException)2 CeylonConfig (com.redhat.ceylon.common.config.CeylonConfig)1 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)1 Main (com.redhat.ceylon.compiler.java.launcher.Main)1 Lint (com.sun.tools.javac.code.Lint)1 Source (com.sun.tools.javac.code.Source)1 Target (com.sun.tools.javac.jvm.Target)1 JavaCompiler (com.sun.tools.javac.main.JavaCompiler)1 COption (com.sun.tools.javac.main.JavacOption.COption)1 HiddenOption (com.sun.tools.javac.main.JavacOption.HiddenOption)1 Option (com.sun.tools.javac.main.JavacOption.Option)1