3 # $Id: jtags,v 1.12.2.1 2006/03/05 04:20:23 paulk Exp $
5 # Usage: jtags [-h | srcdir]
7 # Abstract: This Bourne shell script produces an Emacs
8 # tags file for Java source code. The tags file
9 # contains tags for classes, interfaces, constructors,
10 # methods, and variables.
12 # Options: -h Print usage.
14 # -srcdir Path of top-level directory containing
15 # Java source(*.java) files to be tagged.
16 # If omitted, this script tags files in
17 # the working directory and its subdirectories.
23 # Thanks: David Lim <david@ndc.com>
24 # Michael Mirman <mmirman@mathworks.com>
25 # Kent S. Gordon" <kgor@inetspace.com>
27 # Set this to the path of the etags executable if it is
28 # not in the shell path.
32 if [ "$1" = "-h" ] || [ "$1" = "-help" ] ||
33 [ "$1" = "-usage" ]; then
35 echo "usage: jtags [-h | srcdir]"
37 echo "srcdir Path of the Java source directory."
39 echo "This command tags all public classes, interfaces,"
40 echo "methods, and variables in the specified Java source"
41 echo "hierarchy. If you do not specify a source directory,"
42 echo "jtags searches the current directory and its"
43 echo "subdirectories."
48 # If not the help option, assume first (should be only) parameter
49 # is the source path. If no parameters, default to the working
53 # Ensure that Java source directory exists.
54 if [ ! -d $java_dir ]; then
55 echo "Java source directory $java_dir not found."
64 primitive_type1='\<\(b\(oolean\|yte\)\|char\|double\|float\|int'
65 primitive_type2='\|long\|short\|void\)\>'
66 primitive_type="$primitive_type1$primitive_type2"
67 primitive_type_count=2
69 primitive_type3='\|long\|short\)\>'
70 primitive_type_no_void="$primitive_type1$primitive_type3"
71 primitive_type_no_void_count=2
73 identifier="\<\([$letter][$letter$digit]*\)\>"
76 class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
79 modifier1='\<\(abstract\|const\|final\|native\|'
80 modifier2='p\(r\(ivate\|otected\)\|ublic\)\|'
81 modifier3='s\(tatic\|ynchronized\)\|transient\|volatile\)\>'
82 modifier="$modifier1$modifier2$modifier3"
86 class1="/^$ws*\<\(class\|interface\)\>$ws*$identifier/\2/"
87 class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
90 constructor="/^$ws*\($modifier$ws*\)*$class_type$ws*(/\6/"
92 # Pattern for methods that return primitive types, e.g.,
96 method1="/^[^.*\/]*$primitive_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\4/"
98 # Pattern for methods that return class types, e.g.,
102 method2="/^[^.*\/]*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\3/"
104 # Pattern for matching primitive variable declarations.
105 var1a=".*$primitive_type_no_void$ws*\(\[$ws*\]$ws*\)*$identifier"
107 var1="/$var1a$var1b/\4/"
109 # Pattern for matching user-defined variable declarations.
110 var2a=".*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier"
112 var2="/$var2a$var2b/\3/"
114 # Delete the old TAGS file.
115 # Note: the old file must be deleted because we have to run
116 # etags in append mode. If we don't remove the old file,
117 # etags will append everything to the old file.
119 if [ -f ${java_dir}/TAGS ]; then
121 echo "Removed old TAGS file."
124 # Use find to recurse through the source hierarchy,
125 # finding every java source file.
126 # Use xargs to apply etags to the source files.
127 # Note that xargs may invoke etags multiple
128 # times, depending on how many files it can batch
129 # per invocation. That is why we run etags in
132 echo "Tagging everything"
133 find $java_dir \( -name RCS -prune \) -o \( -name CVS -prune \) -o \( -name '*.java' -print \) | xargs \
134 "${etags_dir}etags" -l none -a -o ${java_dir}/TAGS \
135 "--regex=$class1" "--regex=$class2" "--regex=$constructor" \
136 "--regex=$method1" "--regex=$method2" \
137 "--regex=$var1" "--regex=$var2"
143 # Revision 1.12.2.1 2006/03/05 04:20:23 paulk
144 # Revert to tagging everthing in one invocation of the find command. Thanks to Jon Schewe <jon.schewe@honeywell.com>.
146 # Revision 1.12 2002/09/16 04:53:11 paulk
147 # Quote path of etags executable to permit inclusion of spaces on Windows. Thanks to Jens Barnow.
149 # Revision 1.11 2001/01/06 05:29:58 paulk
150 # Add "\." below to the definition of class_type so
151 # that methods whose return type included a period (e.g, Foo.Bar)
154 # class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
156 # Thanks to Charles Rich <rich@merl.com>
158 # Revision 1.10 2000/12/23 04:29:57 paulk
159 # (1) Added "-l none" to the etags arguments (all four calls) to
160 # eliminate the additional spurious tags that were coming from etags'
161 # default java parsing:
163 # ${etags_dir}etags -l none -a -o ${java_dir}/TAGS \
165 # (2) Added "\/" to the prohibited characters at the start of class2,
166 # method1 and method2 to prevent comment lines like
168 # // this is a nice interface for catching mice
172 # class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
174 # Thanks to Charles Rich <rich@merl.com> for these improvements.
176 # Revision 1.9 1999/08/19 10:19:51 paulk
177 # Added prune clause for RCS.
179 # Revision 1.8 1998/02/19 04:08:24 kinnucan
180 # More edits to the comments.
182 # Revision 1.7 1998/02/19 03:45:03 kinnucan
183 # Cleaned up the comments.
185 # Revision 1.6 1998/02/19 03:42:05 kinnucan
186 # "Kent S. Gordon" <kgor@inetspace.com> contributed the following
189 # - Change some .* expressions to [^.*] to prevent matches
190 # in source file comments and functions.
192 # - Removed . from class_type since declarations should never
193 # be for another package.
197 # Revision 1.5 1997/12/03 03:31:29 kinnucan
198 # Divided tagging process into three passes
199 # through the source hierarchy to avoid overflowing
202 # Revision 1.4 1997/10/06 04:48:58 kinnucan
203 # Replaced existing regular expressions with a new set
204 # based on those contained in andersl-java-font-lock.el
206 # Revision 1.3 1997/08/26 09:10:44 kinnucan
207 # Added revision number.
209 # Revision 1.2 1997/08/26 09:02:42 kinnucan
210 # 1. Exclude RCS directories from tags search.
211 # 2. Added regular expression for abstract classes.
215 # End of jtags script.