001package de.monochromata.anaphors.ast.spi; 002 003import java.util.List; 004import java.util.Optional; 005import java.util.function.Supplier; 006 007import de.monochromata.anaphors.ast.ASTBasedAnaphora; 008import de.monochromata.anaphors.ast.AnaphorPart; 009import de.monochromata.anaphors.ast.RelatedExpressionPart; 010import de.monochromata.anaphors.ast.relatedexp.RelatedExpression; 011import de.monochromata.anaphors.ast.relatedexp.strategy.LocalTempVariableIntroducingStrategy; 012 013/** 014 * A special service provider interface related to finding potential referents 015 * of a given definite expression in a given 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 <VB> The variable binding type 022 * @param <FB> The field binding type 023 * @param <MB> The method binding type 024 * @param <TB> The type binding type 025 * @param <S> The scope type (optional) 026 * @param <I> The type used to represent identifiers 027 * @param <QI> The type used to represent qualified identifiers 028 * @param <R> The sub-type of related expression to use 029 * @param <A> The sub-type of AST-based anaphora to use 030 */ 031public interface AnaphoraResolutionSpi<N, E, T, B, VB extends B, FB extends B, MB extends 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>> { 032 033 <RP extends RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R>, AP extends AnaphorPart<N, E, T, B, TB, S, I, QI, R, A>> A createDirectAnaphora( 034 final RP relatedExpressionPart, final AP anaphorPart, final boolean isUnderspecified); 035 036 <RP extends RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R>, AP extends AnaphorPart<N, E, T, B, TB, S, I, QI, R, A>> A createIndirectAnaphora( 037 final RP relatedExpressionPart, final AP anaphorPart, final String underspecifiedRelation, 038 final boolean isUnderspecified); 039 040 <RP extends RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R>, AP extends AnaphorPart<N, E, T, B, TB, S, I, QI, R, A>> A createIndirectAnaphora( 041 final RP relatedExpressionPart, final AP anaphorPart, final String underspecifiedRelation, 042 final Supplier<String> customReferenceDescriptionSupplier, final boolean isUnderspecified); 043 044 List<FB> getAccessibleFields(TB typeBinding, S scope); 045 046 I getFieldName(FB fieldBinding); 047 048 boolean identifierStartsUpperCase(I identifier); 049 050 String getFieldDescription(FB fieldBinding); 051 052 TB resolveType(FB fieldBinding, S scope); 053 054 List<MB> getAccessibleGetterMethods(TB typeBinding, S scope); 055 056 boolean doesGetterMethodOnlyReturnValueOf(MB methodBinding, FB fieldBinding, S scope); 057 058 /** 059 * Return a variable name for the given method that removes getter or setter 060 * prefix to the method name and converts the first character of the remaining 061 * string to lower case. 062 * 063 * @param methodBinding The method binding to use. 064 * @return A variable name. 065 */ 066 QI getReferentName(MB methodBinding); 067 068 I getMethodName(MB methodBinding); 069 070 String getMethodDescription(MB methodBinding); 071 072 TB resolveReturnType(MB methodBinding, S scope); 073 074 boolean couldBeAPreviousRealization(E definiteExpression); 075 076 I getIdFromPreviousRealization(E definiteExpression); 077 078 /** 079 * Replace an anaphor of kind DA1Re by an expression that realizes it. 080 * 081 * @param replacee The anaphor to be replaced. 082 * @param guessedTempName If the given related expression part has a 083 * {@link LocalTempVariableIntroducingStrategy}, the 084 * strategy introduced a temporary variable that might be 085 * used by the anaphor resolution strategy to generate 086 * code for the anaphors. 087 * @param support Optional compiler-specific support objects. 088 * @return The AST node that realizes the anaphor. 089 */ 090 E realizeDA1Re(RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R> relatedExpressionPart, 091 AnaphorPart<N, E, T, B, TB, S, I, QI, R, A> anaphorPart, E replacee, Optional<I> guessedTempName, 092 Object... support); 093 094 E realizeIA1Mr(RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R> relatedExpressionPart, 095 AnaphorPart<N, E, T, B, TB, S, I, QI, R, A> anaphorPart, E replacee, Optional<I> guessedTempName, 096 Object[] support); 097 098 /** 099 * Replace an anaphor of kind IA2F by an expression that realizes it. 100 * 101 * @param replacee The anaphor to be replaced. 102 * @param guessedTempName If the given related expression part has a 103 * {@link LocalTempVariableIntroducingStrategy}, the 104 * strategy introduced a temporary variable that might be 105 * used by the anaphor resolution strategy to generate 106 * code for the anaphors. 107 * @param support Optional compiler-specific support objects. 108 * @return The AST node that realizes the anaphor. 109 */ 110 E realizeIA2F(RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R> relatedExpressionPart, 111 AnaphorPart<N, E, T, B, TB, S, I, QI, R, A> anaphorPart, E replacee, Optional<I> guessedTempName, 112 Object... support); 113 114 /** 115 * Replace an anaphor of kind IA2Mg by an expression that realizes it. 116 * 117 * @param replacee The anaphor to be replaced. 118 * @param guessedTempName If the given related expression part has a 119 * {@link LocalTempVariableIntroducingStrategy}, the 120 * strategy introduced a temporary variable that might be 121 * used by the anaphor resolution strategy to generate 122 * code for the anaphors. 123 * @param support Optional compiler-specific support objects. 124 * @return The AST node that realizes the anaphor. 125 */ 126 E realizeIA2Mg(RelatedExpressionPart<N, E, T, B, TB, S, I, QI, R> relatedExpressionPart, 127 AnaphorPart<N, E, T, B, TB, S, I, QI, R, A> anaphorPart, E replacee, Optional<I> guessedTempName, 128 Object... support); 129 130 String getIA1MrUnderspecifiedRelation(R potentialRelatedExpression, MB methodBinding, S scope); 131 132 /** 133 * Returns the underspecified relation represented by an indirect anaphora 134 * relation of kind IA2F in the format 135 * <code><fully-qualified name of field declaring type>.<fieldName></code> 136 * . 137 * 138 * @param relatedExpression The related expression whose type declares the 139 * underspecified relation. 140 * @param fieldBinding The field that is part of the underspecified 141 * relation. 142 * @param scope The scope containing the anaphor if used by the 143 * compiler-specific implementation. 144 * @return A string representing the underspecified relation. 145 */ 146 String getIA2FUnderspecifiedRelation(R relatedExpression, FB fieldBinding, S scope); 147 148 String getIA2MgUnderspecifiedRelation(R relatedExpression, MB methodBinding, S scope); 149 150}