[TxMt] useful java commands

Lang Riley lang at langriley.com
Fri Dec 31 21:18:35 UTC 2004


Command purpose: Do a reasonably valiant attempt to locate all senders 
of a particular message/method within the project.
Usage: Highlight the method name, excluding the parameter portion of 
the method signature, and execute this command.  It will search across 
all source in your project and return a clickable list of method 
invocations.  It doesn't work perfectly, but it often works very 
satisfactorily.  Example, you would like to find all the places where 
public void handleRequest(HttpServletRequest request, 
HttpServletResponse response) is used, simply highlight handleRequest 
and execute the command which will bring up a window with links to 
these occurrences.
Command:

grep -rn "\.$TM_SELECTED_TEXT(" $TM_PROJECT_DIRECTORY | grep "\.java"

Standard Input:  None
Standard Ouput: Show in separate window
Pattern: ^.*\/(\w+\.java):(\d+):.*
Format string: $1 $2
File register: 1 Line: 2


Command purpose: Do a reasonably good job of finding all declarations 
of a particular method within the project.
Usage: Same as above.
Command:

grep -rn "[ ]$TM_SELECTED_TEXT(" $TM_PROJECT_DIRECTORY | grep "\.java"

Standard Input:  None
Standard Ouput: Show in separate window
Pattern: ^.*\/(\w+\.java):(\d+):.*
Format string: $1 $2
File register: 1 Line: 2

Command purpose: Do a reasonably good job of finding a class definition 
within the project.
Usage: Same as above, but highlight the class name.  Example, 
Dispatcher d = new DispatcherServlet();, highlight DispatcherServlet 
and execute the command.  This will bring up a window with clickable 
links to each declaration found.
Command:

egrep -rns "class[ ]+$TM_SELECTED_TEXT[ ]+" $TM_PROJECT_DIRECTORY | 
grep "\.java"

Standard Input:  None
Standard Ouput: Show in separate window
Pattern: ^.*\/(\w+\.java):(\d+):.*
Format string: $1 $2
File register: 1 Line: 2


Command purpose: Do a reasonably good job of finding an interface 
definition within the project.
Usage: Same as above, but highlight the class name.  Example, 
Dispatcher d = new DispatcherServlet();, highlight Dispatcher (assuming 
it is an interface) and execute the command.  This will bring up a 
window with clickable links to each declaration found.
Command:

egrep -rns "interface[ ]+$TM_SELECTED_TEXT[ ]+" $TM_PROJECT_DIRECTORY | 
grep "\.java"

Standard Input:  None
Standard Ouput: Show in separate window
Pattern: ^.*\/(\w+\.java):(\d+):.*
Format string: $1 $2
File register: 1 Line: 2


Command purpose: Open a window listing all the methods found in a 
particular class. assuming the class containing the method definitions 
exists in the project.
Usage: Highlight the class name for which you would like to search, 
then execute the command.  This will bring up a window, no links sorry, 
that lists the method signature for each of the methods local to that 
class, i.e., non-inherited methods.  I find this useful when I quickly 
want to find what methods are available without having to search for 
the file or read documentation.


cat `egrep -rnsl "class[ ]+$TM_SELECTED_TEXT[ ]+" .` | egrep "public[ 
]+\<.*\>[ ]+\<.*\>\(.*\)[ ]+(throws .*|){"

Standard Input:  None
Standard Ouput: Show in separate window
Pattern: ^.*\/(\w+\.java):(\d+):.*
Format string: $1 $2
File register: 1 Line: 2


Enjoy,

Lang Riley




More information about the textmate mailing list