is there any way to search all methods in Java class with regex?
-
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.Juvanis– Juvanis2013-07-26 07:42:32 +00:00Commented Jul 26, 2013 at 7:42
-
1Are you trying to parse a Java code file or what? Regex certainly is the wrong tool for this job.Daniel Hilgarth– Daniel Hilgarth2013-07-26 07:43:01 +00:00Commented Jul 26, 2013 at 7:43
-
Um, I am really impressed. It's a first time I see regex used as reflection tool.Leri– Leri2013-07-26 07:43:10 +00:00Commented Jul 26, 2013 at 7:43
-
You are probably looking for AspectJ Pointcut expressions: guptavikas.wordpress.com/2010/04/15/…necromancer– necromancer2013-07-26 07:47:16 +00:00Commented 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.Aditya Hadi– Aditya Hadi2013-07-26 08:00:01 +00:00Commented Jul 26, 2013 at 8:00
|
Show 1 more comment
2 Answers
(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 ^^.
4 Comments
Daniel Hilgarth
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.
Distopic
stackoverflow.com/questions/68633/… This is the link where this is discused. Thanks to Georgios Gousios.
Aditya Hadi
I still got ` else if (plane == REFLECT_PLANE_XZ)` in the results. Any idea?
Distopic
try to use only the first part oh the exreg, altaugh is a little suspicious that the string that you paste validate the expression.
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.