001package de.monochromata.anaphors.ast.spi;
002
003import de.monochromata.anaphors.ast.ASTBasedAnaphora;
004import de.monochromata.anaphors.ast.relatedexp.RelatedExpression;
005import de.monochromata.anaphors.ast.transform.ASTTransformation;
006
007/**
008 * An interface to create AST transformations.
009 *
010 * @param <N>  The node type in the AST
011 * @param <E>  The expression type
012 * @param <T>  The type type
013 * @param <B>  The binding type
014 * @param <TB> The type binding type
015 * @param <S>  The scope type (optional)
016 * @param <I>  The type used to represent identifiers
017 * @param <QI> The type used to represent qualified identifiers
018 * @param <R>  The sub-type of related expression to use
019 * @param <A>  The sub-type of AST-based anaphora to use
020 */
021public interface TransformationsSpi<N, E, T, B, TB extends B, S, I, QI, R extends RelatedExpression<N, T, B, TB, S, QI, R>, A extends ASTBasedAnaphora<N, E, T, B, TB, S, I, QI, R, A>> {
022
023        /**
024         * @return {@literal true} if both nodes are contained in or are the same
025         *         invocable (i.e. initializer, constructor, method or lambda
026         *         expression).
027         */
028        public boolean partOfSameInvocable(N node, E expression);
029
030        /**
031         * Attempts to create a transformation that pass the given upstream node or a
032         * representation of it along the call chain from the invocable (i.e.
033         * initializer, constructor, method or lambda expression) containing the
034         * upstream node to the invocable containing the downstream node.
035         * <p>
036         * Such a transformation can only be constructed if there is a call chain
037         * connecting upstream and downstream nodes and if the chain is no longer than
038         * the implementation-specific analysis limits of the SPI implementation.
039         *
040         * @return a transformation if it can be constructed, or {@literal null}
041         *         otherwise.
042         */
043        public ASTTransformation<N, E, T, B, TB, S, I, QI, R, A> passAlongCallChain(N upstreamNode, E downstreamExpression,
044                        S scope);
045
046}