Wednesday, October 1, 2014

How to find current java class name and package of the current line in vim?

I want to find out the class name and package name that contains the source line where the cursor is currently positioned.

For example given the source below I want to implement a vimscript method that returns "com.example.test.MyClass" given the cursor position.


package com.example.test;

public class MyClass extends Activity {

protected void init() {

.....
...... <- cursor here
}
}


I found that the Tagbar plugin has a method called tagbar#currenttag() that is close to what I want but it returns only the closest tag to the current line. I only want to get the closet tag that is a class and ignore methods, interfaces and fields. Also it wont include the package name that is something I need.

I tried using the tags file directly but these do not contain file lines so it is difficult to extract the class name given only the filename and line number.



I am trying to fix all the java debugger connectors (yavdb, dbg.vim, JavaKit, etc.). All these are 4 years old and use the filename and line number to set breakpoints in the debugger (jdb) but the current version of jdb requires the class name instead of the filename.

All I need is a way within vim to find out the current line class name and package name and I would be able to modify these plugins so they work with current jdb.

regards,

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: