Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are classes kept in jars added via custom classpath container not available for code completion?

What is necessary to get classes provided via custom classpath container visible in the code completion?

I have successfully implemented a custom classpath container, that adds libraries to a project. It adds all jars in a specific folder to the build path unless there is a project with the same name in the workspace, in that case the project is referenced.

Now this obviously seems to work, when I refer to a class from one of those jars, the code compiles, but I do not see the class in the code completion suggestions. When I have the correct project in my workspace, then I see such a class in the code completion.

I have done the following steps to reach this, while I was partly considering a tutorial from IBM:

  • Implement ClasspathContainerInitializer
  • Implement ClasspathContainerPreferencePage for additional configuration
  • Implement IClasspathContainer

When I have added the container to a project I see the jars in the packages explorer as I expected it. (Jar there only if no corresponding project is available, Logging shows expected results)

I can use classes from jars integrated via classpath container without compiler errors, they are just not available for code completion and in Quick Fixes to add the right import. So I guess I maybe just miss contributing to some extension point.

like image 250
Markus Avatar asked Jul 26 '14 10:07

Markus


1 Answers

The answer basically is: You do not need to do anything more than implementing the three parts. But you have to do it the right way.

The ClasspathContainerPreferencePage to prepare the container for adding it to the project.

The ClasspathContainer as entity getting added to the project. For this one it is really important to implement all needed methods right. For me the problem was that I returned a wrong constant value in the method getKind(). Instead of returning IClasspathEntry.CPE_CONTAINER I just needed to use IClasspathContainer.K_APPLICATION and the code completion worked out of the box:

public int getKind() {
    return IClasspathContainer.K_APPLICATION;
}

And finally a ClasspathContainerInitializer for preparing and updating the container.

like image 197
Markus Avatar answered Sep 22 '22 06:09

Markus