{"action":"created","issue":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/254","labels_url":"https://api.github.com/repos/javaparser/javaparser/issues/254/labels{/name}","comments_url":"https://api.github.com/repos/javaparser/javaparser/issues/254/comments","events_url":"https://api.github.com/repos/javaparser/javaparser/issues/254/events","html_url":"https://github.com/javaparser/javaparser/issues/254","id":123673567,"number":254,"title":"Problem matching ConstructorDeclaration with ExplicitConstructorInvocationStmt","user":{"login":"TCke83","id":3518416,"avatar_url":"https://avatars.githubusercontent.com/u/3518416?v=3","gravatar_id":"","url":"https://api.github.com/users/TCke83","html_url":"https://github.com/TCke83","followers_url":"https://api.github.com/users/TCke83/followers","following_url":"https://api.github.com/users/TCke83/following{/other_user}","gists_url":"https://api.github.com/users/TCke83/gists{/gist_id}","starred_url":"https://api.github.com/users/TCke83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TCke83/subscriptions","organizations_url":"https://api.github.com/users/TCke83/orgs","repos_url":"https://api.github.com/users/TCke83/repos","events_url":"https://api.github.com/users/TCke83/events{/privacy}","received_events_url":"https://api.github.com/users/TCke83/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-23T15:01:15Z","updated_at":"2015-12-25T09:45:41Z","closed_at":null,"body":"Hi,\r\n\r\ni'm working on a project to analyse certain files.\r\n\r\n```Java\r\npublic class A {\r\n  public A(String var) {\r\n    // Do something\r\n  }\r\n}\r\n\r\npublic class B extends A {\r\n  private static final String VAR = \"Some string\";\r\n\r\n  public B(Object obj, String var) {\r\n    super(var);\r\n    // Do something more\r\n  }\r\n\r\n  public B(Object obj) {\r\n    this(obj, VAR);\r\n  }\r\n}\r\n```\r\n\r\nNow this is a simple case, a lot of files that extend class A have more than two constructors. I want to be able to get the value 'var' that is send to the super-constructor (of class A).\r\n\r\nIf I get the constructors of B I get 2 ConstructorDeclaration instances. If I check the one with 2 parameters, is see the call to the super-constructor, but i'm unable to determine the value passed, because it is a input variable of the constructor.\r\n\r\nIf I parse the constructor with 1 parameter I see the call to a constructor as a ExplicitConstructorInvocationStmt. But i'm unable to match the ExplicitConstructorInvocationStmt to the correct ConstructorDeclaration. \r\n\r\nThis is an easy example, one could argue it should be the other one of the two constructors. But like I said, a lot of cases have 3 or more constructors. Is there a way to figure out which ConstructorDeclaration will be called with the ExplicitConstructorInvocationStmt? I was thinking of type checking the parameters of the call but the ExplicitConstructorInvocationStmt doesn't contain any type information.\r\n\r\nThanks in advance for your support.\r\n\r\nRegards,\r\n\r\nTom"},"comment":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/comments/167216780","html_url":"https://github.com/javaparser/javaparser/issues/254#issuecomment-167216780","issue_url":"https://api.github.com/repos/javaparser/javaparser/issues/254","id":167216780,"user":{"login":"ftomassetti","id":439078,"avatar_url":"https://avatars.githubusercontent.com/u/439078?v=3","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":"2015-12-25T09:45:41Z","updated_at":"2015-12-25T09:45:41Z","body":"Hi Tom,\r\nwhat you are trying to do is to solve symbols: in this case you want to associate a constructor invokation to a constructor declaration. This can be done on top of JavaParser but JavaParser itself does not provide this functionality. JavaParser produces an Abstract Syntax Tree (AST) and this is it.\r\nTo distinguish between different possible constructors in some cases you can just look at the number of parameters (let's ignore variadic parameters). In the other cases you need to calculate the type of the expressions used as parameters. This is not trivial and require a symbol solver.\r\n\r\nIn this discussion (https://github.com/javaparser/javaparser/issues/221) @JamesXNelson hinted at the fact he is working on a symbol solver. I have also worked on one which is available at https://github.com/ftomassetti/java-symbol-solver.\r\n\r\nIn some simple cases you can do without a symbol solver and if you can I suggest doing so. However if you want to solve the problem in general than it is a lot of work."}}