package accrue.analysis.goals;

import java.io.File;

import polyglot.frontend.EmptyPass;
import polyglot.frontend.ExtensionInfo;
import polyglot.frontend.FileSource;
import polyglot.frontend.Job;
import polyglot.frontend.Pass;
import polyglot.frontend.Scheduler;
import polyglot.frontend.Source;
import polyglot.frontend.goals.Goal;
import accrue.AccrueOptions;

/**
 * Comment for <code>CompileGoal</code>
 *
 * @author nystrom
 */
public class CodeGenerated extends polyglot.frontend.goals.CodeGenerated {
    public static Goal create(Scheduler scheduler, Job job) {
        return scheduler.internGoal(new CodeGenerated(job));
    }

    /**
     * @param job The job to compile.
     */
    protected CodeGenerated(Job job) {
        super(job);
    }

    @Override
    public Pass createPass(ExtensionInfo extInfo) {
        Source s = this.job.source();

        // see if this is a signature file
        // if it is, then don't produce any output
        if (s != null && s instanceof FileSource) {
            FileSource fs = (FileSource) s;
            for (File sigsrc : ((AccrueOptions) extInfo.getOptions()).helper().signatureSourcePath) {
                if (fs.path().startsWith(sigsrc.getPath())) {
                    return new EmptyPass(this);
                }

            }
        }
        return super.createPass(extInfo);
    }

}
