Jsearch
Have you ever need to find what package a Java class belongs to without using an IDE? Let me tell a history.
Back in 1999, when I started using Java with JDK 1.1.6 (not really sure about the date and version), we need to look for the package on the documentation. Again I'm not really sure there was online documentation as we have here (I live in Brazil, internet access was a bit late here) but what I'm really sure is that I used a big book ("The Java Class Libraries") with all the Java APIs to search for info.
I also used some IDEs available back then, such as Symantec's Visual Café, Forté for Java (this one will become NetBeans) but I realized it was more complicated to maintain code on such tools than straight on my Vim editor (yes, I already use it back then), so I abandoned all IDEs and wrote my Java code using only the text editor, and trust me, I was life changing. The code size got 50% smaller and 50% faster.
But in the coming years, when I saw Java code snippets, I never saw people
mentioning the packages the classes used, so I needed to find them by myself
again. What I didn't know is the current IDEs were smarter and with a simple
CTRL+ENTER
they find and import the packages for you. I kept years wondering
why people never mentioned the packages on the snippets, and that was the cause.
As I kept using my text editor, never realized that. Oh, ok, life goes on.
Nowadays I keep using my Vim editor (Neovim most part of the time) to keep some of my Java code (for other languages, like Ruby, use it 100% of the time), while when developing Android apps I use Java and Kotlin inside Android Studio (and fry my CPUs), but finally I decided to make a tool to help me avoid going on the Oracle docs to find the correct package for a class, and then I created Jsearch on a weekend. Basically I use it to find the package of a class, and also gives me the import statement to copy and paste on my Java code file. No bells and whistles, just this.
And yes, I know there are very good options out there to configure Vim (specially Neovim) for Java development, such as nvim-jdtls, which depends on eclipse.jdt.ls and some configurations (sometimes, lots) to configure the editor with some features almost equals to some Java IDE, but I just need less stuff to get and less stuff to configure, so ...
Installation
gem install jsearch
Usage
Use: jsearch [options]
-c, --class CLASS Class to search
-p, --package Show package
-i, --import Show import statement
-s, --silent Don't show output
--cache-size Show cache size
--clear-cache Clear cache
-b, --base URL URL to search for classes reference
-h, --help Show help
It can be used with a small and simple Vim plugin I made.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/taq/jsearch.