2

Is it possible to get a list of methods of the class from command line?

In Eclipse or Intellij IDEA one usually hits ctrl + space for autocompletion menu. It's cool, but I wish to get something alike from bash.

E.g. I have a class that extends a class (or classes if the parent also extends a class) and implements a couple of interfaces - so I need to know which methods I'm able to use.


P.S. I use vim 'cause I have memory limitations to use entire IDE.

2
  • For c you could use cscope, I don't think there is such a tool for Java. You could probably write one. There is the, sadly not up to date, Java Development Environment for Emacs. Commented Aug 22, 2016 at 2:34
  • 1
    This wouldn't be very hard to implement yourself. You could write a Java program that uses Class.forName(args[0]).getMethods() and display them. Commented Aug 22, 2016 at 2:44

2 Answers 2

3

You can use the java disassembler: javap:

Example

Compile the following DocFooter class:

import java.awt.*;
import java.applet.*;
 
public class DocFooter extends Applet {
        String date;
        String email;
 
        public void init() {
                resize(500,100);
                date = getParameter("LAST_UPDATED");
                email = getParameter("EMAIL");
        }
 
        public void paint(Graphics g) {
                g.drawString(date + " by ",100, 15);
                g.drawString(email,290,15);
        }
}

The output from the javap DocFooter.class command yields the following:

Compiled from "DocFooter.java"
public class DocFooter extends java.applet.Applet {
  java.lang.String date;
  java.lang.String email;
  public DocFooter();
  public void init();
  public void paint(java.awt.Graphics);
}
Sign up to request clarification or add additional context in comments.

6 Comments

Hmm, I didn't know about javap disassembler and it's features. Thank for the hint. It does work like a charm on custom classes, but I also wished to disassemble standard Java classes (like e.g. ArrayList) to get fast-list of fields/constructors/methods (if it is possible).
The standard Java classes are all inside rt.jar and a jar file is just a zip file, so you can extract whichever class file you want and decompile it.
Severe decision, but it works. As far as I understood, javap can't read a class from stdin, can it?
@UmbraAeternitatis Just type javap -private java.util.ArrayList on the command line (or don't use -private if you don't want private methods/fields)
I tried to javap ArrayList, but... I failed to understand to pass full path.
|
0

While I would advice spending a bit of money on more RAM, you could using ctags instead. I'm not sure if it's up to date with Java 7/8/9 features, but here's a blog describing how to use it: http://andrewradev.com/2011/06/08/vim-and-ctags/

1 Comment

ctags seems to be interesting tool. Perhaps I should try it - I can't get any effect from it for now. It's does not seem to be trivial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.