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
Hi

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:    {
#16:
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 message
Jay Arthanareeswaran is currently offline Jay ArthanareeswaranFriend
Messages: 15
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.
Previous Topic:switch from "lambda expression" to "method reference"
Next Topic:Dependent Projects and JAR files
Goto Forum:
  


Current Time: Mon Dec 18 09:18:16 GMT 2017

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

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