senny / emacs-eclim

This project brings some of the great eclipse features to emacs developers. It is based on the eclim project, which provides eclipse features for vim.
http://www.emacswiki.org/emacs/EmacsEclim
587 stars 102 forks source link

eclim-java-find-type ignores files in jars #250

Open gdanov opened 8 years ago

gdanov commented 8 years ago

I have java project where the source codes for external libs (incl. the jdk) are in jars. When I run the eclimd command that eclim-emacs dumps in the terminal I get result, but it's filtered out from what I can see in the source code. Details:

the terminal command

eclim -command java_search -p Integer -t type -x declarations -s workspace -i ''

result

[{"filename":"jar:file:///Library/Java/JavaVirtualMachines/1.6.0_29-b11-402.jdk/Contents/Classes/classes.jar!java/lang/Integer.class","offset":-1,"length":0,"line":1,"column":1,"message":"java.lang.Integer"},{"filename":"zip:///Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/src.zip!/java/lang/Integer.java","offset":1149,"length":7,"line":52,"column":20,"message":"java.lang.Integer"}]

eclim grep view pops-up and shows empty result. Same also with a class from another lib where the jar contains the .class as well as the .java files. I suspect that this is where these results are filtered out: https://github.com/senny/emacs-eclim/blob/master/eclim.el#L371

(defun eclim--find-display-results (pattern results &optional open-single-file)
  (let ((results (remove-if (lambda (result) (string-match (rx bol (or "jar" "zip") ":") (assoc-default 'filename result))) results)))

I guess there is good reason for that. I am interested to understand how to set-up my project so that emacs-eclim would be able to display these results

sampajano commented 8 years ago

+1 This is very useful for android programming as I quite often need to look up builtin class definitions. The default behavior in the Vim plugin is locating the jar and opening the class file.

Also with the existing packages like https://github.com/gbalats/autodisass-java-bytecode, there is a very simple fix.

JordanFaust commented 8 years ago

Eclim already provides an API for reading from a archive file: https://github.com/ervandew/eclim/blob/2.5.0/org.eclim.core/java/org/eclim/plugin/core/command/archive/ArchiveReadCommand.java

This command will create a temporary file that contains the contents of the decompiled java file just as you would see when using eclipse to "goto declaration".

EDIT:

Example command executed by the vim plugin:

-editor vim -command archive_read -f "jar:///Users/path/to/.m2/repository/org/apache/curator/curator-framework/2.7.1/curator-framework-2.7.1-sources.jar!/org/apache/curator/framework/CuratorFramework.java"