所有Java标准类和方法的简单列表?

时间:2021-03-02 19:33:50

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.

我正在构建一个非常简单的Java解析器,以寻找一些特定的使用模型。对于运行代码的目的,这绝不是lex / yacc或任何其他形式的解释器/编译器。

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.

当我遇到一个单词或一组两个用点分隔的单词(“word.word”)时,我想知道这是否是标准的Java类(和方法),例如“整数”,或一些用户定义的名称。我对代码中是否包含/导入了正确的类(如果代码编译得很好)并不感兴趣,并且覆盖标准Java类名称的用户定义类的极端情况也不感兴趣。换句话说:我对假阴性没什么好处,我只是对“大多数”正确感兴趣。

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.

如果有一个地方我可以找到所有Java标准类和方法的所有名称的简单列表,在表单中容易保存到文本文件或数据库中? (J2SE没问题,但J2EE更好)。我熟悉http://java.sun.com/j2se/等,但似乎我需要大量的手工工作才能从中提取所有名称。此外,最新的JDK不是必需的,我可以使用1.4或1.5。

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

澄清:我不是在Java中工作,而是在Python中,所以我不能在我的解析机制中使用特定于Java的命令。

Thanks

6 个解决方案

#1


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

javadoc有什么问题?索引列出了所有类,方法和静态变量。你可以用grep来表示括号。

#2


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

要获取所有类和方法,可以查看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

我建议您在IDE中使用auto-complete。这将根据上下文向您显示所有匹配的类/方法。例如说你有一个变量

long time = System.

很长时间=系统。

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

这将显示System中返回long值的所有方法,例如

long time = System.nanoTime();

long time = System.nanoTime();

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

即使你知道很多方法/类,这也可以节省大量的输入。

#3


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.

如果您只想创建Java中所有类及其方法的列表(以便可以填充数据库或XML文件),您可能需要编写一个查看整个JavaCore模型的Eclipse插件,并扫描所有其类(例如,通过搜索Object的所有子类型)。然后枚举所有方法。您可以通过将其包含在您的上下文中来技术上对任何库执行此操作。

#4


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

如果我没有弄错的话,IBM有一个从JavaDocs创建XML的工具:http://www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html

#5


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.

还有一个选项可以从jre / lib文件夹解析classlist文件或打开jsse.jar文件,列出所有类,并自己以点分隔的形式列出它们。

#6


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.

当我遇到一个单词或一组两个用点分隔的单词(“word.word”)时,我想知道这是否是标准的Java类(和方法),例如“整数”,或一些用户定义的名称。

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/

如果这就是你所追求的,你可以通过一些简单的反思来做一个(有限的)Java类列表: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.

像这样的东西应该足以满足你的目的,他增加的好处是不限于类的子集,并且可以通过类路径上的任何库进行扩展。

#1


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

javadoc有什么问题?索引列出了所有类,方法和静态变量。你可以用grep来表示括号。

#2


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

要获取所有类和方法,可以查看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

我建议您在IDE中使用auto-complete。这将根据上下文向您显示所有匹配的类/方法。例如说你有一个变量

long time = System.

很长时间=系统。

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

这将显示System中返回long值的所有方法,例如

long time = System.nanoTime();

long time = System.nanoTime();

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

即使你知道很多方法/类,这也可以节省大量的输入。

#3


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.

如果您只想创建Java中所有类及其方法的列表(以便可以填充数据库或XML文件),您可能需要编写一个查看整个JavaCore模型的Eclipse插件,并扫描所有其类(例如,通过搜索Object的所有子类型)。然后枚举所有方法。您可以通过将其包含在您的上下文中来技术上对任何库执行此操作。

#4


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

如果我没有弄错的话,IBM有一个从JavaDocs创建XML的工具:http://www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html

#5


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.

还有一个选项可以从jre / lib文件夹解析classlist文件或打开jsse.jar文件,列出所有类,并自己以点分隔的形式列出它们。

#6


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.

当我遇到一个单词或一组两个用点分隔的单词(“word.word”)时,我想知道这是否是标准的Java类(和方法),例如“整数”,或一些用户定义的名称。

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/

如果这就是你所追求的,你可以通过一些简单的反思来做一个(有限的)Java类列表: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.

像这样的东西应该足以满足你的目的,他增加的好处是不限于类的子集,并且可以通过类路径上的任何库进行扩展。