vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

No definition from an external JAR

Open kamtungc opened this issue 9 years ago • 4 comments

No class definition is found in an external library

Environment
  • Operating System: Windows 10 or Mac OS.
  • JDK version: C:\Program Files\Java\jdk1.8.0_121
  • Visual Studio Code version: 1.9.1
  • Java extension version: v0.0.10
Steps To Reproduce
  1. I have "import com.foo.FooFunction;" in my java file. When I click on the FooFunction, no definition is found.
  2. But all other public libraries, such as "import org.springframework.http.HttpStatus;" or current project import works as expected.
Current Result

No class definition is found.

Expected Result

Class definition shows up.

Additional Informations

I am using Gradle to build my project.

The .classpath contains default entries:

Questions

  1. Can I declare external JAVA source code paths for using this extension?
  2. How should I build foo.jar for using this extension?
  3. Does foo.jar have to contain JAVA source codes? Or does foo.jar have to have javadoc?
  4. IntelliJ decompile jar files to find class definitions. can we do something like that?

kamtungc avatar Feb 22 '17 18:02 kamtungc

I assume by class definition you mean Javadoc.

Do you see the same results when importing the project in Eclipse (as a Gradle project, via BuildShip)?

The way buildship (the vscode-java uses under the hood) configures the classpath, you have no way to specify custom sources.

I'm not entirely sure how gradle/buildship discover sources, but it's very likely you need to put a foo-sources.jar along foo.jar (foo-javadoc.jar would also work).

Adding a decompiler to vscode-java (eclipse.jdt.ls really) would certainly present some legal challenges, I don't think it's worth the trouble.

fbricon avatar Feb 22 '17 19:02 fbricon

When I right clicked on "import com.foo.FooFunction;" and selected either "Go to Definition" or "Peek Definition", nothing happened. And, I got no description about "import com.foo.FooFunction;" if I just pointed on it.

For "import org.springframework.http.HttpStatus;", after I right clicked and selected "Go to Definition"; I could jump to some codes. If I just moved my mouse cursor on the top of "import org.springframework.http.HttpStatus;", I got some definition on how to use this. I believe it is Javadoc.

For decompiling, IntelliJ said it found the class definition by decompiling jar. And it said I could point to some local path for locating the actual source code. Yes, vscode-java does not need to decompile the jar file.

After all, it sounds like the main issue on my "import com.foo.FooFunction;" is because foo.jar does not have either source codes or JavaDoc reference. Even IntelliJ cannot find the information without decompiling the jar file.

But a dependence section in build.gradle can include "foo:1.0.1" (for foo.jar). I don't know whether it works for both "foo:1.0.1" (for foo.jar) and "foo-source:1.0.1" (for foo-source.jar).

I want to check any easy way to get class information from vscode-java.

kamtungc avatar Feb 22 '17 19:02 kamtungc

So, can I say that "Go to Definition" in vscode-java works with a jar only if the jar has JavaDoc?

kamtungc avatar Feb 22 '17 22:02 kamtungc

@kamtungc yes, if JavaDoc or source for the jar can be resolved we can provide hovers. If source exists vscode-java can navigate to them.

gorkem avatar Feb 22 '17 22:02 gorkem