Skip to content

Commit

Permalink
improvement on verifying method compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Oct 15, 2016
1 parent 8a3b74e commit 69e724f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -42,7 +42,8 @@ public JavaParserClassDeclaration(com.github.javaparser.ast.body.ClassOrInterfac

@Override
public SymbolReference<MethodDeclaration> solveMethod(String name, List<Type> parameterTypes) {
return getContext().solveMethod(name, parameterTypes, typeSolver());
Context ctx = getContext();
return ctx.solveMethod(name, parameterTypes, typeSolver);
}

public Context getContext() {
Expand Down
Expand Up @@ -74,7 +74,7 @@ private static boolean isApplicable(MethodDeclaration method, String name, List<
for (int i = 0; i < method.getNoParams(); i++) {
Type expectedType = method.getParam(i).getType();
Type actualType = paramTypes.get(i);
if (expectedType.isTypeVariable() && expectedType.asTypeParameter().declaredOnMethod()) {
if ((expectedType.isTypeVariable() && !(expectedType.isWildcard())) && expectedType.asTypeParameter().declaredOnMethod()) {
matchedParameters.put(expectedType.asTypeParameter().getName(), actualType);
continue;
}
Expand Down Expand Up @@ -110,6 +110,18 @@ private static boolean isApplicable(MethodDeclaration method, String name, List<
return !withWildcardTolerance || needForWildCardTolerance;
}

public static boolean isAssignableMatchTypeParameters(Type expected, Type actual,
Map<String, Type> matchedParameters) {
if (expected.isReferenceType() && actual.isReferenceType()) {
return isAssignableMatchTypeParameters(expected.asReferenceType(), actual.asReferenceType(), matchedParameters);
} else if (expected.isTypeVariable()) {
matchedParameters.put(expected.asTypeParameter().getName(), actual);
return true;
} else {
throw new UnsupportedOperationException(expected.getClass().getCanonicalName() + " "+actual.getClass().getCanonicalName());
}
}

public static boolean isAssignableMatchTypeParameters(ReferenceType expected, ReferenceType actual,
Map<String, Type> matchedParameters) {
if (actual.getQualifiedName().equals(expected.getQualifiedName())) {
Expand Down Expand Up @@ -159,7 +171,10 @@ private static boolean isAssignableMatchTypeParametersMatchingQName(ReferenceTyp
return false;
}
} else if (expectedParam.isWildcard()) {
// TODO verify bounds
if (expectedParam.asWildcard().isExtends()){
return isAssignableMatchTypeParameters(expectedParam.asWildcard().getBoundedType(), actual, matchedParameters);
}
// TODO verify super bound
return true;
} else {
throw new UnsupportedOperationException(expectedParam.describe());
Expand Down

0 comments on commit 69e724f

Please sign in to comment.