package org.metaborg.spoofax.core.stratego;

import java.io.File;

import org.apache.commons.vfs2.FileObject;
import org.metaborg.core.MetaborgException;
import org.metaborg.core.context.IContext;
import org.metaborg.core.language.ILanguageComponent;
import org.metaborg.core.language.ILanguageImpl;
import org.spoofax.interpreter.terms.IStrategoString;
import org.spoofax.interpreter.terms.IStrategoTerm;
import org.strategoxt.HybridInterpreter;

public interface IStrategoCommon {
    /**
     * Invokes a Stratego strategy in given component.
     *
     * @param component
     *            Component to invoke the strategy in.
     * @param context
     *            Context to initialize the runtime with.
     * @param input
     *            Input term
     * @param strategy
     *            Name of the strategy to call.
     * @return Resulting term, or null if the strategy failed.
     * @throws MetaborgException
     *             When an error occurs getting a Stratego runtime.
     * @throws MetaborgException
     *             When invoking the strategy fails unexpectedly.
     */
    IStrategoTerm invoke(ILanguageComponent component, IContext context, IStrategoTerm input, String strategy)
        throws MetaborgException;

    /**
     * Invokes a Stratego strategy in components of given language implementation. Returns the first result that
     * succeeds.
     *
     * @param impl
     *            Language implementation to invoke the strategy in.
     * @param context
     *            Context to initialize the runtime with.
     * @param input
     *            Input term
     * @param strategy
     *            Name of the strategy to call.
     * @return Resulting term, or null if the strategy failed.
     * @throws MetaborgException
     *             When an error occurs getting a Stratego runtime.
     * @throws MetaborgException
     *             When invoking the strategy fails unexpectedly.
     */
    IStrategoTerm invoke(ILanguageImpl impl, IContext context, IStrategoTerm input, String strategy)
        throws MetaborgException;

    /**
     * Invokes a Stratego strategy in components of given language implementation. Returns the first result that
     * succeeds.
     *
     * @param impl
     *            Language implementation to invoke the strategy in.
     * @param location
     *            Location to initialize the Stratego runtime with.
     * @param input
     *            Input term
     * @param strategy
     *            Name of the strategy to call.
     * @return Resulting term, or null if the strategy failed.
     * @throws MetaborgException
     *             When an error occurs getting a Stratego runtime.
     * @throws MetaborgException
     *             When invoking the strategy fails unexpectedly.
     */
    IStrategoTerm invoke(ILanguageImpl impl, FileObject location, IStrategoTerm input, String strategy)
        throws MetaborgException;

    /**
     * Invokes a Strategy strategy in given runtime.
     * 
     * @param runtime
     *            Stratego runtime to invoke the strategy in.
     * @param input
     *            Input term
     * @param strategy
     *            Name of the strategy to call.
     * @return Resulting term, or null if the strategy failed.
     * @throws MetaborgException
     *             When invoking the strategy fails unexpectedly.
     */
    IStrategoTerm invoke(HybridInterpreter runtime, IStrategoTerm input, String strategy) throws MetaborgException;

    /**
     * Converts a location into a Stratego string.
     * 
     * @param localLocation
     *            Location to convert.
     * @return Stratego string with location.
     */
    IStrategoString localLocationTerm(File localLocation);

    /**
     * Converts a resource relative to a location into a Stratego string.
     * 
     * @param localResource
     *            Resource to convert.
     * @param localLocation
     *            Location to convert relative to.
     * @return Stratego string with resource.
     */
    IStrategoString localResourceTerm(File localResource, File localLocation);

    /**
     * Creates an input term for a builder.
     * 
     * @param ast
     *            Term to use as the AST.
     * @param resource
     *            Location of the input resource.
     * @param location
     *            Location of the input context.
     * @return A 5-tuple input term (selected, position, ast, path, project-path).
     * @throws MetaborgException
     *             When {@code resource} or {@code location} do not reside on the local file system.
     */
    IStrategoTerm builderInputTerm(IStrategoTerm ast, FileObject resource, FileObject location)
        throws MetaborgException;

    /**
     * Turns given term into a string. If the term is a string, return the string. Otherwise, return a pretty-printed
     * term.
     * 
     * @param term
     *            Term to convert to a string.
     * @return Result as a string.
     */
    String toString(IStrategoTerm term);

    /**
     * Pretty prints an ATerm.
     * 
     * @param term
     *            ATerm to pretty print.
     * @return Pretty printed ATerm as a Stratego string.
     */
    IStrategoString prettyPrint(IStrategoTerm term);
}

@@ -60,16 +60,51 @@
 .File;%0A%0A
+import javax.annotation.Nullable;%0A%0A
 import o
@@ -138,16 +138,16 @@
 Object;%0A
-
 import o
@@ -1127,32 +1127,42 @@
 ly.%0A     */%0A    
+@Nullable 
 IStrategoTerm in
@@ -1987,32 +1987,42 @@
 ly.%0A     */%0A    
+@Nullable 
 IStrategoTerm in
@@ -2848,32 +2848,42 @@
 ly.%0A     */%0A    
+@Nullable 
 IStrategoTerm in
@@ -3440,32 +3440,42 @@
 ly.%0A     */%0A    
+@Nullable 
 IStrategoTerm in
@@ -3543,16 +3543,24 @@
 trategy)
+%0A       
  throws 

Fix missing nullable annotations.