Search in sources :

Example 1 with Option

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

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

the class Main method processArgs.

public Collection<File> processArgs(String[] flags, String[] classNames) {
    // 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(optionHelper, flag, operand))
                return null;
        } else {
            if (option.process(optionHelper, flag))
                return null;
        }
    }
    if (options.get(PROFILE) != null && options.get(BOOTCLASSPATH) != null) {
        error("err.profile.bootclasspath.conflict");
        return null;
    }
    if (this.classnames != null && classNames != null) {
        this.classnames.addAll(Arrays.asList(classNames));
    }
    if (!checkDirectory(D))
        return null;
    if (!checkDirectory(S))
        return null;
    String sourceString = options.get(SOURCE);
    String targetString = options.get(TARGET);
    if (sourceString == null && targetString == null) {
        sourceString = "7";
        options.put(SOURCE, sourceString);
    }
    Source source = (sourceString != null) ? Source.lookup(sourceString) : Source.JDK1_7;
    if (targetString == null) {
        targetString = "7";
        options.put(TARGET, targetString);
    }
    Target target = (targetString != null) ? Target.lookup(targetString) : Target.JDK1_7;
    // 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);
            }
        }
    }
    String profileString = options.get(PROFILE);
    if (profileString != null) {
        Profile profile = Profile.lookup(profileString);
        if (!profile.isValid(target)) {
            warning("warn.profile.target.conflict", profileString, target.name);
            return null;
        }
    }
    // 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 = "org.eclipse.ceylon.langtools.tools.javac.Main";
        showClass(showClass);
    }
    options.notifyListeners();
    return filenames;
}
Also used : Target(org.eclipse.ceylon.langtools.tools.javac.jvm.Target) Option(org.eclipse.ceylon.langtools.tools.javac.main.Option) Source(org.eclipse.ceylon.langtools.tools.javac.code.Source) Profile(org.eclipse.ceylon.langtools.tools.javac.jvm.Profile)

Example 3 with Option

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

the class Locations method initHandlers.

void initHandlers() {
    handlersForLocation = new HashMap<Location, LocationHandler>();
    handlersForOption = new EnumMap<Option, LocationHandler>(Option.class);
    LocationHandler[] handlers = { new BootClassPathLocationHandler(), new ClassPathLocationHandler(), new SimpleLocationHandler(StandardLocation.SOURCE_PATH, Option.SOURCEPATH), new SimpleLocationHandler(CeylonLocation.RESOURCE_PATH, Option.CEYLONRESOURCEPATH) {

        @Override
        boolean handleOption(Option option, String value) {
            if (!options.contains(option) || value == null) {
                List<File> files = DefaultToolOptions.getCompilerResourceDirs(CeylonConfig.get());
                createPath().addFiles(files, warn);
                return true;
            }
            searchPath = value == null ? null : Collections.unmodifiableCollection(createPath().addFiles(value));
            return true;
        }

        @Override
        Collection<File> getLocation() {
            if (searchPath == null) {
                List<File> files = DefaultToolOptions.getCompilerResourceDirs(CeylonConfig.get());
                searchPath = Collections.unmodifiableCollection(createPath().addFiles(files, warn));
            }
            return searchPath;
        }
    }, new SimpleLocationHandler(StandardLocation.ANNOTATION_PROCESSOR_PATH, Option.PROCESSORPATH), new OutputLocationHandler((StandardLocation.CLASS_OUTPUT), Option.D), new OutputLocationHandler((StandardLocation.SOURCE_OUTPUT), Option.S), new OutputLocationHandler((StandardLocation.NATIVE_HEADER_OUTPUT), Option.H) };
    for (LocationHandler h : handlers) {
        handlersForLocation.put(h.location, h);
        for (Option o : h.options) handlersForOption.put(o, h);
    }
}
Also used : Collection(java.util.Collection) Option(org.eclipse.ceylon.langtools.tools.javac.main.Option) List(java.util.List) CeylonLocation(org.eclipse.ceylon.compiler.java.tools.CeylonLocation) Location(org.eclipse.ceylon.javax.tools.JavaFileManager.Location) StandardLocation(org.eclipse.ceylon.javax.tools.StandardLocation)

Example 4 with Option

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

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.
 */
@Override
public Collection<File> processArgs(String[] flags, String[] classNames) {
    int ac = 0;
    while (ac < flags.length) {
        String flag = flags[ac];
        ac++;
        int j;
        // 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 (j = firstOptionToCheck; j < recognizedOptions.length; j++) if (recognizedOptions[j].matches(flag))
            break;
        if (j == recognizedOptions.length) {
            error("err.invalid.flag", flag);
            return null;
        }
        Option option = recognizedOptions[j];
        if (option.hasArg()) {
            if (ac == flags.length) {
                error("err.req.arg", flag);
                return null;
            }
            String operand = flags[ac];
            ac++;
            if (option.process(optionHelper, flag, operand))
                return null;
        } else {
            if (option.process(optionHelper, flag))
                return null;
        }
    }
    if (this.classnames != null && classNames != null) {
        this.classnames.addAll(Arrays.asList(classNames));
    }
    if (!checkDirectoryOrURL("-d"))
        return null;
    if (!checkDirectory("-s"))
        return null;
    String sourceString = options.get("-source");
    String targetString = options.get("-target");
    if (sourceString == null && targetString == null) {
        sourceString = "7";
        options.put(Option.SOURCE, sourceString);
    }
    Source source = (sourceString != null) ? Source.lookup(sourceString) : Source.DEFAULT;
    if (targetString == null) {
        targetString = "7";
        options.put(Option.TARGET, targetString);
    }
    Target target = (targetString != null) ? Target.lookup(targetString) : Target.JDK1_7;
    // 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 {
                options.put("-target", source.requiredTarget().name);
            }
        } else {
            if (targetString == null && !source.allowGenerics()) {
                options.put("-target", Target.JDK1_4.name);
            }
        }
    }
    return filenames;
}
Also used : Target(org.eclipse.ceylon.langtools.tools.javac.jvm.Target) Option(org.eclipse.ceylon.langtools.tools.javac.main.Option) Source(org.eclipse.ceylon.langtools.tools.javac.code.Source)

Aggregations

Option (org.eclipse.ceylon.langtools.tools.javac.main.Option)4 Source (org.eclipse.ceylon.langtools.tools.javac.code.Source)2 Target (org.eclipse.ceylon.langtools.tools.javac.jvm.Target)2 Collection (java.util.Collection)1 List (java.util.List)1 CeylonLocation (org.eclipse.ceylon.compiler.java.tools.CeylonLocation)1 Location (org.eclipse.ceylon.javax.tools.JavaFileManager.Location)1 StandardLocation (org.eclipse.ceylon.javax.tools.StandardLocation)1 Profile (org.eclipse.ceylon.langtools.tools.javac.jvm.Profile)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