001package de.monochromata.anaphors.cog.transform; 002 003import de.monochromata.anaphors.ast.ASTBasedAnaphora; 004import de.monochromata.anaphors.ast.relatedexp.RelatedExpression; 005import de.monochromata.anaphors.ast.spi.TransformationsSpi; 006 007/** 008 * @param <N> The node type in the AST 009 * @param <E> The expression type 010 * @param <T> The type type 011 * @param <B> The binding type 012 * @param <TB> The type binding type 013 * @param <S> The scope type (optional) 014 * @param <I> The type used to represent identifiers 015 * @param <QI> The type used to represent qualified identifiers 016 * @param <R> The sub-type of related expression to use 017 * @param <A> The sub-type of AST-based anaphora to use 018 */ 019public abstract class AbstractPreparatoryTransformation<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>> 020 implements PreparatoryTransformation<N, E, T, B, TB, S, I, QI, R, A> { 021 022 protected final TransformationsSpi<N, E, T, B, TB, S, I, QI, R, A> transformationsSpi; 023 024 /** 025 * Used in contract testing. 026 */ 027 @SuppressWarnings("unused") 028 protected AbstractPreparatoryTransformation() { 029 this(null); 030 } 031 032 public AbstractPreparatoryTransformation( 033 final TransformationsSpi<N, E, T, B, TB, S, I, QI, R, A> transformationsSpi) { 034 this.transformationsSpi = transformationsSpi; 035 } 036 037 protected void requireSuccessfulCheck(final CheckResult<N, E, S> result) { 038 if (!result.canPerformTransformation()) { 039 throw new IllegalArgumentException("Only results of successful checks may be passed"); 040 } 041 } 042 043 protected <C extends CheckResult<N, E, S>> void requireInstanceOf(final CheckResult<N, E, S> result, 044 final Class<C> clazz) { 045 if (!clazz.isInstance(result)) { 046 throw new IllegalArgumentException("Instance of " + clazz.getName() + " required"); 047 } 048 } 049 050}