package org.metaborg.core.processing.parse;

import org.apache.commons.vfs2.FileObject;
import org.metaborg.core.language.ILanguageImpl;
import org.metaborg.core.syntax.IParseUnit;
import org.metaborg.core.syntax.ParseException;

/**
 * Interface for updating parse results which are requested by an {@link IParseResultRequester}.
 */
public interface IParseResultUpdater<P extends IParseUnit> {
    /**
     * Invalidates the parse result for given resource. Must be followed by a call to {@link #update} or {@link #error}
     * for that resource eventually. Failing to do so will block any request made while resource was in an invalid
     * state.
     * 
     * @param resource
     *            Resource to invalidate.
     */
    void invalidate(FileObject resource);

    /**
     * Invalidates the parse result for all sources of the given language. Must be followed by a call to
     * {@link #update} or {@link #error} for that resource eventually. Failing to do so will block any
     * request made while resource was in an invalid state.
     * 
     * @param lang
     *            Language to invalidate for.
     */
    void invalidate(ILanguageImpl lang);

    /**
     * Updates the parse result for a single resource. Pushes the parse result to subscribed requests.
     * 
     * @param result
     *            Result to update.
     * @param result
     *            Parent of the result to update.
     */
    void update(FileObject resource, P unit);

    /**
     * Sets a parse error for given resource. Pushes the parse error to subscribed requests.
     * 
     * @param resource
     *            Resource to set a parse error for.
     * @param exception
     *            Parse error to set.
     */
    void error(FileObject resource, ParseException exception);

    /**
     * Removes cached parse results for given resource.
     * 
     * @param resource
     *            Resource to remove cached parse results for.
     */
    void remove(FileObject resource);
}