aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjean pierre Lerbscher <5850581+jlerbsc@users.noreply.github.com>2024-04-30 18:17:57 +0200
committerGitHub <noreply@github.com>2024-04-30 18:17:57 +0200
commit9b1c15fedc7993594233f245ef025cf3ab33268b (patch)
treebe45556145fbfbb13a86654e7c6ce792d772da20
parent6ba381403022ef84938d927fae3ceee6e64af17f (diff)
parenta0d89f0a140a856ade4eeaf3d7f722f8d070b448 (diff)
downloadjavaparser-upstream-master.tar.gz
Merge pull request #4402 from jlerbsc/masterupstream-master
Fix issue 2368 Unable to calculate the type of a varargs parameter
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java30
1 files changed, 4 insertions, 26 deletions
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
index b13a83371..a13429623 100644
--- a/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
@@ -798,30 +798,8 @@ public class MethodResolutionLogic {
return paramType.isReferenceType() && paramType.asReferenceType().getQualifiedName().equals("java.lang.Object");
}
- private static boolean isMoreSpecific(MethodUsage methodA, MethodUsage methodB) {
- boolean oneMoreSpecificFound = false;
- for (int i = 0; i < methodA.getNoParams(); i++) {
- ResolvedType tdA = methodA.getParamType(i);
- ResolvedType tdB = methodB.getParamType(i);
-
- boolean aIsAssignableByB = tdA.isAssignableBy(tdB);
- boolean bIsAssignableByA = tdB.isAssignableBy(tdA);
-
- // A is more specific
- if (bIsAssignableByA && !aIsAssignableByB) {
- oneMoreSpecificFound = true;
- }
- // B is more specific
- if (aIsAssignableByB && !bIsAssignableByA) {
- return false;
- }
-
- // If B is vararg and A is not, A is more specific
- if (tdB.isArray() && tdB.asArrayType().getComponentType().isAssignableBy(tdA)) {
- oneMoreSpecificFound = true;
- }
- }
- return oneMoreSpecificFound;
+ private static boolean isMoreSpecific(MethodUsage methodA, MethodUsage methodB, List<ResolvedType> argumentTypes) {
+ return isMoreSpecific(methodA.getDeclaration(), methodB.getDeclaration(), argumentTypes);
}
public static Optional<MethodUsage> findMostApplicableUsage(List<MethodUsage> methods, String name, List<ResolvedType> argumentsTypes, TypeSolver typeSolver) {
@@ -836,9 +814,9 @@ public class MethodResolutionLogic {
MethodUsage winningCandidate = applicableMethods.get(0);
for (int i = 1; i < applicableMethods.size(); i++) {
MethodUsage other = applicableMethods.get(i);
- if (isMoreSpecific(winningCandidate, other)) {
+ if (isMoreSpecific(winningCandidate, other, argumentsTypes)) {
// nothing to do
- } else if (isMoreSpecific(other, winningCandidate)) {
+ } else if (isMoreSpecific(other, winningCandidate, argumentsTypes)) {
winningCandidate = other;
} else {
if (winningCandidate.declaringType().getQualifiedName().equals(other.declaringType().getQualifiedName())) {