-3

is there any way to search all methods in Java class with regex?

6
  • of course it is possible even it would be a complex regex. but what are you trying to achieve? you can get the list of methods with java reflection much more easily. Commented Jul 26, 2013 at 7:42
  • 1
    Are you trying to parse a Java code file or what? Regex certainly is the wrong tool for this job. Commented Jul 26, 2013 at 7:43
  • Um, I am really impressed. It's a first time I see regex used as reflection tool. Commented Jul 26, 2013 at 7:43
  • You are probably looking for AspectJ Pointcut expressions: guptavikas.wordpress.com/2010/04/15/… Commented Jul 26, 2013 at 7:47
  • I cannot compile the class due to some data not ready yet, that's why I cannot use java reflection. Commented Jul 26, 2013 at 8:00

2 Answers 2

3
(public|protected|private|static|\s) +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;])

With this you can, but search before ask, because i only have used the search to find this answer ^^.

Sign up to request clarification or add additional context in comments.

4 Comments

That would not account for comments or strings. And if you copied that expression from somewhere, give the original author credit by linking to the source.
stackoverflow.com/questions/68633/… This is the link where this is discused. Thanks to Georgios Gousios.
I still got ` else if (plane == REFLECT_PLANE_XZ)` in the results. Any idea?
try to use only the first part oh the exreg, altaugh is a little suspicious that the string that you paste validate the expression.
0

I think you're looking for reflection - see this tutorial for help. Only through reflection can you access information about loaded classes - unless you're thinking of loading in the .java file and analyzing its text.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.