Results 1 to 10 of 10
Thread: Parse .java files
- 04-20-2011, 02:32 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
Parse .java files
Hello,
I am using JavaParser (Java Source Reflection) to parse .java files, but what I really want is to get the info from the comments, Javadoc and simple // comments.
JavaParser parses only the code and not the comments. So:
gives the names of the methods but null for the javadoc comments.Java Code:JavaMethod[] methods = js.getMethods(); for (int i = 0; i < methods.length; i++) { System.out.println(" " + methods[i].getName()); System.out.println(" " + methods[i].getComment()); }
I am using netbeans. Do you know which library should I use?
- 04-21-2011, 02:52 AM #2
If you have access to a .java file, why don't you parse it yourself for the comments? Just look for the method declaration, and search within the brackets for any occurrences of "//".
- 04-21-2011, 09:22 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
Thanks 4 your answer ra4king.
..Because I need to take the comments separately from the methods, then from the description of the class, then from the fields and then any other "//" comments.
I want this to work with any source file with unknown to me structure, not only this particularly.
Is there a parser at all? I can't find a parser to work like this.
- 04-21-2011, 12:55 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
I am making my own parser.
If I know the method's name in the source code, how can I take the previous lines that contain the method Javadoc?
for the author's name, I have done the following code.
Java Code:FileInputStream fstream = new FileInputStream(pFile.getAbsolutePath()); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console // System.out.println (strLine); if (strLine.contains("* @author")){ author = strLine.substring("* @author".length()+2); System.out.println("Author: " + author); System.out.println(); } } .........e.t.c
- 04-21-2011, 06:42 PM #5
I wouldn't suggest doing "substring("* @author*.length()+2)" because you may not know how many stars and spaces there might be. try doing:
If you want the comments right before a method, I would suggest storing all the lines in an ArrayList first then, after searching and finding the method declaration, parse the previous lines for the comments.Java Code:strLine.substring(strLine.indexOf("@author")+8);
- 04-21-2011, 07:21 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
ok!! I did do that with the ArrayList and it worked!
I will try the tip you told me..
Thanks again, good luck at you do!
- 04-21-2011, 08:04 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-21-2011, 09:27 PM #8
- 04-22-2011, 04:40 AM #9
Here.Where is this Doclet class?
db
- 04-22-2011, 04:42 AM #10
Hm, I have actually never ventured into the "com" package. Pretty cool classes over there!
Similar Threads
-
how to parse an input files that have different types of delimiters
By renu in forum New To JavaReplies: 10Last Post: 04-12-2011, 06:00 PM -
Parse Data from Java Applet
By ssh1091 in forum Java AppletsReplies: 6Last Post: 02-27-2011, 03:28 AM -
Parse log file using java
By mvg in forum Advanced JavaReplies: 0Last Post: 07-03-2009, 11:36 AM -
Parse EDI File Using java
By vaskarbasak in forum Advanced JavaReplies: 6Last Post: 09-24-2008, 02:38 PM -
How to parse an xml file using java
By karthik84 in forum XMLReplies: 4Last Post: 09-12-2008, 09:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks