001package de.monochromata.ast; 002 003import java.util.Set; 004 005/** 006 * A special service provider interface to perform actions related to finding 007 * and processing related expressions. 008 * 009 * @param <N> The node type in the AST 010 * @param <E> The expression type The class instance creation expression node 011 * type 012 * @param <T> The type type 013 * @param <B> The binding type 014 * @param <MB> The method binding type 015 * @param <TB> The type binding type 016 * @param <S> The scope type (optional) 017 * @param <I> The type used to represent identifiers 018 * @param <QI> The type used to represent qualified identifiers 019 * @param <EV> The type of the event contained in the condition that is 020 * evaluated to check when the perspectivations shall be applied. 021 * @param <PP> The type used for positions that carry perspectivations 022 */ 023public interface RelatedExpressionsApi<N, E, T, B, MB extends B, TB extends B, S, I, QI, EV, PP> { 024 025 /** 026 * @return {@literal true} if the {@code node1} is able to declare more than one 027 * variable but {@code node2} is the only variable declaration that 028 * {@code node1} actually contains. 029 */ 030 boolean isOnlyFragmentOfMultiVariable(final N node1, final N node2); 031 032 boolean hasInitializer(N node, N potentialInitializer); 033 034 T getReservedTypeVar(S scope); 035 036 // TODO: Array creation 037 038 Set<QI> getFeatures(N relatedExpression); 039 040 /** 041 * Compares all strings occurring in the two AST nodes. 042 * 043 * @throws IllegalArgumentException if the given nodes do not have the same 044 * type. 045 */ 046 boolean compare(N node1, N node2); 047 048 String getDescription(N node); 049 050 int getLine(N node); 051 052 int getColumn(N node); 053 054 I getIdentifier(final TB typeBinding); 055 056 int getLengthOfSimpleNameOfType(final T type); 057 058 int getLength(final I identifier); 059 060 /* 061 * TODO: Move logic from PublicDom to d.m.a to remove d.m.a types from the API 062 * default I guessTempName(final R relatedExpression, final String anaphor, 063 * final LocalTempVariableContents localTempVariableContents, final S scope) { 064 * return guessTempName(relatedExpression, singletonList(new 065 * ImmutablePair<>(localTempVariableContents, anaphor)), scope); } 066 * 067 * I guessTempName(final R relatedExpression, final 068 * List<Pair<LocalTempVariableContents, String>> indirectionsAndAnaphors, final 069 * S scope); 070 */ 071 072 QI toQualifiedIdentifier(final I identifier); 073 074 MB resolveMethodInvocationBinding(N relatedExpression, S scope); 075 076 String identifierToString(final I identifier); 077 078 String qualifiedIdentifierToString(final QI qualifiedIdentifier); 079 080 default boolean supportsLocalVariableTypeInference(final S scope) { 081 return false; 082 } 083 084 /* 085 * TODO: Move logic from PublicDom to d.m.a to remove d.m.a types from the API 086 * PP createPositionForNode(final N node, final Predicate<EV> condition, final 087 * List<Perspectivation> perspectivations); 088 */ 089}