0

like:

import com.xxx.utility.*;
class MyClass{
    public static void main(String[] args){
        MyUtiliy ut = new MyUtiliy();
        MyUtility.doAdd(5, 6);
        .......
    }    
}

When put the "." after MyUtiliy, eclipse will tell you all the methods you can use, how does eclipse achieve this?

Does eclipse use the reflection on the fly? (like the answer of this thread? )

Community
  • 1
  • 1
chailong
  • 286
  • 3
  • 11

3 Answers3

0

The architecture of the eclipse software is describe here, in the section 6.1.2. Java Development Tools (JDT) it briefly describes the incremental build system used. That system would have all the relavent information to populate the autocomplete mechanism.

For the exact mechanism, you would have to look at the eclipse source code.

norlesh
  • 1,749
  • 11
  • 23
0

Yes Eclipse (and any other Java IDEs) uses reflection.

If fact Eclipse uses a ClassLoader for each project's libraries, so it load the classes in jar files, and after that everything is easy, it can get information using reflection.

By the way java IDEs not only use reflection, but also read class debug info, to extract parameter names, and so on.

Amir Pashazadeh
  • 7,170
  • 3
  • 39
  • 69
0

There is an explanation in this article. Basically the Eclipse Java compiler builds an Abstract Syntax Tree (AST) of your code which lets it find all the information it needs for autocompletion very quickly.

So it is not using reflection for this, rather it is compiling the code in to an internal form for quick access.

When no source code is available (you just have a .class file) it is still possible to construct the part of the AST containing the class methods and types which are needed for completion. This appears to be done by reading the .class files directly rather than using a class loader (org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader)

greg-449
  • 109,219
  • 232
  • 102
  • 145