Skip to content

Commit

Permalink
Merge 14aa2d0 into c88752c
Browse files Browse the repository at this point in the history
  • Loading branch information
jlerbsc committed Nov 26, 2020
2 parents c88752c + 14aa2d0 commit 75e55c2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ private static boolean isApplicable(ResolvedMethodDeclaration methodDeclaration,
needForWildCardTolerance = true;
continue;
}
// if the expected is java.lang.Math.max(double,double) and the type parameters are defined with constrain
// for example LambdaConstraintType{bound=TypeVariable {ReflectionTypeParameter{typeVariable=T}}}, LambdaConstraintType{bound=TypeVariable {ReflectionTypeParameter{typeVariable=U}}}
// we want to keep this method for future resolution
if (actualArgumentType.isConstraint() && withWildcardTolerance && expectedDeclaredType.isPrimitive()) {
needForWildCardTolerance = true;
continue;
}
if (methodIsDeclaredWithVariadicParameter && i == countOfMethodParametersDeclared - 1) {
if (new ResolvedArrayType(expectedDeclaredType).isAssignableBy(actualArgumentType)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.javaparser.symbolsolver;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.junit.jupiter.api.Test;

import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;

public class Issue2065Test extends AbstractResolutionTest {

@Test
void test() {
String code = "import java.util.stream.Stream;\n" +
"\n" +
"public class A {\n" +
" public void test(){\n" +
" Stream.of(1,2).reduce((a, b) -> Math.max(a, b));\n" +
" }\n" +
"}";

ParserConfiguration config = new ParserConfiguration();
config.setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver(false)));
StaticJavaParser.setConfiguration(config);

CompilationUnit cu = StaticJavaParser.parse(code);
List<MethodCallExpr> exprs = cu.findAll(MethodCallExpr.class);
for (MethodCallExpr expr : exprs) {
if (expr.getNameAsString().contentEquals("max")) {
assertEquals("java.lang.Math.max(int, int)", expr.resolve().getQualifiedSignature());
}
}
}

}

0 comments on commit 75e55c2

Please sign in to comment.