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

2

12

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.

Derrek answered 26/7, 2014 at 10:3 Comment(6)
I haven't worked with custom classpath containers, yet. But I think the javaCompletionProposalComputer might be a good start. The coderecommenders project has an example of usage: git.eclipse.org/c/recommenders/org.eclipse.recommenders.git/…Ferrer
you are using RAD / eclipse?Oho
@Ferrer I will have a look into your suggestion. Maybe this will be of help.Derrek
@KalpeshSoni Yes, I use Eclipse.Derrek
This may help, even though it does not directly address the question: #2390871Pharmacology
A deleted answer suggested peeking into the m2 sources for further advice.Derrek
D
1

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.

Derrek answered 9/7, 2015 at 15:7 Comment(0)
S
0

I use Eclipse Luna and Eclipse does autocomplete code even from custom external JARs. You should consider upgrading to Luna if you haven't already and see it solves your problem

Silin answered 16/11, 2014 at 6:26 Comment(2)
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.Frederiksen
Sorry @Hamad, I would have commented if I had enough reputation.Silin

© 2022 - 2024 — McMap. All rights reserved.