Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » JDT - Find startline of method excluding Javadocs(JDT - Find startline of method declaration excluding Javadocs)
JDT - Find startline of method excluding Javadocs [message #1755284] Thu, 02 March 2017 06:17 Go to next message
Suresh P is currently offline Suresh PFriend
Messages: 27
Registered: May 2013
Junior Member

I'm implementing quick assist based on the selection in the editor, using JDT/AST.

Can you let me know how to find the starting line number of the Method Declaration (excluding the Javadocs).

Below code gives me the Line number, but it starts with the JavaDoc comment line number. But I need to get the line number at the Method declaration level.

      public boolean visit(MethodDeclaration node) {
			CompilationUnit cu = getCompilationUnit();
			int startLineNumber =  getCompilationUnit().getLineNumber(node.getStartPosition()));

Sample Method:

In below sample code, I need to get the Line Number as #14 (from method signature), but Im getting line number as #10 (from Javadoc).

 #10:   /**
#11:     * Method used for extracting the given parameter form the request.return
#12:     * null if empty
#13:     */
#14:     private String getString(HttpServletRequest request, String param)
#15:    {
Re: JDT - Find startline of method excluding Javadocs [message #1760767 is a reply to message #1755284] Tue, 02 May 2017 17:37 Go to previous messageGo to next message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 29
Registered: July 2009
Junior Member
I am not sure you can really do it this way. One way you can do is to get the modifiers (i.e. the child of this node that is expected to be in front) and get its start position.
Re: JDT - Find startline of method excluding Javadocs [message #1782769 is a reply to message #1755284] Thu, 01 March 2018 08:19 Go to previous message
Federer Roger  is currently offline Federer Roger Friend
Messages: 19
Registered: December 2017
Junior Member
Use MethodDeclaration.getName() to do that.
Previous Topic:How to generate binding (key) for a CompilationUnit? [100$ reward for solution]
Next Topic:Parsing Java files with JDT and it's memory consumption / performance
Goto Forum:

Current Time: Mon Nov 12 17:33:04 GMT 2018

Powered by FUDForum. Page generated in 0.01865 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top