Skip to content

Conversation

maartenc
Copy link
Contributor

Fixes #2657.

@MysterAitch
Copy link
Member

MysterAitch commented May 11, 2020

Cheers @maartenc

Could you take a look at this though, as the test included seems to pass with or without the included changes.

Edit: and the test case from #2657 still fails:

@Test
    public void issue2657Test_StringValueOfInStream() {
        String s =
                "import java.util.HashSet;\n" +
                        "import java.util.Set;\n" +
                        "import java.util.stream.Collectors;\n" +
                        "\n" +
                        "public class StreamTest {\n" +
                        "    \n" +
                        "    public void streamTest () {\n" +
                        "        Set<Integer> intSet = new HashSet<Integer>() {{\n" +
                        "           add(1);\n" +
                        "           add(2);\n" +
                        "        }};\n" +
                        "        Set <String> strings = intSet.stream().map(String::valueOf).collect(Collectors.toSet());\n" +
                        "    }\n" +
                        "}";

        TypeSolver typeSolver = new ReflectionTypeSolver();
        StaticJavaParser.getConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
        CompilationUnit cu = StaticJavaParser.parse(s);

        int errorCount = 0;

        Set<MethodCallExpr> methodCallExpr = new HashSet<>(cu.findAll(MethodCallExpr.class));
        for (MethodCallExpr expr : methodCallExpr) {
            try {
                ResolvedMethodDeclaration rd = expr.resolve();
                System.out.println("\t Solved : " + rd.getQualifiedSignature());
            } catch (UnsolvedSymbolException e) {
                System.out.println("\t UNSOLVED: " + expr.toString());
                e.printStackTrace();
                errorCount++;
            }
        }

        assertEquals(0, errorCount, "Expected zero UnsolvedSymbolException s");
    }

@maartenc
Copy link
Contributor Author

sorry, you are right, made some stupid error while cleaning up my code, I've committed a fix

Strange my testcase didn't fail though, perhaps we should check what is different with the one you provided.

@MysterAitch
Copy link
Member

sorry, you are right, made some stupid error while cleaning up my code, I've committed a fix

Strange my testcase didn't fail though, perhaps we should check what is different with the one you provided.

All good! 😆

I'll merge now as it otherwise seems good now that tests are passing :)

@MysterAitch MysterAitch added this to the next release 3.15.22 milestone May 11, 2020
@MysterAitch MysterAitch merged commit c701438 into javaparser:master May 11, 2020
@maartenc
Copy link
Contributor Author

👍
Thanks for reviewing and merging this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnsolvedSymbolException when String::valueOf is used in streams

2 participants