Class MethodResolutionLogic
- java.lang.Object
-
- com.github.javaparser.resolution.logic.MethodResolutionLogic
-
public class MethodResolutionLogic extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringJAVA_LANG_OBJECT
-
Constructor Summary
Constructors Constructor Description MethodResolutionLogic()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static booleanareOverride(MethodUsage winningCandidate, MethodUsage other)private static ResolvedArrayTypeconvertToVariadicParameter(ResolvedType type)private static <T> java.util.function.Predicate<T>distinctByKey(java.util.function.Function<? super T,?> keyExtractor)Filters by given function {@param keyExtractor} using a stateful filter mechanism.private static ResolvedTypefindCommonType(java.util.List<ResolvedType> variadicValues)static SymbolReference<ResolvedMethodDeclaration>findMostApplicable(java.util.List<ResolvedMethodDeclaration> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)static SymbolReference<ResolvedMethodDeclaration>findMostApplicable(java.util.List<ResolvedMethodDeclaration> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver, boolean wildcardTolerance)static java.util.Optional<MethodUsage>findMostApplicableUsage(java.util.List<MethodUsage> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)private static intgetLastParameterIndex(int countOfMethodParametersDeclared)private static ResolvedTypegetMethodsExplicitAndVariadicParameterType(ResolvedMethodDeclaration method, int i)private static java.util.List<ResolvedType>groupTrailingArgumentsIntoArray(ResolvedMethodDeclaration methodDeclaration, java.util.List<ResolvedType> needleArgumentTypes, ResolvedType expectedVariadicParameterType)private static java.util.List<ResolvedType>groupVariadicParamValues(java.util.List<ResolvedType> argumentsTypes, int startVariadic, ResolvedType variadicType)static voidinferTypes(ResolvedType source, ResolvedType target, java.util.Map<ResolvedTypeParameterDeclaration,ResolvedType> mappings)static booleanisApplicable(ResolvedMethodDeclaration method, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)private static booleanisApplicable(ResolvedMethodDeclaration methodDeclaration, java.lang.String needleName, java.util.List<ResolvedType> needleArgumentTypes, TypeSolver typeSolver, boolean withWildcardTolerance)Note the specific naming here -- parameters are part of the method declaration, while arguments are the values passed when calling a method.static booleanisApplicable(MethodUsage methodUsage, java.lang.String needleName, java.util.List<ResolvedType> needleParameterTypes, TypeSolver typeSolver)Note the specific naming here -- parameters are part of the method declaration, while arguments are the values passed when calling a method.private static booleanisArrayOfObject(ResolvedType type)static booleanisAssignableMatchTypeParameters(ResolvedReferenceType expected, ResolvedReferenceType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)static booleanisAssignableMatchTypeParameters(ResolvedType expected, ResolvedType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)private static booleanisAssignableMatchTypeParametersMatchingQName(ResolvedReferenceType expected, ResolvedReferenceType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)protected static booleanisExactMatch(ResolvedMethodLikeDeclaration method, java.util.List<ResolvedType> argumentsTypes)private static booleanisJavaLangObject(ResolvedType paramType)private static booleanisMoreSpecific(ResolvedMethodDeclaration methodA, ResolvedMethodDeclaration methodB, java.util.List<ResolvedType> argumentTypes)private static booleanisMoreSpecific(MethodUsage methodA, MethodUsage methodB, java.util.List<ResolvedType> argumentTypes)private static booleanmatchTypeVariable(ResolvedTypeVariable typeVariable, ResolvedType type, java.util.Map<java.lang.String,ResolvedType> matchedParameters)static ResolvedTypereplaceTypeParam(ResolvedType type, ResolvedTypeParameterDeclaration tp, TypeSolver typeSolver)static SymbolReference<ResolvedMethodDeclaration>solveMethodInType(ResolvedTypeDeclaration typeDeclaration, java.lang.String name, java.util.List<ResolvedType> argumentsTypes)static SymbolReference<ResolvedMethodDeclaration>solveMethodInType(ResolvedTypeDeclaration typeDeclaration, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, boolean staticOnly)
-
-
-
Method Detail
-
groupVariadicParamValues
private static java.util.List<ResolvedType> groupVariadicParamValues(java.util.List<ResolvedType> argumentsTypes, int startVariadic, ResolvedType variadicType)
-
findCommonType
private static ResolvedType findCommonType(java.util.List<ResolvedType> variadicValues)
-
isApplicable
public static boolean isApplicable(ResolvedMethodDeclaration method, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)
-
isApplicable
private static boolean isApplicable(ResolvedMethodDeclaration methodDeclaration, java.lang.String needleName, java.util.List<ResolvedType> needleArgumentTypes, TypeSolver typeSolver, boolean withWildcardTolerance)
Note the specific naming here -- parameters are part of the method declaration, while arguments are the values passed when calling a method. Note that "needle" refers to that value being used as a search/query term to match against.- Returns:
- true, if the given ResolvedMethodDeclaration matches the given name/types (normally obtained from a MethodUsage)
-
isArrayOfObject
private static boolean isArrayOfObject(ResolvedType type)
-
convertToVariadicParameter
private static ResolvedArrayType convertToVariadicParameter(ResolvedType type)
-
getLastParameterIndex
private static int getLastParameterIndex(int countOfMethodParametersDeclared)
-
groupTrailingArgumentsIntoArray
private static java.util.List<ResolvedType> groupTrailingArgumentsIntoArray(ResolvedMethodDeclaration methodDeclaration, java.util.List<ResolvedType> needleArgumentTypes, ResolvedType expectedVariadicParameterType)
-
isAssignableMatchTypeParameters
public static boolean isAssignableMatchTypeParameters(ResolvedType expected, ResolvedType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)
-
isAssignableMatchTypeParameters
public static boolean isAssignableMatchTypeParameters(ResolvedReferenceType expected, ResolvedReferenceType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)
-
isAssignableMatchTypeParametersMatchingQName
private static boolean isAssignableMatchTypeParametersMatchingQName(ResolvedReferenceType expected, ResolvedReferenceType actual, java.util.Map<java.lang.String,ResolvedType> matchedParameters)
-
matchTypeVariable
private static boolean matchTypeVariable(ResolvedTypeVariable typeVariable, ResolvedType type, java.util.Map<java.lang.String,ResolvedType> matchedParameters)
-
replaceTypeParam
public static ResolvedType replaceTypeParam(ResolvedType type, ResolvedTypeParameterDeclaration tp, TypeSolver typeSolver)
-
isApplicable
public static boolean isApplicable(MethodUsage methodUsage, java.lang.String needleName, java.util.List<ResolvedType> needleParameterTypes, TypeSolver typeSolver)
Note the specific naming here -- parameters are part of the method declaration, while arguments are the values passed when calling a method. Note that "needle" refers to that value being used as a search/query term to match against.- Returns:
- true, if the given MethodUsage matches the given name/types (normally obtained from a ResolvedMethodDeclaration)
-
distinctByKey
private static <T> java.util.function.Predicate<T> distinctByKey(java.util.function.Function<? super T,?> keyExtractor)
Filters by given function {@param keyExtractor} using a stateful filter mechanism.persons.stream().filter(distinctByKey(Person::getName))The example above would return a distinct list of persons containing only one person per name.
-
findMostApplicable
public static SymbolReference<ResolvedMethodDeclaration> findMostApplicable(java.util.List<ResolvedMethodDeclaration> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)
- Parameters:
methods- we expect the methods to be ordered such that inherited methods are later in the list
-
findMostApplicable
public static SymbolReference<ResolvedMethodDeclaration> findMostApplicable(java.util.List<ResolvedMethodDeclaration> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver, boolean wildcardTolerance)
-
isExactMatch
protected static boolean isExactMatch(ResolvedMethodLikeDeclaration method, java.util.List<ResolvedType> argumentsTypes)
-
getMethodsExplicitAndVariadicParameterType
private static ResolvedType getMethodsExplicitAndVariadicParameterType(ResolvedMethodDeclaration method, int i)
-
isMoreSpecific
private static boolean isMoreSpecific(ResolvedMethodDeclaration methodA, ResolvedMethodDeclaration methodB, java.util.List<ResolvedType> argumentTypes)
-
isJavaLangObject
private static boolean isJavaLangObject(ResolvedType paramType)
-
isMoreSpecific
private static boolean isMoreSpecific(MethodUsage methodA, MethodUsage methodB, java.util.List<ResolvedType> argumentTypes)
-
findMostApplicableUsage
public static java.util.Optional<MethodUsage> findMostApplicableUsage(java.util.List<MethodUsage> methods, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, TypeSolver typeSolver)
-
areOverride
private static boolean areOverride(MethodUsage winningCandidate, MethodUsage other)
-
solveMethodInType
public static SymbolReference<ResolvedMethodDeclaration> solveMethodInType(ResolvedTypeDeclaration typeDeclaration, java.lang.String name, java.util.List<ResolvedType> argumentsTypes)
-
solveMethodInType
public static SymbolReference<ResolvedMethodDeclaration> solveMethodInType(ResolvedTypeDeclaration typeDeclaration, java.lang.String name, java.util.List<ResolvedType> argumentsTypes, boolean staticOnly)
-
inferTypes
public static void inferTypes(ResolvedType source, ResolvedType target, java.util.Map<ResolvedTypeParameterDeclaration,ResolvedType> mappings)
-
-