views:

595

answers:

6

Hello,

I'm building a very simple Java parser, to look for some specific usage models. This is in no way lex/yacc or any other form of interpreter/compiler for puposes of running the code.

When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name. I'm not interested in whether the proper classes were included/imported in the code (i.e. if the code compiles well), and the extreme cases of user defined classes that override the names of standard Java classes also does not interest me. In other words: I'm okay with false negative, I'm only interesting in being "mostly" right.

If there a place wher I could find a simple list of all the names of all Java standard classes and methods, in the form easily saved into a text file or database? (J2SE is okay, but J2EE is better). I'm familiar with http://java.sun.com/j2se/ etc, but it seems I need a terrible amount of manual work to extract all the names from there. Also, the most recent JDK is not neccesary, I can live with 1.4 or 1.5.

Clarification: I'm not working in Java but in Python, so I can't use Java-specific commands in my parsing mechanism.

Thanks

+1  A: 

What's wrong with the javadoc? The index lists all classes, methods, and static variables. You can probably grep for parenthesis.

eed3si9n
+1 Nothing wrong :) I was not familiar with this form of list... Is there a similiar simple way to access the list of methods for each class (i.e. not the tabled list that each of the classes has)
Roee Adler
At this stage what I'll do is use the classes list and just assume everything following a "real" class is a "real" member. The reason is that it will take the least time to implement. Thanks.
Roee Adler
+1  A: 

To get all classes and methods you can look at the index on http://java.sun.com/javase/6/docs/api/index-files/index-1.html

This will be 10's of thousands classes and method which can be overwhelming.

I suggest instead you use auto-complete in your IDE. This will show you all the matching classes/methods appropriate based on context. e.g. say you have a variable

long time = System.

This will show you all the methods in System which return a long value, such as

long time = System.nanoTime();

Even if you know a lot of the method/classes, this can save you a lot of typing.

Peter Lawrey
Thanks, that contains plenty of manual work (a regex on that list is problematic)
Roee Adler
A: 

When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name.

If thats what you're after, you could do without a (limited) list of Java Classes by using some simple reflection: http://java.sun.com/developer/technicalArticles/ALT/Reflection/

try {
  Class.forName("word.word");
  System.out.println("This is a valid class!");
} catch (ClassNotFoundException e) {
  System.out.println("This is not a valid class.");
}

Something like this should be enough for your purposes, with he added benefit of not being limited to a subset of classes, and extensible by any libraries on the classpath.

Tim
I didn't say I was working in Java :) My code is actually in Python.
Roee Adler
+1  A: 

If you just want to create a list of all classes in Java and their methods (so that you can populate a database or an XML file), you may want to write an Eclipse-plugin that looks at the entire JavaCore model, and scans all of its classes (e.g., by searching all subtypes of Object). Then enumerate all the methods. You can do that technically to any library by including it in your context.

Uri
Yeah, it should be possible to produce pretty much any output with custom Doclets: http://java.sun.com/javase/6/docs/technotes/guides/javadoc/index.html
McDowell
+1  A: 

IBM had a tool for creating XML from JavaDocs, if I am not mistaken: http://www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html

Uri
A: 

There's also an option to either parse classlist file from jre/lib folder or open the jsse.jar file, list all classes there and make a list of them in dot-separated form by yourself.

macbirdie
I don't understand what you mean. Can you please elaborate?
Roee Adler
There are two files in the JRE's lib folder - classlist and jsse.jar . The primer contains list of all classes in the library, the latter is a jar containing all standard runtime classes. You can use those to make a list of standard library classes to use in your parser.
macbirdie