Initial Commit
[packages] / xemacs-packages / jde / lisp / jtags
1 #! /bin/sh
2 #
3 # $Id: jtags,v 1.12.2.1 2006/03/05 04:20:23 paulk Exp $
4 #
5 # Usage:     jtags [-h | srcdir]
6 #
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.
11 #
12 # Options:   -h  Print usage.
13 #
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.
18 #
19 # By:        Paul Kinnucan 
20 #            The MathWorks, Inc.
21 #            paulk@mathworks.com
22 #
23 # Thanks:    David Lim <david@ndc.com>
24 #            Michael Mirman <mmirman@mathworks.com>
25 #            Kent S. Gordon" <kgor@inetspace.com>
26 #
27 # Set this to the path of the etags executable if it is
28 # not in the shell path.
29 etags_dir=""
30
31 # Print help.
32 if [ "$1" = "-h" ] || [ "$1" = "-help" ] ||
33    [ "$1" = "-usage" ]; then
34     echo ""
35     echo "usage: jtags [-h | srcdir]"
36     echo ""
37     echo "srcdir   Path of the Java source directory."
38     echo ""
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."
44     echo ""
45     exit 1
46 fi
47
48 # If not the help option, assume first (should be only) parameter
49 # is the source path. If no parameters, default to the working
50 # directory.
51 java_dir=${1-.}
52
53 # Ensure that Java source directory exists.
54 if [ ! -d $java_dir ]; then
55     echo "Java source directory $java_dir not found."
56     exit 1
57 fi
58
59 capital='A-Z'
60 letter='a-zA-Z_.'
61 digit='0-9'
62 ws='[ \t]'
63
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
68
69 primitive_type3='\|long\|short\)\>'
70 primitive_type_no_void="$primitive_type1$primitive_type3"
71 primitive_type_no_void_count=2
72
73 identifier="\<\([$letter][$letter$digit]*\)\>"
74 identifier_count=1
75
76 class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
77 class_type_count=1
78
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"
83 modifier_count=4
84
85 # Class patterns
86 class1="/^$ws*\<\(class\|interface\)\>$ws*$identifier/\2/"
87 class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
88
89 # Constructor pattern
90 constructor="/^$ws*\($modifier$ws*\)*$class_type$ws*(/\6/"
91
92 # Pattern for methods that return primitive types, e.g.,
93 #
94 #   int[] foo()
95 #
96 method1="/^[^.*\/]*$primitive_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\4/"
97
98 # Pattern for methods that return class types, e.g.,
99 #
100 #   Foo[] foo()
101 #
102 method2="/^[^.*\/]*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\3/"
103
104 # Pattern for matching primitive variable declarations.
105 var1a=".*$primitive_type_no_void$ws*\(\[$ws*\]$ws*\)*$identifier"
106 var1b="$ws*\(=\|;\)"
107 var1="/$var1a$var1b/\4/"
108
109 # Pattern for matching user-defined variable declarations.
110 var2a=".*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier"
111 var2b="$ws*\(=\|;\)"
112 var2="/$var2a$var2b/\3/"
113
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.
118
119 if [ -f ${java_dir}/TAGS ]; then
120     rm ${java_dir}/TAGS
121     echo "Removed old TAGS file."
122 fi
123
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
130 # append (-a) mode.
131
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"
138
139
140 # History:
141 #
142 # $Log: jtags,v $
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>.
145 #
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.
148 #
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)
152 # were tagged:
153 #
154 #   class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
155 #
156 # Thanks to Charles Rich <rich@merl.com>
157 #
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:
162 #
163 #     ${etags_dir}etags -l none -a -o ${java_dir}/TAGS \
164 #
165 # (2) Added "\/" to the prohibited characters at the start of class2,
166 # method1 and method2 to prevent comment lines like
167 #
168 # // this is a nice interface for catching mice
169 #
170 # getting tagged:
171 #
172 #     class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
173 #
174 # Thanks to Charles Rich <rich@merl.com>  for these improvements.
175 #
176 # Revision 1.9  1999/08/19 10:19:51  paulk
177 # Added prune clause for RCS.
178 #
179 # Revision 1.8  1998/02/19 04:08:24  kinnucan
180 # More edits to the comments.
181 #
182 # Revision 1.7  1998/02/19 03:45:03  kinnucan
183 # Cleaned up the comments.
184 #
185 # Revision 1.6  1998/02/19 03:42:05  kinnucan
186 # "Kent S. Gordon" <kgor@inetspace.com> contributed the following
187 # improvements
188 #
189 #  - Change some .* expressions to [^.*] to prevent matches
190 #    in source file comments and functions.
191 #
192 #  - Removed . from class_type since declarations should never
193 #    be for another package.
194 #
195 # Thanks Kent.
196 #
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
200 # the xargs bugger.
201 #
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
205 #
206 # Revision 1.3  1997/08/26 09:10:44  kinnucan
207 # Added revision number.
208 #
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.
212 #
213 #
214
215 # End of jtags script.