• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Parser.

 
nateshkumar natesamudaliar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch and thank you for correcting the naming problem.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nateshkumar natesamudaliar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic