GeeCON Prague 2014*
The moose likes Java in General and the fly likes Java Parser. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Parser." Watch "Java Parser." New topic
Author

Java Parser.

nateshkumar natesamudaliar
Greenhorn

Joined: Feb 24, 2009
Posts: 3
Hi
I need to extract all the method names in a given Java file name and would like to know some available parsers that does the same.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Welcome to JavaRanch and thank you for correcting the naming problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Do you mean using reflection on the .class files or something like JFlex/CUP on the .java files?
I would try JFlex/CUP to create a parser.
nateshkumar natesamudaliar
Greenhorn

Joined: Feb 24, 2009
Posts: 3
I dont want to use reflection.
I have a Java file which has 4 or more independent classes(say A,B,C,D) in it.
I will have the Java file name and the name of all the 4 or more classes.
Given the class name (A or B or C or D), I need the methods inside that class. This is the main objective.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
The main parser engines written in Java are Antlr, SableCC and JavaCC. Grammars for parsing Java source code are available for each of these on their respective web sites.


Ping & DNS - my free Android networking tools app
nateshkumar natesamudaliar
Greenhorn

Joined: Feb 24, 2009
Posts: 3
I have chosen JavaCC.
I extracted EclipseJavaCC plugin. Also I have the JavaCC jar file imported in my eclipse.
I have also downloaded java1.5.jj which has the grammar for Java I guess.
I dont know how to organize these things and use it in my project to give a Java source file and do the parsing and get the method information.
Also I would like to know if it works without using Eclipse(basically without any plugin) just by using one more JAR file.
Please give some JavaCC specific explanation.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
You do not need any plugin to work with JavaCC (or any IDE, for that matter). There's a tutorial at http://www.engr.mun.ca/~theo/JavaCC-Tutorial/ and some further documentation on the main JavaCC web site.
 
GeeCON Prague 2014
 
subject: Java Parser.