package accrue.jl5;

import java.util.Set;

import accrue.AccrueExtensionInfo;
import accrue.AccrueOptions;
import accrue.AccrueOptionsHelper;

import polyglot.ext.jl5.JL5Options;
import polyglot.frontend.ExtensionInfo;
import polyglot.main.OptFlag;
import polyglot.main.OptFlag.Arg;
import polyglot.main.UsageError;

/**
 * Polyglot options for an object sensitive analysis
 */
public class AccrueJL5Options extends JL5Options implements AccrueOptions {
    protected AccrueOptionsHelper helper;

    public AccrueJL5Options(ExtensionInfo extension) {
        super(extension);
    }

    public AccrueOptionsHelper helper() {
        if (this.helper == null) {
            this.helper = new AccrueOptionsHelper();
        }
        return this.helper;
    }

    @Override
    protected void populateFlags(Set<OptFlag<?>> flags) {
        super.populateFlags(flags);
        helper().populateFlags(flags);

    }

    @Override
    protected void handleArg(Arg<?> arg) throws UsageError {
        if (helper().handleArg(arg)) {
            // the helper was able to handle the argument.
            return;
        }
        super.handleArg(arg);
    }

    @Override
    protected void validateArgs() throws UsageError {
        AccrueExtensionInfo extInfo = (AccrueExtensionInfo) this.extension;
        if (extInfo.isOutputExtensionInfo()) {
            // if we are an output extension info, then
            // skip the validation
            return;
        }
        super.validateArgs();
    }

}
