如何自动完成在Java中与反思的作品? [英] How Auto Complete in java works with Reflection?

查看:145
本文介绍了如何自动完成在Java中与反思的作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说Eclipse使用反射来提供其自动完成features.But它是如何实际工作?我搜索谷歌,但发现it.Can任何人都没有好文章,请解释程序或提供我与任何有用的文章.Thanks提前。

I have heard that Eclipse uses reflection to provide its auto complete features.But How does it work actually?I searched Google but found no good article on it.Can Anyone please explain the procedures or provide me with any useful article on it.Thanks in advance.

推荐答案

反射的API只能告诉你正在运行(或者至少,它是一个程序中加载code,在一个完整的编译状态,准备运行)。当你编辑code,它没有运行,并且它不会加载到一个JVM,所以它不可能使用反射检查。也有在Eclipse的自动完成信息通过反射将不可用,如当地(内法)变量的名字。

The reflection APIs can only tell you about code that is running (or at least, it is loaded within a program, in a complete compiled state, ready to run). When you're editing your code, it's not running, and it's not loaded into a JVM, so it can't possibly be examined using reflection. There is also information in Eclipse's auto-complete that is never available via reflection, such as names of local (within-method) variables.

相反,Eclipse拥有自己的编译器。它直接读取源$ C ​​$ c和使用它来建立自己的可用类,方法,构造函数,字段和局部变量的理解。这些信息被用于由几个编辑功能,包括自动完成。

Instead, Eclipse has its own compiler. It reads the source code directly and uses this to build its own understanding of the available classes, methods, constructors, fields and local variables. That information is used by several editing features including auto-complete.

此外,当源$ C ​​$ c是不可用,Eclipse可以通过直接读取编译的.class文件获取自动完成的部分信息。 .class文件结构是完全记录。 (有几个原因,这仅仅是部分的信息。一方面,它不包括局部变量的信息,如果类是无调试信息的编制,也通常不包括方法参数的名字。(Java的8增加其中可用于记录方法的参数名称的类文件格式的新MethodParameters属性,但javac的默认不这样做。))

Additionally, when the source code is not available, Eclipse can get partial information for auto-complete by reading compiled .class files directly. The .class file structure is fully documented. (There are several reasons why this is only "partial" information. For one thing, it does not include information about local variables if the class was compiled without debugging information. It also does not typically include the names of method parameters. (Java 8 has added a new "MethodParameters" attribute in the class file format which can be used to record the method parameter names, but javac does not do this by default.))

我对Eclipse的内部专家,但我想/希望这是正确的。

I'm no expert on Eclipse's internals but I think/hope this is accurate.

这篇关于如何自动完成在Java中与反思的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆