{"action":"created","issue":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/490","repository_url":"https://api.github.com/repos/javaparser/javaparser","labels_url":"https://api.github.com/repos/javaparser/javaparser/issues/490/labels{/name}","comments_url":"https://api.github.com/repos/javaparser/javaparser/issues/490/comments","events_url":"https://api.github.com/repos/javaparser/javaparser/issues/490/events","html_url":"https://github.com/javaparser/javaparser/issues/490","id":181186391,"number":490,"title":"Is there is a way to obtain method calls inside a method?","user":{"login":"moar82","id":5522349,"avatar_url":"https://avatars.githubusercontent.com/u/5522349?v=3","gravatar_id":"","url":"https://api.github.com/users/moar82","html_url":"https://github.com/moar82","followers_url":"https://api.github.com/users/moar82/followers","following_url":"https://api.github.com/users/moar82/following{/other_user}","gists_url":"https://api.github.com/users/moar82/gists{/gist_id}","starred_url":"https://api.github.com/users/moar82/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moar82/subscriptions","organizations_url":"https://api.github.com/users/moar82/orgs","repos_url":"https://api.github.com/users/moar82/repos","events_url":"https://api.github.com/users/moar82/events{/privacy}","received_events_url":"https://api.github.com/users/moar82/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/javaparser/javaparser/labels/Question","name":"Question","color":"006b75"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-05T15:23:10Z","updated_at":"2016-10-06T08:12:20Z","closed_at":null,"body":"Let's suppose I have the following method, and I want to detect all callings to method ToString().\r\nHere inside assertEquals method called, there is one call to ToString.  Is there is a way to obtain all method calls to ToString() method?\r\n\r\n`\r\npublic void testTagDefinitions() {\r\n    Facade facade = Model.getFacade();//\r\n    Object td = Model.getExtensionMechanismsFactory().buildTagDefinition(\"testTD\", stereotype, null, \"String\");\r\n      assertEquals(\"1..3\", facade.toString(facade.getMultiplicity(td)));\r\n}\r\n`"},"comment":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/comments/251895451","html_url":"https://github.com/javaparser/javaparser/issues/490#issuecomment-251895451","issue_url":"https://api.github.com/repos/javaparser/javaparser/issues/490","id":251895451,"user":{"login":"matozoid","id":55701,"avatar_url":"https://avatars.githubusercontent.com/u/55701?v=3","gravatar_id":"","url":"https://api.github.com/users/matozoid","html_url":"https://github.com/matozoid","followers_url":"https://api.github.com/users/matozoid/followers","following_url":"https://api.github.com/users/matozoid/following{/other_user}","gists_url":"https://api.github.com/users/matozoid/gists{/gist_id}","starred_url":"https://api.github.com/users/matozoid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matozoid/subscriptions","organizations_url":"https://api.github.com/users/matozoid/orgs","repos_url":"https://api.github.com/users/matozoid/repos","events_url":"https://api.github.com/users/matozoid/events{/privacy}","received_events_url":"https://api.github.com/users/matozoid/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T08:12:20Z","updated_at":"2016-10-06T08:12:20Z","body":"I took out the \"//\" because it made the sample invalid.\r\n\r\n```java\r\nimport com.github.javaparser.ast.CompilationUnit;\r\nimport com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;\r\nimport com.github.javaparser.ast.body.MethodDeclaration;\r\nimport com.github.javaparser.ast.expr.MethodCallExpr;\r\nimport com.github.javaparser.ast.visitor.VoidVisitorAdapter;\r\nimport org.junit.Test;\r\n\r\npublic class ObtainMethodCalssInsideMethod {\r\n    @Test\r\n    public void test() {\r\n        CompilationUnit cu = JavaParser.parse(\"class X{ public void testTagDefinitions() { Facade facade = Model.getFacade(); Object td = Model.getExtensionMechanismsFactory().buildTagDefinition(\\\"testTD\\\", stereotype, null, \\\"String\\\"); assertEquals(\\\"1..3\\\", facade.toString(facade.getMultiplicity(td))); }}\");\r\n\r\n        ClassOrInterfaceDeclaration classX = cu.getClassByName(\"X\");\r\n\r\n        for (MethodDeclaration method : classX.getMethods()) {\r\n            // Make the visitor go through everything inside the method.\r\n            method.accept(new MethodCallVisitor(), null);\r\n        }\r\n    }\r\n}\r\n\r\nclass MethodCallVisitor extends VoidVisitorAdapter<Void> {\r\n    @Override\r\n    public void visit(MethodCallExpr n, Void arg) {\r\n        // Found a method call\r\n        System.out.println(n.getScope() + \" - \" + n.getName());\r\n        // Don't forget to call super, it may find more method calls inside the arguments of this method call, for example.\r\n        super.visit(n, arg);\r\n    }\r\n}\r\n```\r\n\r\n"}}
{"actor":{"display_login":"matozoid"}}