{"action":"created","issue":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/1482","repository_url":"https://api.github.com/repos/javaparser/javaparser","labels_url":"https://api.github.com/repos/javaparser/javaparser/issues/1482/labels{/name}","comments_url":"https://api.github.com/repos/javaparser/javaparser/issues/1482/comments","events_url":"https://api.github.com/repos/javaparser/javaparser/issues/1482/events","html_url":"https://github.com/javaparser/javaparser/issues/1482","id":308056750,"number":1482,"title":"[Question] How to get the ResolvedType of a MethodCallExpr within a multi catch?","user":{"login":"daanschipper","id":2778477,"avatar_url":"https://avatars0.githubusercontent.com/u/2778477?v=4","gravatar_id":"","url":"https://api.github.com/users/daanschipper","html_url":"https://github.com/daanschipper","followers_url":"https://api.github.com/users/daanschipper/followers","following_url":"https://api.github.com/users/daanschipper/following{/other_user}","gists_url":"https://api.github.com/users/daanschipper/gists{/gist_id}","starred_url":"https://api.github.com/users/daanschipper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daanschipper/subscriptions","organizations_url":"https://api.github.com/users/daanschipper/orgs","repos_url":"https://api.github.com/users/daanschipper/repos","events_url":"https://api.github.com/users/daanschipper/events{/privacy}","received_events_url":"https://api.github.com/users/daanschipper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-23T14:43:59Z","updated_at":"2018-03-23T14:47:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"How would one get the type of a `MethodCallExpr` within a multi catch? I've provided the following example to illustrate what I exactly mean. Of the two printing statements, I would like to know the types of the arguments. For just the argument `e` I get a ResolvedUnionType of  `java.lang.ArrayIndexOutOfBoundsException | java.lang.ClassCastException`, but when I try to get the type of `e.getMessage()` I receive an UnsupportedException.\r\n\r\n```\r\npublic static void main(String[] args) {\r\n    CompilationUnit cu = JavaParser.parse(\"public class X {\\n\" +\r\n            \"        public void test() {\\n\" +\r\n            \"            try {\\n\" +\r\n            \"                methodWithExceptions();\\n\" +\r\n            \"            } catch (ArrayIndexOutOfBoundsException | ClassCastException e) {\\n\" +\r\n            \"                System.out.println(e);\\n\" +\r\n            \"                System.out.println(e.getMessage());\\n\" +\r\n            \"            }\\n\" +\r\n            \"        }\\n\" +\r\n            \"\\n\" +\r\n            \"        private void methodWithExceptions() throws ArrayIndexOutOfBoundsException, ClassCastException {\\n\" +\r\n            \"            // do something\\n\" +\r\n            \"        }\\n\" +\r\n            \"    }\");\r\n    cu.accept(new Visitor(), null);\r\n}\r\n\r\nprivate static class Visitor extends VoidVisitorAdapter<Void> {\r\n    @Override\r\n    public void visit(MethodCallExpr n, Void arg) {\r\n        System.out.println(\"n.toString() = \" + n.toString());\r\n        if (n.getArguments().size() != 0) {\r\n            Expression argument = n.getArgument(0);\r\n            // succeeds on e, but fails on e.getMessage()\r\n            ResolvedType type = JavaParserFacade.get(new ReflectionTypeSolver(true)).getType(argument);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThis is the error message I receive when executing the above example\r\n```\r\nException in thread \"main\" java.lang.UnsupportedOperationException: type usage: com.github.javaparser.resolution.types.ResolvedUnionType\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext.solveMethodAsUsage(MethodCallExprContext.java:410)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.contexts.MethodCallExprContext.solveMethodAsUsage(MethodCallExprContext.java:111)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.solveMethodAsUsage(JavaParserFacade.java:513)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:276)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.TypeExtractor.visit(TypeExtractor.java:46)\r\n\tat com.github.javaparser.ast.expr.MethodCallExpr.accept(MethodCallExpr.java:109)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getTypeConcrete(JavaParserFacade.java:377)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getType(JavaParserFacade.java:274)\r\n\tat com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade.getType(JavaParserFacade.java:268)\r\n\tat visitors.Test$Visitor.visit(Test.java:37)\r\n\tat visitors.Test$Visitor.visit(Test.java:31)\r\n\tat com.github.javaparser.ast.expr.MethodCallExpr.accept(MethodCallExpr.java:115)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:285)\r\n\tat com.github.javaparser.ast.stmt.ExpressionStmt.accept(ExpressionStmt.java:77)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$17(VoidVisitorAdapter.java:118)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\r\n\tat com.github.javaparser.ast.NodeList.forEach(NodeList.java:267)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:118)\r\n\tat com.github.javaparser.ast.stmt.BlockStmt.accept(BlockStmt.java:78)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:146)\r\n\tat com.github.javaparser.ast.stmt.CatchClause.accept(CatchClause.java:88)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$153(VoidVisitorAdapter.java:593)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\r\n\tat com.github.javaparser.ast.NodeList.forEach(NodeList.java:267)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:593)\r\n\tat com.github.javaparser.ast.stmt.TryStmt.accept(TryStmt.java:143)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$17(VoidVisitorAdapter.java:118)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\r\n\tat com.github.javaparser.ast.NodeList.forEach(NodeList.java:267)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:118)\r\n\tat com.github.javaparser.ast.stmt.BlockStmt.accept(BlockStmt.java:78)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$98(VoidVisitorAdapter.java:410)\r\n\tat java.util.Optional.ifPresent(Optional.java:159)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:410)\r\n\tat com.github.javaparser.ast.body.MethodDeclaration.accept(MethodDeclaration.java:120)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$29(VoidVisitorAdapter.java:170)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\r\n\tat com.github.javaparser.ast.NodeList.forEach(NodeList.java:267)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:170)\r\n\tat com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.accept(ClassOrInterfaceDeclaration.java:105)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.lambda$visit$40(VoidVisitorAdapter.java:192)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1249)\r\n\tat com.github.javaparser.ast.NodeList.forEach(NodeList.java:267)\r\n\tat com.github.javaparser.ast.visitor.VoidVisitorAdapter.visit(VoidVisitorAdapter.java:192)\r\n\tat com.github.javaparser.ast.CompilationUnit.accept(CompilationUnit.java:131)\r\n\tat visitors.Test.main(Test.java:28)\r\n```"},"comment":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/comments/375688970","html_url":"https://github.com/javaparser/javaparser/issues/1482#issuecomment-375688970","issue_url":"https://api.github.com/repos/javaparser/javaparser/issues/1482","id":375688970,"user":{"login":"ftomassetti","id":439078,"avatar_url":"https://avatars2.githubusercontent.com/u/439078?v=4","gravatar_id":"","url":"https://api.github.com/users/ftomassetti","html_url":"https://github.com/ftomassetti","followers_url":"https://api.github.com/users/ftomassetti/followers","following_url":"https://api.github.com/users/ftomassetti/following{/other_user}","gists_url":"https://api.github.com/users/ftomassetti/gists{/gist_id}","starred_url":"https://api.github.com/users/ftomassetti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ftomassetti/subscriptions","organizations_url":"https://api.github.com/users/ftomassetti/orgs","repos_url":"https://api.github.com/users/ftomassetti/repos","events_url":"https://api.github.com/users/ftomassetti/events{/privacy}","received_events_url":"https://api.github.com/users/ftomassetti/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T14:47:34Z","updated_at":"2018-03-23T14:47:34Z","author_association":"OWNER","body":"This is a current limitation of JSS. It should look for common ancestors of all the types involved in the union and use that common ancestor to solve the method calls.\r\n\r\nIf someone wanted to submit a Pull Request it would be great and we could help him getting done"}}
{"actor":{"display_login":"ftomassetti"}}