001package de.monochromata.anaphors.ast.relatedexp.strategy; 002 003import static java.util.Collections.emptyList; 004 005import java.util.List; 006 007import org.apache.commons.lang3.tuple.Pair; 008 009import de.monochromata.anaphors.ast.relatedexp.RelatedExpression; 010import de.monochromata.anaphors.ast.spi.RelatedExpressionsSpi; 011import de.monochromata.anaphors.perspectivation.Perspectivation; 012import de.monochromata.anaphors.preferences.Preferences; 013 014/** 015 * Parameter declarations functioning as related expression. 016 * 017 * @param <N> The node type in the AST 018 * @param <E> The expression type 019 * @param <T> The type type 020 * @param <B> The binding type 021 * @param <MB> The method binding type 022 * @param <TB> The type binding type 023 * @param <S> The scope type (optional) 024 * @param <I> The type used to represent identifiers 025 * @param <QI> The type used to represent qualified identifiers 026 * @param <EV> The type of the event contained in the condition that is 027 * evaluated to check when the perspectivations shall be applied. 028 * @param <PP> The type used for positions that carry perspectivations 029 * @param <R> The sub-type of related expression to use 030 */ 031public class ParameterDeclarationStrategy<N, E, T, B, MB extends B, TB extends B, S, I, QI, EV, PP, R extends RelatedExpression<N, T, B, TB, S, QI, R>> 032 extends AbstractRelatedExpressionStrategy<N, E, T, B, MB, TB, S, I, QI, EV, PP, R> { 033 034 public static final String PD_KIND = "PD"; 035 036 /** 037 * Used in contract testing. 038 */ 039 @SuppressWarnings("unused") 040 protected ParameterDeclarationStrategy() { 041 } 042 043 public ParameterDeclarationStrategy( 044 final RelatedExpressionsSpi<N, E, T, B, MB, TB, S, I, QI, EV, PP, R> relatedExpressionsSpi, 045 final Preferences preferences) { 046 super(relatedExpressionsSpi, preferences); 047 } 048 049 @Override 050 public String getKind() { 051 return PD_KIND; 052 } 053 054 /** 055 * Anaphoras related to parameters are realized as related to that parameter 056 * without introducing another local variable. 057 */ 058 @Override 059 public String getKindOfRelatedExpressionToBeRealized() { 060 return getKind(); 061 } 062 063 @Override 064 public List<Perspectivation> underspecifyRelatedExpression(final R relatedExpression, 065 final List<Pair<LocalTempVariableContents, String>> variableContentsAndAnaphors, final S scope) { 066 // No perspectivation necessary 067 return emptyList(); 068 } 069 070 protected boolean refersToSameAstNode(final R thisInstance, final R otherInstance) { 071 return thisInstance.equals(otherInstance) 072 && thisInstance.getRelatedExpression() == otherInstance.getRelatedExpression(); 073 } 074}