9

This question got me thinking in a regex for matching javadoc comments that include some specified text.

For example, finding all javadoc fragments that include @deprecated:

/**
* Method1
* .....
* @deprecated
* @return
*/

I manage to get to the expression /\*\*.*?@deprecated.*?\*/ but this fails in some cases like:

/**
* Method1
* .....
* @return
*/
public int Method1() { } 

// this method should be @deprecated
public void Method2() { }    

/**
* Method3
* .....
* @return
*/
public int Method3() { } 

where it matches all the code from the 1st javadoc fragment until the 3rd javadoc fragment.

Can someone give a regex for this?

Community
  • 1
  • 1
bruno conde
  • 47,767
  • 15
  • 98
  • 117

2 Answers2

14

Try this one :

/\*\*([^\*]|\*(?!/))*?@deprecated.*?\*/
Diadistis
  • 12,086
  • 1
  • 33
  • 55
0

method2() does not have a javadoc comment and is therefor not deprecated (though the comment states it should be).

Also, if you want to extract information from the javadoc comments I’d recommend looking into the javadoc tool and writing a Doclet. You have easy access to all the information from the javadoc comment from there.

Bombe
  • 81,643
  • 20
  • 123
  • 127
  • Bombe, I just chose the string "@deprecated" as I might have chosen "bla". That is not the point. Also, I cannot use an external tool because this expression is to incorporate in the eclipse search dialog. See the related question. – bruno conde Mar 27 '09 at 11:31