Get details of method from particular class

web_api

(Menuka Ishan) #1

Hello.

I am new to sonarqube. I am currently using sonarqube-7.2.1.
For my project, I want to get details of the methods for a given class.
I read http://localhost:9000/api/webservices/list json to get an idea. But I couldn’t. I could find web API documentation for SonarQube 4.3 but not for 7.2.1
Can you help me to show a path? What I want is if I gave a class I need the names of methods and number of lines in each method. is this possible to achieve through SonarQube?

Thank you. :slight_smile:


How to get line-by-line coverage information with REST api?
(Grégoire Aubert) #2

Hello,
You can have the API documentation of your current instance through http://localhost:9000/web_api, there you can search for what you need.
But as far as I know there is no api endpoint to get the methods of a class. The closest I could think of is getting some metrics of a file (number of lines of codes, number of functions…)


(Nicolas Bontoux) #3

Hi Menuka,

It’s good you ask, because indeed it’s not obvious how this relates to SonarQube’s intent of static code analysis. I’ll quote a past discussion:

In this discussion here, when I read ‘need the names of methods and number of lines in each method’ I do not see the relation with code quality and/or bug detection, so trying to query/extend SonarQube for that purpose might end-up a frustrating effort (not what the product and its APIs are designed for).


(Tharushi Geethma) #5

HI Nicolas ,

I’m doing a project.In that project, I also need to get the method name, method’s starting line number, method’s ending line number for each of the methods in a particular class. As you say, I think that using SonarQube’s code parsing mechanism would be a frustrating one.

But I heard about this H2 internal database and that it can be converted in to mysql, postgreSql , MariaDB etc. Do you think that analysing this database for the above purpose will be useful ?

Thanks in advance


(Nicolas Bontoux) #6

No I don’t think this can help in any way. You wouldn’t find more information there (to help with your use-case) then you would in the source file alone. As much as SonarQube can help with detection of bugs/vulnerabilities/code_smells in codebase, I just don’t think it will help for the precise goals you’ve described here.