Search in sources :

Example 6 with Source

use of com.sun.tools.javac.code.Source in project ceylon-compiler by ceylon.

the class Main method processArgs.

/**
 * Process command line arguments: store all command line options
 *  in `options' table and return all source filenames.
 *  @param flags    The array of command line arguments.
 */
public List<File> processArgs(String[] flags) {
    // XXX sb protected
    int ac = 0;
    while (ac < flags.length) {
        String flag = flags[ac];
        ac++;
        Option option = null;
        if (flag.length() > 0) {
            // quick hack to speed up file processing:
            // if the option does not begin with '-', there is no need to check
            // most of the compiler options.
            int firstOptionToCheck = flag.charAt(0) == '-' ? 0 : recognizedOptions.length - 1;
            for (int j = firstOptionToCheck; j < recognizedOptions.length; j++) {
                if (recognizedOptions[j].matches(flag)) {
                    option = recognizedOptions[j];
                    break;
                }
            }
        }
        if (option == null) {
            error("err.invalid.flag", flag);
            return null;
        }
        if (option.hasArg()) {
            if (ac == flags.length) {
                error("err.req.arg", flag);
                return null;
            }
            String operand = flags[ac];
            ac++;
            if (option.process(options, flag, operand))
                return null;
        } else {
            if (option.process(options, flag))
                return null;
        }
    }
    if (!checkDirectory(D))
        return null;
    if (!checkDirectory(S))
        return null;
    String sourceString = options.get(SOURCE);
    Source source = (sourceString != null) ? Source.lookup(sourceString) : Source.DEFAULT;
    String targetString = options.get(TARGET);
    Target target = (targetString != null) ? Target.lookup(targetString) : Target.DEFAULT;
    // prototype.
    if (Character.isDigit(target.name.charAt(0))) {
        if (target.compareTo(source.requiredTarget()) < 0) {
            if (targetString != null) {
                if (sourceString == null) {
                    warning("warn.target.default.source.conflict", targetString, source.requiredTarget().name);
                } else {
                    warning("warn.source.target.conflict", sourceString, source.requiredTarget().name);
                }
                return null;
            } else {
                target = source.requiredTarget();
                options.put("-target", target.name);
            }
        } else {
            if (targetString == null && !source.allowGenerics()) {
                target = Target.JDK1_4;
                options.put("-target", target.name);
            }
        }
    }
    // handle this here so it works even if no other options given
    String showClass = options.get("showClass");
    if (showClass != null) {
        if (// no value given for option
        showClass.equals("showClass"))
            showClass = "com.sun.tools.javac.Main";
        showClass(showClass);
    }
    return filenames.toList();
}
Also used : Target(com.sun.tools.javac.jvm.Target) Option(com.sun.tools.javac.main.JavacOption.Option) Source(com.sun.tools.javac.code.Source)

Aggregations

Source (com.sun.tools.javac.code.Source)6 Target (com.sun.tools.javac.jvm.Target)4 Option (com.sun.tools.javac.main.JavacOption.Option)3 DefaultToolOptions (com.redhat.ceylon.common.config.DefaultToolOptions)1 Lint (com.sun.tools.javac.code.Lint)1 COption (com.sun.tools.javac.main.JavacOption.COption)1 HiddenOption (com.sun.tools.javac.main.JavacOption.HiddenOption)1 XOption (com.sun.tools.javac.main.JavacOption.XOption)1 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)1 Context (com.sun.tools.javac.util.Context)1 DiagnosticSource (com.sun.tools.javac.util.DiagnosticSource)1 Log (com.sun.tools.javac.util.Log)1 Options (com.sun.tools.javac.util.Options)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1