Initial Commit
[packages] / xemacs-packages / jde / lisp / jde-java-font-lock.el
1 ;;; jde-java-font-lock.el -- Extra level font locking for java
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by David Ponce
4
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;;             Paul Kinnucan <paulk@mathworks.com>
8 ;; Created: September 28 1998
9 ;; Keywords: java, tools
10 ;; VC: $Id: jde-java-font-lock.el,v 1.24 2005/04/07 05:54:29 paulk Exp $
11
12 ;; This file is not part of Emacs
13
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
28
29 ;;; Commentary:
30 ;;
31 ;; Adds some extra level font locking for java in `jde-mode'.
32 ;;
33 ;; - Numbers are fontified with `jde-java-font-lock-number-face'.
34 ;;
35 ;; - Packages in package and import statements are fontified with
36 ;;   `jde-java-font-lock-package-face'.  Last '*' of imported packages
37 ;;   are fontified with `jde-java-font-lock-number-face'.  Last type
38 ;;   identifiers of imported packages are fontified with
39 ;;   `font-lock-type-face'.
40 ;;
41 ;; - Modifiers are fontified with `jde-java-font-lock-modifier-face'.
42 ;;
43 ;; - Keywords const and goto are fontified with
44 ;;   `font-lock-warning-face'.  These keywords are reserved, even
45 ;;   though they are not currently used.
46 ;;
47 ;; - Keywords super, this and default are fontified with
48 ;;   `font-lock-keyword-face'.
49 ;;
50 ;; - User's defined identifiers (see variable
51 ;;   `jde-java-font-lock-api-file') are fontified with
52 ;;   `jde-java-font-lock-api-face'.
53 ;;
54 ;; - Capitalized identifiers and special constants null, true and
55 ;;   false are fontified with `jde-java-font-lock-constant-face'.
56 ;;
57 ;; - Text between `' in comments and javadoc tags (including non
58 ;;   official javadoc tags) are fontified with
59 ;;   `jde-java-font-lock-doc-tag-face'.
60 ;;
61 ;; - Javadoc links (following @link tags or enclosed in HTML <a> tags)
62 ;;   are fontified with `jde-java-font-lock-link-face'
63 ;;
64 ;; - Javadoc code samples (enclosed in HTML <code> tags or following
65 ;;   @see tags) are fontified with `jde-java-font-lock-code-face'.
66 ;;  
67 ;; - Javadoc HTML bold and strong styles are fontified with
68 ;;   `jde-java-font-lock-bold-face'.
69 ;;
70 ;; - Javadoc HTML italic and emphasized styles are fontified with
71 ;;   `jde-java-font-lock-italic-face'.
72 ;;
73 ;; - Javadoc HTML underlined style is fontified with
74 ;;   `jde-java-font-lock-underline-face'.
75 ;;
76 ;; - Javadoc HTML preformatted style is fontified with
77 ;;   `jde-java-font-lock-pre-face'.
78 ;;
79 ;; All font-lock and jde-java-font-lock faces are individually
80 ;; customizable.  jde-java-font-lock faces are in the customization
81 ;; group `jde-java-font-lock-faces' which is a sub group of
82 ;; `font-lock-highlighting-faces' (Emacs) or `font-lock-faces'
83 ;; (XEmacs).
84
85 ;; This code has been tested with GNU Emacs 20.7, 21.0 and XEmacs
86 ;; 21.1.  Any comments, suggestions, bug reports or upgrade requests
87 ;; are welcome.  Please send them to the maintainers.
88
89 ;; WARNING: It seems there is byte-code compatibility issues between
90 ;; Emacs and XEmacs.  When using Emacs byte-code on XEmacs font
91 ;; locking don't work correctly for some complex matchers like those
92 ;; used to highlight imported package name :-)
93
94 ;;; History:
95 ;;
96 ;; See at end of this file.
97
98 ;;; Code:
99 (require 'font-lock)
100 (require 'regexp-opt)
101 (condition-case nil
102     (require 'cc-fonts)
103   (error nil))
104
105 (defcustom jde-use-font-lock t
106   "*Turn on font-locking if non-nil.
107 Set to nil to disable the use of font-locking."
108   :group 'jde-project
109   :type 'boolean)
110
111 (defcustom jde-java-font-lock-max-names-by-regexp
112   100
113   "*Maximum number of user defined names that one regexp can match.
114 No limit if less than 1.  For speed, the default value of 100 seems to
115 be a good compromize between the number of font lock keyword regexps
116 to match and the complexity of each regexp.
117
118 WARNING: It seems XEmacs search fails with a very long regexp.  So if
119 you have a lot of user's defined names don't use a value less than 1!"
120   :group 'jde-project
121   :type 'integer)
122 \f
123 ;;;;
124 ;;;; Define the faces
125 ;;;;
126
127 (defgroup jde-java-font-lock-faces nil
128   "Specific JDE faces for highlighting Java sources."
129   :prefix "jde-java-font-lock-"
130   :group (if (featurep 'xemacs)
131              'font-lock-faces
132            'font-lock-highlighting-faces))
133
134 (defface jde-java-font-lock-number-face
135   '((((class grayscale) (background light)) (:foreground "DimGray" :italic t))
136     (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
137     (((class color) (background light)) (:foreground "RosyBrown"))
138     (((class color) (background dark)) (:foreground "LightSalmon"))
139     (t (:italic t)))
140   "Font Lock mode face used to highlight numbers."
141   :group 'jde-java-font-lock-faces)
142
143 (defface jde-java-font-lock-operator-face
144   '((((class grayscale)) (:foreground "grey"))
145     (((class color)) (:foreground "medium blue"))
146     (t (:bold t)))
147   "Font Lock mode face used to highlight operators."
148   :group 'jde-java-font-lock-faces)
149
150 (defface jde-java-font-lock-constant-face
151   '((((type tty) (class color)) (:foreground "magenta"))
152     (((class grayscale) (background light))
153      (:foreground "LightGray" :bold t :underline t))
154     (((class grayscale) (background dark))
155      (:foreground "Gray50" :bold t :underline t))
156     (((class color) (background light)) (:foreground "CadetBlue"))
157     (((class color) (background dark)) (:foreground "Aquamarine"))
158     (t (:bold t :underline t)))
159   "Font Lock mode face used to highlight constants."
160   :group 'jde-java-font-lock-faces)
161
162 (defface jde-java-font-lock-api-face
163   '((((class grayscale) (background light)) (:foreground "DimGray"))
164     (((class grayscale) (background dark)) (:foreground "LightGray"))
165     (((class color) (background light)) (:foreground "dark goldenrod"))
166     (((class color) (background dark)) (:foreground "light goldenrod")))
167   "Font Lock mode face used to highlight user's defined names."
168   :group 'jde-java-font-lock-faces)
169
170 (defface jde-java-font-lock-link-face
171   '((t (:foreground "blue" :italic nil :underline t)))
172   "Font Lock mode face used to highlight links."
173   :group 'jde-java-font-lock-faces)
174
175 (defface jde-java-font-lock-package-face
176   '((((class color) (background dark)) (:foreground "steelblue1"))
177     (((class color) (background light)) (:foreground "blue3"))
178     (t (:underline t)))
179   "Font Lock Mode face used to highlight packages."
180   :group 'jde-java-font-lock-faces)
181
182 (defface jde-java-font-lock-doc-tag-face
183   '((((class color) (background dark)) (:foreground "light coral"))
184     (((class color) (background light)) (:foreground "green4"))
185     (t (:bold t)))
186   "Font Lock Mode face used to highlight doc tags."
187   :group 'jde-java-font-lock-faces)
188
189 (defface jde-java-font-lock-modifier-face
190   '((((type tty) (class color)) (:foreground "blue" :weight light))
191     (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
192     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
193     (((class color) (background light)) (:foreground "Orchid"))
194     (((class color) (background dark)) (:foreground "LightSteelBlue"))
195     (t (:bold t)))
196   "Font Lock Mode face used to highlight modifiers."
197   :group 'jde-java-font-lock-faces)
198
199 (defface jde-java-font-lock-private-face
200   '((((type tty) (class color)) (:foreground "blue" :weight light))
201     (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
202     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
203     (((class color) (background light)) (:foreground "Orchid"))
204     (((class color) (background dark)) (:foreground "LightSteelBlue"))
205     (t (:bold t)))
206   "Font Lock Mode face used to highlight private access."
207   :group 'jde-java-font-lock-faces)
208
209 (defface jde-java-font-lock-protected-face
210   '((((type tty) (class color)) (:foreground "blue" :weight light))
211     (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
212     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
213     (((class color) (background light)) (:foreground "Orchid"))
214     (((class color) (background dark)) (:foreground "LightSteelBlue"))
215     (t (:bold t)))
216   "Font Lock Mode face used to highlight protected access."
217   :group 'jde-java-font-lock-faces)
218
219 (defface jde-java-font-lock-public-face
220   '((((type tty) (class color)) (:foreground "blue" :weight light))
221     (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
222     (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
223     (((class color) (background light)) (:foreground "Orchid"))
224     (((class color) (background dark)) (:foreground "LightSteelBlue"))
225     (t (:bold t)))
226   "Font Lock Mode face used to highlight public access."
227   :group 'jde-java-font-lock-faces)
228
229 (defface jde-java-font-lock-bold-face
230   '((t (:bold t)))
231   "Font Lock Mode face used to highlight HTML bold text style."
232   :group 'jde-java-font-lock-faces)
233
234 (defface jde-java-font-lock-italic-face
235   '((t (:italic t)))
236   "Font Lock Mode face used to highlight HTML italic text style."
237   :group 'jde-java-font-lock-faces)
238
239 (defface jde-java-font-lock-underline-face
240   '((t (:underline t)))
241   "Font Lock Mode face used to highlight HTML underlined text style."
242   :group 'jde-java-font-lock-faces)
243
244 (defface jde-java-font-lock-pre-face
245   '((t nil))
246   "Font Lock Mode face used to highlight HTML preformatted text style."
247   :group 'jde-java-font-lock-faces)
248
249 (defface jde-java-font-lock-code-face
250   '((t nil))
251   "Font Lock Mode face used to highlight HTML program code style."
252   :group 'jde-java-font-lock-faces)
253
254 ;; Define the extra font lock faces
255 (defvar jde-java-font-lock-number-face    'jde-java-font-lock-number-face
256   "Face name to use for numbers.")
257 (defvar jde-java-font-lock-operator-face  'jde-java-font-lock-operator-face
258   "Face name to use for operators.")
259 (defvar jde-java-font-lock-constant-face  'jde-java-font-lock-constant-face
260   "Face name to use for constants.")
261 (defvar jde-java-font-lock-package-face   'jde-java-font-lock-package-face
262   "Face name to use for packages.")
263 (defvar jde-java-font-lock-modifier-face  'jde-java-font-lock-modifier-face
264   "Face name to use for modifiers.")
265 (defvar jde-java-font-lock-private-face   'jde-java-font-lock-private-face
266   "Face name to use for private modifiers.")
267 (defvar jde-java-font-lock-protected-face 'jde-java-font-lock-protected-face
268   "Face name to use for protected modifiers.")
269 (defvar jde-java-font-lock-public-face    'jde-java-font-lock-public-face
270   "Face name to use for public modifiers.")
271 (defvar jde-java-font-lock-api-face       'jde-java-font-lock-api-face
272   "Face name to use for user's defined names.")
273 (defvar jde-java-font-lock-doc-tag-face   'jde-java-font-lock-doc-tag-face
274   "Face name to use for doc tags.")
275 (defvar jde-java-font-lock-link-face      'jde-java-font-lock-link-face
276   "Face name to use for links.")
277 (defvar jde-java-font-lock-bold-face      'jde-java-font-lock-bold-face
278   "Face name to use for HTML bold text style.")
279 (defvar jde-java-font-lock-italic-face    'jde-java-font-lock-italic-face
280   "Face name to use for HTML italic text style.")
281 (defvar jde-java-font-lock-underline-face 'jde-java-font-lock-underline-face
282   "Face name to use for HTML underlined text style.")
283 (defvar jde-java-font-lock-pre-face       'jde-java-font-lock-pre-face
284   "Face name to use for HTML preformatted text style.")
285 (defvar jde-java-font-lock-code-face      'jde-java-font-lock-code-face
286   "Face name to use for HTML program code style.")
287 \f
288 ;;;;
289 ;;;; Useful constants
290 ;;;;
291
292 (eval-and-compile
293   (defconst jde-java-font-lock-capital-letter
294     "A-Z\300-\326\330-\337_$"
295     "Java identifier capital letter.")
296
297   (defconst jde-java-font-lock-letter
298     (eval-when-compile
299       (concat jde-java-font-lock-capital-letter "a-z"))
300     "Java identifier letter.")
301
302   (defconst jde-java-font-lock-capital-letter-or-digit
303     (eval-when-compile
304       (concat jde-java-font-lock-capital-letter "0-9"))
305     "Java identifier capital letter or digit.")
306
307   (defconst jde-java-font-lock-letter-or-digit
308     (eval-when-compile
309       (concat jde-java-font-lock-letter "0-9"))
310     "Java identifier letter or digit.")
311   )
312
313 (defconst jde-java-font-lock-modifier-regexp
314   (eval-when-compile
315     (concat "\\<\\("
316             (regexp-opt '("abstract"
317                           "const"
318                           "final"
319                           "native"
320                           ;;; removed after making each its own font -PaulL
321                           ;;"private"
322                           ;;"protected"
323                           ;;"public"
324                           "static"
325                           "strictfp"
326                           "synchronized"
327                           "transient"
328                           "volatile"
329                           ))
330             "\\)\\>"))
331   "Regular expression to match Java modifiers.")
332
333 (defconst jde-java-font-lock-number-regexp
334   (eval-when-compile
335     (concat "\\("
336             "\\<[0-9]+[.][0-9]+\\([eE][-+]?[0-9]+\\)?[fFdD]?\\>"
337             "\\|"
338             "\\<[0-9]+[.][eE][-+]?[0-9]+[fFdD]?\\>"
339             "\\|"
340             "\\<[0-9]+[.][fFdD]\\>"
341             "\\|"
342             "\\<[0-9]+[.]"
343             "\\|"
344             "[.][0-9]+\\([eE][-+]?[0-9]+\\)?[fFdD]?\\>"
345             "\\|"
346             "\\<[0-9]+[eE][-+]?[0-9]+[fFdD]?\\>"
347             "\\|"
348             "\\<0[xX][0-9a-fA-F]+[lL]?\\>"
349             "\\|"
350             "\\<[0-9]+[lLfFdD]?\\>"
351             "\\)"
352             ))
353   "Regular expression to match Java numbers.")
354
355 (defconst jde-java-font-lock-operator-regexp
356   "[<>=|/*&!%:?~^]+"
357   "Regular expression to match Java operators.")
358
359 (defconst jde-java-font-lock-capital-id-regexp
360   (eval-when-compile
361     (concat "\\(\\b[" jde-java-font-lock-capital-letter
362             "]+[" jde-java-font-lock-capital-letter-or-digit
363             "]*\\b\\)"))
364   "Regular expression to match capitalised identifiers.")
365 \f
366 ;;;;
367 ;;;; Support for fontification inside javadocs and comments.
368 ;;;;
369
370 (defun jde-java-font-lock-remove-javadoc-keywords (keywords)
371   "Remove existing javadoc font lock keywords from KEYWORDS.
372 That is those with \"@\" in their matcher regexp."
373   (let (kw matcher)
374     (while keywords
375       (setq matcher  (car keywords)
376             keywords (cdr keywords))
377       (if (not (and (consp matcher)
378                     (stringp (car matcher))
379                     (string-match "@" (car matcher))))
380           (setq kw (cons matcher kw))))
381     (nreverse kw)))
382
383 (defconst jde-java-font-lock-comment-faces
384   '(font-lock-comment-face font-lock-doc-face)
385   "List of faces font-lock uses for comments.")
386
387 (defmacro jde-java-font-lock-at-comment (pos)
388   "Return non-nil if POS is in a comment."
389   `(memq (get-text-property ,pos 'face)
390          jde-java-font-lock-comment-faces))
391
392 (defsubst jde-java-font-lock-search-in-comment (regexp end)
393   "Search forward from point for regular expression REGEXP.
394 Ensure matching occurs in a java comment.  Buffer position END bounds
395 the search.  The match found must not extend after that position."
396   (let ((here (point))
397         ok b p)
398     (while (and (not ok)
399                 (setq p (re-search-forward regexp end t)))
400       (setq b (match-beginning 0))
401       (setq ok (and (jde-java-font-lock-at-comment b)
402                     (< p (next-single-property-change
403                           b 'face nil (point-max))))))
404     (if ok
405         (point)
406       (goto-char here)
407       nil)))
408
409 (defsubst jde-java-font-lock-search-in-javadoc (regexp end)
410   "Search forward from point for regular expression REGEXP.
411 Ensure matching occurs in a javadoc comment.  Buffer position END
412 bounds the search.  The match found must not extend after that
413 position."
414   (let ((here (point))
415         b c ok md p)
416     (while (and (not ok) (setq p (re-search-forward regexp end t)))
417       (setq b  (match-beginning 0)
418             md (match-data)
419             ok (and (re-search-backward "^\\s-*\\(/[*][*]\\)" nil t)
420                     (jde-java-font-lock-at-comment
421                      (goto-char (setq c (match-beginning 1))))
422                     (forward-comment 1)
423                     (< p (point))
424                     (>= b c)
425                     (setq here p)))
426       (goto-char p))
427     (set-match-data md)
428     (goto-char here)
429     ok))
430
431 (defun jde-java-font-lock-quote-matcher (end)
432   "Font lock matcher for comment enclosed in \`\'.
433 Limit search to END position."
434   (jde-java-font-lock-search-in-comment
435    "`\\([^']*\\)'"
436    end))
437
438 (defconst jde-java-font-lock-quote-keyword
439   '(jde-java-font-lock-quote-matcher
440     1 jde-java-font-lock-doc-tag-face t)
441   "Font lock keyword for comment enclosed in \`\'.")
442
443 (defun jde-java-font-lock-html-ahref-matcher (end)
444   "Font lock matcher for HTML A HREF anchor in javadoc comments.
445 Limit search to END position."
446   (jde-java-font-lock-search-in-javadoc
447    "<[Aa]\\s-+[Hh][Rr][Ee][Ff][^>]*>\\([^>]+\\)</[Aa]>"
448    end))
449
450 (defconst jde-java-font-lock-html-ahref-keyword
451   '(jde-java-font-lock-html-ahref-matcher
452     1 jde-java-font-lock-link-face t)
453   "Font lock keyword for javadoc HTML A HREF anchor.")
454
455 (eval-and-compile
456   (defun jde-java-font-lock-html-tag-regexp (tag &rest aliases)
457     "Return a regexp that matches HTML tag TAG.
458 The string between <TAG> and </TAG> is the second parenthesized
459 expression in the returned regexp.  ALIASES are other names for TAG."
460     (let* ((tag-re (mapconcat
461                     #'(lambda (tag)
462                         (mapconcat #'(lambda (c)
463                                        (format "[%c%c]"
464                                                (upcase c)
465                                                (downcase c)))
466                                    tag
467                                    ""))
468                     (cons tag aliases)
469                     "\\|"))
470            (hit-re (if (or (and (featurep 'xemacs)
471                                 (or (< emacs-major-version 21)
472                                     (and (= emacs-major-version 21)
473                                          (< emacs-minor-version 4))))
474                            (< emacs-major-version 21))
475                        ".*"
476                      ;; In GNU Emacs 21 use the "non-greedy" variant of
477                      ;; the operator `*' to match the smallest possible
478                      ;; substring.
479                      "\\(.\\|[\r\n]\\)*?")))
480       (format "<\\(%s\\)>\\(%s\\)</\\(%s\\)>" tag-re hit-re tag-re)
481       )))
482
483 (defconst jde-java-font-lock-comment-faces
484   '(font-lock-comment-face font-lock-doc-face)
485   "List of faces font-lock uses for comments.")
486
487 (defmacro jde-java-font-lock-at-comment (pos)
488   "Return non-nil if POS is in a comment."
489   `(memq (get-text-property ,pos 'face)
490          jde-java-font-lock-comment-faces))
491
492
493   (defsubst jde-java-font-lock-search-in-comment (regexp end)
494     "Search forward from point for regular expression REGEXP.
495 Ensure matching occurs in a java comment.  Buffer position END bounds
496 the search.  The match found must not extend after that position."
497     (let ((here (point))
498           ok b p)
499       (while (and (not ok)
500                   (setq p (re-search-forward regexp end t)))
501         (setq b (match-beginning 0))
502         (setq ok (and (jde-java-font-lock-at-comment b)
503                       (< p (next-single-property-change
504                             b 'face nil (point-max))))))
505       (if ok
506           (point)
507         (goto-char here)
508         nil)))
509
510 (defun jde-java-font-lock-quote-matcher (end)
511   "Font lock matcher for comment enclosed in \`\'.
512 Limit search to END position."
513   (jde-java-font-lock-search-in-comment
514    "`\\([^']*\\)'"
515    end))
516
517 (defconst jde-java-font-lock-quote-keyword
518   '(jde-java-font-lock-quote-matcher
519     1 jde-java-font-lock-doc-tag-face t)
520   "Font lock keyword for comment enclosed in \`\'.")
521
522 (eval-and-compile
523   (if (featurep 'cc-fonts)
524     
525       ;; Highlight javadoc comments through cc-fonts.
526       (defconst jde-java-font-lock-doc-comments
527         `(
528           ;; Fontify javadoc tags (including non official ones)
529           (,(concat "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*"
530                     "\\(@[" jde-java-font-lock-letter-or-digit "]+\\)")
531            2 jde-java-font-lock-doc-tag-face t)
532           ;; Fontify @param variable name
533           ("^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*@param\\>[ \t]*\\(\\sw+\\)?"
534            2 font-lock-variable-name-face prepend t)
535           ;; Fontify @exception or @throws exception type
536           ("^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*\
537 @\\(exception\\|throws\\)\\>[ \t]*\\(\\S-+\\)?"
538            3 font-lock-type-face prepend t)
539           ;; Fontify @docRoot
540           ("{\\(@docRoot\\)}"
541            1 jde-java-font-lock-doc-tag-face t)
542           ;; Fontify @link
543           ("{\\(@link\\)\\>[ \t]+\\([^}]*\\)}"
544            (1 jde-java-font-lock-doc-tag-face t)
545            (2 jde-java-font-lock-link-face t))
546           ;; Fontify @see reference
547           (,(concat "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*"
548                     "@see\\>[ \t]*"
549                     "\\([.#" jde-java-font-lock-letter-or-digit "]+\\)")
550            2 jde-java-font-lock-code-face t)
551           ;; Fontify the text of a HREF anchor
552           ("<[Aa]\\s-+[Hh][Rr][Ee][Ff][^>]*>\\([^>]+\\)</[Aa]>"
553            1 jde-java-font-lock-link-face t)
554           ;; Fontify other HTML tags
555           (,(jde-java-font-lock-html-tag-regexp "b")
556            2 jde-java-font-lock-bold-face t)
557           (,(jde-java-font-lock-html-tag-regexp "strong")
558            2 jde-java-font-lock-bold-face t)
559           (,(jde-java-font-lock-html-tag-regexp "i")
560            2 jde-java-font-lock-italic-face t)
561           (,(jde-java-font-lock-html-tag-regexp "em")
562            2 jde-java-font-lock-italic-face t)
563           (,(jde-java-font-lock-html-tag-regexp "u")
564            2 jde-java-font-lock-underline-face t)
565           (,(jde-java-font-lock-html-tag-regexp "code")
566            2 jde-java-font-lock-code-face t)
567           (,(jde-java-font-lock-html-tag-regexp "pre")
568            2 jde-java-font-lock-pre-face t)
569           )
570         "Keywords highlighted in javadoc comments.")
571   
572     ;; Highlight javadoc comments through JDEE's own support
573     (defun jde-java-font-lock-remove-javadoc-keywords (keywords)
574       "Remove existing javadoc font lock keywords from KEYWORDS.
575 That is those with \"@\" in their matcher regexp."
576       (let (kw matcher)
577         (while keywords
578           (setq matcher  (car keywords)
579                 keywords (cdr keywords))
580           (if (not (and (consp matcher)
581                         (stringp (car matcher))
582                         (string-match "@" (car matcher))))
583               (setq kw (cons matcher kw))))
584         (nreverse kw)))
585
586     (defsubst jde-java-font-lock-search-in-javadoc (regexp end)
587       "Search forward from point for regular expression REGEXP.
588 Ensure matching occurs in a javadoc comment.  Buffer position END
589 bounds the search.  The match found must not extend after that
590 position."
591       (let ((here (point))
592             b c ok md p)
593         (while (and (not ok) (setq p (re-search-forward regexp end t)))
594           (setq b  (match-beginning 0)
595                 md (match-data)
596                 ok (and (re-search-backward "^\\s-*\\(/[*][*]\\)" nil t)
597                         (jde-java-font-lock-at-comment
598                          (goto-char (setq c (match-beginning 1))))
599                         (forward-comment 1)
600                         (< p (point))
601                         (>= b c)
602                         (setq here p)))
603           (goto-char p))
604         (set-match-data md)
605         (goto-char here)
606         ok))
607
608     (defun jde-java-font-lock-html-ahref-matcher (end)
609       "Font lock matcher for HTML A HREF anchor in javadoc comments.
610 Limit search to END position."
611       (jde-java-font-lock-search-in-javadoc
612        "<[Aa]\\s-+[Hh][Rr][Ee][Ff][^>]*>\\([^>]+\\)</[Aa]>"
613        end))
614
615     (defconst jde-java-font-lock-html-ahref-keyword
616       '(jde-java-font-lock-html-ahref-matcher
617         1 jde-java-font-lock-link-face t)
618       "Font lock keyword for javadoc HTML A HREF anchor.")
619
620
621     (defvar jde-java-font-lock-html-keywords nil
622       "List of HTML keywords defined so far.")
623
624     (defmacro jde-java-font-lock-def-html-keyword (tag face)
625       "Define a font-lock keyword for HTML TAG.
626 Data inside TAG will be highlighted with FACE.
627 A new keyword is pushed into `jde-java-font-lock-html-keywords'."
628       (let* ((matcher (intern (format "jde-java-font-lock-html-%s-matcher" tag))))
629         `(progn
630            (add-to-list 'jde-java-font-lock-html-keywords '(,matcher 2 ,face t))
631            (defun ,matcher (end)
632              (jde-java-font-lock-search-in-javadoc
633               ,(jde-java-font-lock-html-tag-regexp tag) end)))))
634
635     (jde-java-font-lock-def-html-keyword "b" jde-java-font-lock-bold-face)
636     (jde-java-font-lock-def-html-keyword "strong" jde-java-font-lock-bold-face)
637     (jde-java-font-lock-def-html-keyword "i" jde-java-font-lock-italic-face)
638     (jde-java-font-lock-def-html-keyword "em" jde-java-font-lock-italic-face)
639     (jde-java-font-lock-def-html-keyword "u" jde-java-font-lock-underline-face)
640     (jde-java-font-lock-def-html-keyword "code" jde-java-font-lock-code-face)
641     (jde-java-font-lock-def-html-keyword "pre" jde-java-font-lock-pre-face)
642
643     (defun jde-java-font-lock-javadoc-tag-matcher (end)
644       "Font lock matcher for javadoc tags.
645 Limit search to END position."
646       (jde-java-font-lock-search-in-javadoc
647        (eval-when-compile
648          (concat "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*"
649                  "\\(@[" jde-java-font-lock-letter-or-digit "]+\\)"))
650        end))
651
652     (defconst jde-java-font-lock-javadoc-tag-keyword
653       '(jde-java-font-lock-javadoc-tag-matcher
654         2 jde-java-font-lock-doc-tag-face t)
655       "Font lock keyword for javadoc tags.")
656
657     (defun jde-java-font-lock-javadoc-docroot-matcher (end)
658       "Font lock matcher for javadoc @docRoot tags.
659 Limit search to END position."
660       (jde-java-font-lock-search-in-javadoc
661        "{\\(@docRoot\\)}"
662        end))
663
664     (defconst jde-java-font-lock-javadoc-docroot-keyword
665       '(jde-java-font-lock-javadoc-docroot-matcher
666         1 jde-java-font-lock-doc-tag-face t)
667       "Font lock keyword for javadoc @docRoot tags.")
668
669     (defun jde-java-font-lock-javadoc-link-matcher (end)
670       "Font lock matcher for javadoc @link tags.
671 Limit search to END position."
672       (jde-java-font-lock-search-in-javadoc
673        "{\\(@link\\)\\>[ \t]+\\([^}]*\\)}"
674        end))
675
676     (defconst jde-java-font-lock-javadoc-link-keyword
677       '(jde-java-font-lock-javadoc-link-matcher
678         (1 jde-java-font-lock-doc-tag-face t)
679         (2 jde-java-font-lock-link-face t))
680       "Font lock keyword for javadoc @link tags.")
681
682     (defun jde-java-font-lock-javadoc-see-ref-matcher (end)
683       "Font lock matcher for javadoc @see references.
684 Limit search to END position."
685       (jde-java-font-lock-search-in-javadoc
686        (eval-when-compile
687          (concat "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*"
688                  "@see\\>[ \t]*"
689                  "\\([.#" jde-java-font-lock-letter-or-digit "]+\\)"))
690        end))
691
692     (defconst jde-java-font-lock-javadoc-see-ref-keyword
693       '(jde-java-font-lock-javadoc-see-ref-matcher
694         2 jde-java-font-lock-code-face t)
695       "Font lock keyword for javadoc @see references.")
696
697     (defun jde-java-font-lock-javadoc-param-name-matcher (end)
698       "Font lock matcher for javadoc @param names.
699 Limit search to END position."
700       (jde-java-font-lock-search-in-javadoc
701        "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*@param\\>[ \t]*\\(\\sw+\\)?"
702        end))
703
704     (defconst jde-java-font-lock-javadoc-param-name-keyword
705       '(jde-java-font-lock-javadoc-param-name-matcher
706         2 font-lock-variable-name-face prepend t)
707       "Font lock keyword for javadoc @param names.")
708
709     (defun jde-java-font-lock-javadoc-exception-type-matcher (end)
710       "Font lock matcher for javadoc exception types.
711 Limit search to END position."
712       (jde-java-font-lock-search-in-javadoc
713        "^[ \t]*\\(/\\*\\*\\|\\*?\\)[ \t]*\
714 @\\(exception\\|throws\\)\\>[ \t]*\\(\\S-+\\)?"
715        end))
716
717     (defconst jde-java-font-lock-javadoc-exception-type-keyword
718       '(jde-java-font-lock-javadoc-exception-type-matcher
719         3 font-lock-type-face prepend t)
720       "Font lock keyword for javadoc exception types.")
721
722     ))
723 \f
724 ;;;;
725 ;;;; Support for fontification of user's defined names.
726 ;;;;
727
728 (defcustom jde-java-font-lock-api-file
729   (expand-file-name "~/jde-java-font-lock.api")
730   "*File which contains a list of user's defined names to fontify.
731 If nil no name fontification occurs.  Otherwise the specified file must
732 contain one name by line.  Lines not beginning with a letter are
733 ignored.  When you change this file or modify its content a new cache
734 of font lock regular expressions will be rebuilt when restarting
735 Emacs.  Also, you can manually rebuild the cache and update font lock
736 keywords by entering the command:
737
738 \\[universal-argument] \\[jde-java-font-lock-setup-keywords]."
739   :group 'jde-project
740   :type '(choice :tag "Names"
741                  (const :tag "No" nil)
742                  (file  :tag "In file" :format "%t\n%v")))
743
744 (defcustom jde-java-font-lock-api-name-filter nil
745   "*Function used to filter a name."
746   :group 'jde-project
747   :type 'function)
748
749 (defconst jde-java-font-lock-api-entry-regexp
750   (eval-when-compile
751     (concat "^[" jde-java-font-lock-letter "]"
752             "[" jde-java-font-lock-letter-or-digit "]+$"))
753   "Regexp to match a valid entry in `jde-java-font-lock-api-file'.")
754
755 (defconst jde-java-font-lock-api-entry-match 0
756   "Index of the match data in `jde-java-font-lock-api-entry-regexp'.")
757
758 (defun jde-java-font-lock-api-names (&optional filter)
759   "Return the list of names in `jde-java-font-lock-api-file'.
760 If optional FILTER function is non-nil it is called for each name
761 found and must return non-nil to include it in the result list."
762   (let (k kl)
763     (if (and jde-java-font-lock-api-file
764              (file-readable-p jde-java-font-lock-api-file))
765         (with-temp-buffer
766           (erase-buffer)
767           (insert-file-contents jde-java-font-lock-api-file)
768           (goto-char (point-min))
769           (while (re-search-forward jde-java-font-lock-api-entry-regexp nil t)
770             (setq k (match-string jde-java-font-lock-api-entry-match))
771             ;; Allow filtering of names
772             (if (or (null filter) (funcall filter k))
773                 (setq kl (cons k kl))))))
774     kl))
775
776 (defun jde-java-font-lock-api-split-list (l n)
777   "Split list L in sub listes of N elements.
778 If L is nil return nil.  If N is less than 1 all elements will be in
779 one sub list."
780   (if l
781       (if (<= n 0)
782           (list l)
783         (let (split-list sub-list i)
784           (while l
785             (setq i 0 sub-list nil)
786             (while (and l (< i n))
787               (setq sub-list (cons (car l) sub-list)
788                     i        (1+ i)
789                     l        (cdr l)))
790             (if sub-list
791                 (setq split-list (cons sub-list split-list))))
792           split-list))))
793
794 (defun jde-java-font-lock-api-build-regexps (max-matches)
795   "Build regular expressions matching names to fontify.
796 MAX-MATCHES is the maximum number of names that one regular expression
797 will match.  If MAX-MATCHES is less than 1 one regular expression will
798 match all the names."
799   (let ((max-specpdl-size 2000)) ;; Prevent errors in `regexp-opt'
800                                  ;; when processing long string listes
801     (mapcar (function
802              (lambda (k)
803                (concat "\\<" (regexp-opt k t) "\\>")))
804             (jde-java-font-lock-api-split-list
805              (jde-java-font-lock-api-names
806               jde-java-font-lock-api-name-filter)
807              max-matches))))
808
809 (defvar jde-java-font-lock-api-cache nil
810   "Cache of regular expressions matching names to fontify..")
811
812 (defun jde-java-font-lock-api-cache-file ()
813   "Return the filename of the regular expressions cache.
814 There is a different cache file for each major version of (X)Emacs
815 because of incompatible regular expressions returned by `regexp-opt'."
816   (and jde-java-font-lock-api-file
817        (format "%s.%semacs-%d.apicache"
818                jde-java-font-lock-api-file
819                (if (featurep 'xemacs) "x" "")
820                emacs-major-version)))
821
822 (defconst jde-java-font-lock-api-cache-file-header
823   ";;; Regular expressions matching names to fontify.
824 ;;; Automatically generated by `jde-java-font-lock' on %s.
825 "
826   "Header to be written into the cache file.")
827
828 (defun jde-java-font-lock-api-regexps (&optional rebuild)
829   "Return regular expressions matching names to fontify.
830 The list is cached in variable `jde-java-font-lock-api-cache'.  If it
831 is nil try to initialize it from the cache file (see function
832 `jde-java-font-lock-api-cache-file').  If optional REBUILD flag is
833 non-nil or there is no cache file or the cache file is older than the
834 names file (see variable `jde-java-font-lock-api-file'), a new cache
835 is created."
836   (let ((cache (jde-java-font-lock-api-cache-file)))
837     (cond
838
839      ;; Inconditionnal rebuild
840      (rebuild
841       ;; Clear the cache to rebuild
842       (setq jde-java-font-lock-api-cache nil))
843
844      ;; No names file exists
845      ((null cache)
846       ;; Clear the cache (no fontification)
847       (setq jde-java-font-lock-api-cache nil))
848      
849      ;; A cache file exists
850      ((file-readable-p cache)
851       (if (file-newer-than-file-p jde-java-font-lock-api-file cache)
852           (progn
853             (message
854              "jde-java-font-lock: names file %s newer than cache file %s"
855              jde-java-font-lock-api-file cache)
856             ;; The api file has been modified since the cache was
857             ;; created, so clear the cache to rebuild
858             (setq jde-java-font-lock-api-cache nil))
859         ;; Try to load the existing cache if needed
860         (or jde-java-font-lock-api-cache
861             (condition-case nil
862                 (load-file cache)
863               ;; If load fails clear the cache to rebuild
864               (error
865                (setq jde-java-font-lock-api-cache nil)))))))
866
867     (or jde-java-font-lock-api-cache
868         (not cache)
869         ;; Build a new cache if it is empty and available
870         (progn
871           (message "jde-java-font-lock: building names cache...")
872           (when (setq jde-java-font-lock-api-cache
873                       (jde-java-font-lock-api-build-regexps
874                        jde-java-font-lock-max-names-by-regexp))
875             ;; Save regexps in cache
876             (with-current-buffer (find-file-noselect cache)
877               (erase-buffer)
878               (insert
879                (format jde-java-font-lock-api-cache-file-header
880                        (current-time-string))
881                (format "(setq jde-java-font-lock-api-cache '%S)"
882                        jde-java-font-lock-api-cache))
883               (save-buffer)
884               (kill-buffer (current-buffer))))
885           (message "jde-java-font-lock: building names cache...%s"
886                    (if jde-java-font-lock-api-cache "done" "empty"))))
887           jde-java-font-lock-api-cache))
888
889 (defun jde-java-font-lock-api-keywords (&optional rebuild)
890   "Return a list of font lock keywords for user's defined names.
891 If optional REBUILD flag is non-nil create a new cache of regular
892 expressions."
893   (mapcar (function
894            (lambda (k)
895              (cons k 'jde-java-font-lock-api-face)))
896           (jde-java-font-lock-api-regexps rebuild)))
897 \f
898 ;;;;
899 ;;;; Font lock setup.
900 ;;;;
901
902 (defvar java-font-lock-keywords-4 nil
903   "Extra level fontification keywords for JDE mode.")
904
905 (defun jde-java-font-lock-refontify ()
906   "Re-fontify buffers in `java-mode' and `jde-mode'."
907   (dolist (b (buffer-list))
908     (when (buffer-live-p b)
909       (with-current-buffer b
910         (when (and font-lock-mode
911                    (memq major-mode '(java-mode jde-mode)))
912           (message "JDEE refontify buffer %s..." b)
913           (font-lock-mode -1)
914           (font-lock-mode 1)
915           (message "JDEE refontify  buffer %s...done" b))))))
916
917 (defun jde-java-font-lock-keywords (&optional rebuild)
918   "JDEE's extra level font lock keywords.
919 If optional REBUILD flag is non-nil create a new cache of regular
920 expressions."
921   (if (featurep 'cc-fonts)
922       
923       ;; Through cc-fonts support.
924       (append
925        java-font-lock-keywords-3
926        ;; Fontify user's defined names
927        (mapcar #'(lambda (e)
928                    (list
929                     (c-make-font-lock-search-function
930                      (car e)
931                      (list 0 (cdr e) t))))
932                (jde-java-font-lock-api-keywords rebuild))
933        (list
934         ;; Fontify modifiers.
935         `(,(c-make-font-lock-search-function
936             jde-java-font-lock-modifier-regexp
937             '(0 jde-java-font-lock-modifier-face t)))
938         `(,(c-make-font-lock-search-function
939             "\\<\\(false\\|null\\|true\\)\\>"
940             '(1 jde-java-font-lock-constant-face t)))
941         ;; Fontify default and assert as keywords
942         `(,(c-make-font-lock-search-function
943             "\\<\\(default\\|assert\\)\\>"
944             '(1 'font-lock-keyword-face t)))
945         ;; Fontify const and goto with warning face. These keywords are
946         ;; reserved, even though they are not currently used.
947         `(,(c-make-font-lock-search-function
948             "\\<\\(const\\|goto\\)\\>"
949             '(1 'font-lock-warning-face t)))
950         ;; Fontify numbers
951         `(,(c-make-font-lock-search-function
952             jde-java-font-lock-number-regexp
953             '(0 jde-java-font-lock-number-face t)))
954         ;; Fontify operators
955 ;;;     `(,(c-make-font-lock-search-function
956 ;;;         jde-java-font-lock-operator-regexp
957 ;;;         '(0 jde-java-font-lock-operator-face t)))
958         ;; Fontify capitalised identifiers as constant
959         `(,jde-java-font-lock-capital-id-regexp
960           1 jde-java-font-lock-constant-face)
961         ;; Fontify text between `' in comments
962         jde-java-font-lock-quote-keyword
963         ;; Fontify javadoc comments
964         '((lambda (limit)
965             (c-font-lock-doc-comments
966                 "/\\*\\*" limit
967               jde-java-font-lock-doc-comments)))
968         )
969        )
970     
971     ;; Through JDEE's own support
972     (append
973      ;; Feature scoping: These must come first or the Special
974      ;; constants, Modifiers and Packages from keywords-1 will catch
975      ;; them.
976 ;;; Compatibility
977      (if (featurep 'xemacs)
978          (list
979             
980           ;; Special keywords and constants
981           '("\\<\\(this\\|super\\)\\>"
982             (1 font-lock-keyword-face))
983           '("\\<\\(false\\|null\\|true\\)\\>"
984             (1 jde-java-font-lock-constant-face))
985           ))
986        
987      (list
988       ;; Fontify default as keyword
989       '("\\<\\(default\\)\\>" (1 font-lock-keyword-face))
990       ;; Fontify assert as keyword
991       '("\\<\\(assert\\)\\>" (1 font-lock-keyword-face))
992       ;; Fontify const and goto with warning face. These keywords are
993       ;; reserved, even though they are not currently used.
994       '("\\<\\(const\\|goto\\)\\>" (1 font-lock-warning-face))
995       ;; Fontify modifiers.
996       (cons jde-java-font-lock-modifier-regexp
997             'jde-java-font-lock-modifier-face)
998       ;; Fontify package directives
999       '("\\<\\(package\\)\\>\\s-+\\(\\sw+\\)"
1000         (1 font-lock-keyword-face)
1001         (2 jde-java-font-lock-package-face nil t)
1002         ("\\=\\.\\(\\sw+\\)" nil nil
1003          (1 jde-java-font-lock-package-face nil t)))
1004       ;; Fontify import directives
1005       '("\\<\\(import\\)\\>\\s-+\\(\\sw+\\)"
1006         (1 font-lock-keyword-face)
1007         (2 (if (equal (char-after (match-end 0)) ?\.)
1008                'jde-java-font-lock-package-face
1009              'font-lock-type-face))
1010         ("\\=\\.\\(\\*\\|\\sw+\\)" nil nil
1011          (1 (if (equal (char-after (match-end 0)) ?\.)
1012                 'jde-java-font-lock-package-face
1013               (if (equal (char-before (match-end 0)) ?\*)
1014                   'jde-java-font-lock-number-face
1015                 'font-lock-type-face)))))
1016       ;; modifier protections
1017       '("\\<\\(private\\)\\>" (1 jde-java-font-lock-private-face))
1018       '("\\<\\(protected\\)\\>" (1 jde-java-font-lock-protected-face))
1019       '("\\<\\(public\\)\\>" (1 jde-java-font-lock-public-face))
1020       )
1021      ;; Fontify user's defined names
1022      (jde-java-font-lock-api-keywords rebuild)
1023        
1024 ;;; Compatibility
1025      (if (featurep 'xemacs)
1026          java-font-lock-keywords-2
1027        ;; Remove existing javadoc font lock keywords from GNU Emacs
1028        ;; `java-font-lock-keywords-3'
1029        (jde-java-font-lock-remove-javadoc-keywords
1030         java-font-lock-keywords-3))
1031
1032 ;;; Compatibility
1033      (unless (featurep 'xemacs)
1034        ;; GNU Emacs don't fontify capitalized types so do it
1035        (list
1036         (list
1037          (concat "\\<\\([" jde-java-font-lock-capital-letter "]\\sw*\\)\\>"
1038                  "\\([ \t]*\\[[ \t]*\\]\\)*"
1039                  "\\([ \t]*\\sw\\)")
1040          '(font-lock-match-c-style-declaration-item-and-skip-to-next
1041            (goto-char (match-beginning 3))
1042            (goto-char (match-beginning 3))
1043            (1 (if (match-beginning 2)
1044                   font-lock-function-name-face
1045                 font-lock-variable-name-face))))
1046         (cons
1047          (concat "\\<\\([" jde-java-font-lock-capital-letter "]\\sw*\\)\\>"
1048                  "\\([ \t]*\\[[ \t]*\\]\\)*"
1049                  "\\([ \t]*\\sw\\)")
1050          '(1 font-lock-type-face))
1051         '("\\<\\(new\\|instanceof\\)\\>[ \t]+\\(\\sw+\\)"
1052           2 font-lock-type-face)))
1053
1054      ;; Some extra fontification
1055      (list
1056       ;; Fontify numbers
1057       (cons jde-java-font-lock-number-regexp
1058             'jde-java-font-lock-number-face)
1059       ;; Fontify operators
1060 ;;;      (cons jde-java-font-lock-operator-regexp
1061 ;;;            'jde-java-font-lock-operator-face)
1062       ;; Fontify capitalised identifiers as constant
1063       (cons jde-java-font-lock-capital-id-regexp
1064             '(1 jde-java-font-lock-constant-face))
1065       ;; Fontify text between `' in comments
1066       jde-java-font-lock-quote-keyword
1067       ;; Fontify javadoc tags (including non official ones)
1068       jde-java-font-lock-javadoc-tag-keyword
1069       ;; Fontify @param variable name
1070       jde-java-font-lock-javadoc-param-name-keyword
1071       ;; Fontify @exception or @throws exception type
1072       jde-java-font-lock-javadoc-exception-type-keyword
1073       ;; Fontify @docRoot
1074       jde-java-font-lock-javadoc-docroot-keyword
1075       ;; Fontify @link
1076       jde-java-font-lock-javadoc-link-keyword
1077       ;; Fontify @see reference
1078       jde-java-font-lock-javadoc-see-ref-keyword
1079       ;; Fontify the text of a HREF anchor
1080       jde-java-font-lock-html-ahref-keyword
1081       )
1082      ;; Fontify other HTML tags
1083      jde-java-font-lock-html-keywords
1084      )
1085     ))
1086
1087 ;;;###autoload
1088 (defun jde-java-font-lock-setup-keywords (&optional rebuild)
1089   "Setup font lock keywords in `java-font-lock-keywords-4'.
1090 If optional REBUILD flag is non-nil create a new cache of regular
1091 expressions."
1092   (interactive "P")
1093   (and (interactive-p)
1094        (consp current-prefix-arg)
1095        (setq rebuild t))
1096   
1097   ;; Setup the JDEE's extra font lock keywords.
1098   (setq java-font-lock-keywords-4 (jde-java-font-lock-keywords rebuild))
1099   
1100   ;; Update fontification of buffers in `java-mode' and `jde-mode'.
1101   (when (interactive-p)
1102     (jde-java-font-lock-refontify)))
1103
1104 ;; Setup `java-font-lock-keywords-4'
1105 (jde-java-font-lock-setup-keywords)
1106
1107 ;; Define new defaults for Font Lock mode
1108 (defconst jde-java-font-lock-defaults
1109   (let ((java-defaults 
1110          (if (featurep 'xemacs)
1111              (get 'java-mode 'font-lock-defaults)
1112            ;;; To avoid compilation warning, replace obsolete variable,
1113            ;;; font-lock-defaults-alist, with its value for java-mode.
1114            ;;; (cdr (assq 'java-mode font-lock-defaults-alist)))))
1115            ;;; Paul Kinnucan.
1116            '((java-font-lock-keywords 
1117               java-font-lock-keywords-1
1118               java-font-lock-keywords-2 
1119               java-font-lock-keywords-3)
1120              nil nil ((?_ . "w") (?$ . "w")) nil
1121              (font-lock-mark-block-function . mark-defun)))))
1122     (cons (append (car java-defaults) '(java-font-lock-keywords-4))
1123           (cdr java-defaults)))
1124   "Defaults for coloring Java keywords in jde-mode. The defaults
1125 consist of the java-mode defaults plus `java-font-lock-keywords-4'.")
1126 \f
1127 ;;;;
1128 ;;;; Mode hook to setup syntax coloring.
1129 ;;;;
1130
1131 (defun jde-setup-syntax-coloring ()
1132   "Mode hook to setup syntax coloring in `java-mode' and `jde-mode'.
1133 When `jde-use-font-lock' is non-nil syntax coloring is always turned
1134 on and uses `java-font-lock-keywords-4' extra level of fontification.
1135 If `jde-use-font-lock' is nil syntax coloring rules are those of
1136 standard `java-mode'."
1137   (when (or (featurep 'xemacs)          ; XEmacs and Emacs 21 support
1138             (> emacs-major-version 20)  ; colors on ordinary terminal. 
1139             window-system)              ; Others only on `window-system'.
1140     ;; If `jde-use-font-lock' is non-nil setup
1141     ;; `java-font-lock-keywords-4' extra level of fontification.
1142     (when jde-use-font-lock
1143       ;; Setup `font-lock-defaults'
1144       (set (make-local-variable 'font-lock-defaults)
1145            jde-java-font-lock-defaults)
1146       ;; Use the maximum decoration available
1147       (set (make-local-variable 'font-lock-maximum-decoration) t)
1148       ;; Handle multiline
1149       (set (make-local-variable 'font-lock-multiline) t)
1150       )
1151     ;; Turn on Font Lock Mode as needed (based on parent `java-mode'
1152     ;; if `jde-use-font-lock' is nil).
1153     (let ((major-mode (if jde-use-font-lock major-mode 'java-mode)))
1154       (if (featurep 'xemacs)
1155           ;; The following is intended to avoid a byte-compilation warning
1156           ;; when compiling this file under Emacs. The Emacs version of
1157           ;; font-lock-set-defaults accepts no arguments.
1158           (apply 'font-lock-set-defaults (list t))
1159         (if global-font-lock-mode
1160             (turn-on-font-lock-if-enabled))))
1161     ;; Always turn on font locking if `jde-use-font-lock' is non-nil.
1162     (if jde-use-font-lock
1163         (turn-on-font-lock))))
1164
1165 ;; By default, enable extra fontification in `jde-mode'.
1166 (add-hook 'jde-mode-hook #'jde-setup-syntax-coloring)
1167 \f
1168 (provide 'jde-java-font-lock)
1169
1170 ;;; Change History:
1171
1172 ;;
1173 ;; $Log: jde-java-font-lock.el,v $
1174 ;; Revision 1.24  2005/04/07 05:54:29  paulk
1175 ;; Defines faces for public, private, and protected keywords. Thanks to Paul Landes.
1176 ;;
1177 ;; Revision 1.23  2004/07/07 04:35:20  paulk
1178 ;; Made changes to eliminate byte-compilation warnings.
1179 ;;
1180 ;; Revision 1.22  2004/05/28 04:34:18  paulk
1181 ;; Remove DOS line endings.
1182 ;;
1183 ;; Revision 1.21  2004/05/14 04:03:27  paulk
1184 ;; Update to support c-doc-face-name if defined. Thanks to David Ponce.
1185 ;;
1186 ;; Revision 1.20  2004/03/03 03:14:28  paulk
1187 ;; Fix bug that causes a (wrong-type-argument integerp nil) error when entering an import statement in a new Java file. Thanks to David Ponce.
1188 ;;
1189 ;; Revision 1.19  2003/07/15 11:58:45  paulk
1190 ;; Remove CRs.
1191 ;;
1192 ;; Revision 1.18  2003/07/06 13:42:01  paulk
1193 ;; As of version 5.30, cc-mode provides its own set of font lock keywords and faces for
1194 ;; Java: cc-fonts.  The JDEE now uses cc-fonts if defined. Thanks to David Ponce.
1195 ;;
1196 ;; Revision 1.17  2003/06/07 05:07:42  paulk
1197 ;; Fix a small bug in the JDEE font lock on XEmacs 21.4.11. Thanks to Andrew Kensler.
1198 ;;
1199 ;; Revision 1.16  2003/02/07 00:38:10  jslopez
1200 ;; Adds assert as a keyword to be fortified.
1201 ;; Ideally we want the assert keyword fortified only when the user
1202 ;; is using jdk 1.4 but I don't know of a good way of enabling/disabling
1203 ;; fortifying a keyword based on another parameter. Since fortifying does
1204 ;; not cause any harm, I rather have it fortified always. This might prevent
1205 ;; users from using the assert keyword and causing them problem if they
1206 ;; want to upgrade to 1.4 and use assertions.
1207 ;;
1208 ;; Revision 1.15  2002/09/16 04:42:54  paulk
1209 ;; XEmacs compatibility fix: added require statement for regexp-opt package.
1210 ;;
1211 ;; Revision 1.14  2002/09/16 04:06:14  paulk
1212 ;; XEmacs compatibility fixes. Thanks to Andy Piper.
1213 ;;
1214 ;; Revision 1.13  2002/06/23 17:38:28  jslopez
1215 ;; Removes carriage returns.
1216 ;;
1217 ;; Revision 1.12  2002/06/22 06:29:32  paulk
1218 ;; Improves highlighting of multiline HTML tags in javadoc comments. Thanks to David Ponce.
1219 ;;
1220 ;; Revision 1.11  2001/09/18 15:03:52  jslopez
1221 ;; Adding david's fixed for the make error.
1222 ;;
1223 ;; Revision 1.10  2001/09/18 14:58:02  jslopez
1224 ;; reverted to 1.8 code
1225 ;;
1226 ;; Revision 1.8  2001/09/16 17:55:37  paulk
1227 ;; This new version should be a little bit faster when byte compiled and
1228 ;; fixes the `font-lock-add-keywords' problem reported by Klaus Berndl
1229 ;; <klaus.berndl@sdm.de>. Thanks to David Ponce.
1230 ;;
1231 ;; Revision 1.7  2001/08/06 05:32:20  paulk
1232 ;; New implementation of `jde-setup-syntax-coloring' as a
1233 ;; `java-mode-hook'.
1234 ;;
1235 ;; - If `jde-use-font-lock' is non-nil the JDE completely handles font
1236 ;;   lock setup (it turns on font locking in `java-mode' if needed) and
1237 ;;   installs the extra level of fontification in
1238 ;;   `java-font-lock-keywords-4'.
1239 ;;
1240 ;; - If `jde-use-font-lock' is nil the JDE does nothing by itself (it
1241 ;;   does not turn on font locking in `java-mode') and just delegates
1242 ;;   syntax coloring setup to standard `java-mode'.
1243 ;;
1244 ;; Revision 1.6  2001/06/05 04:54:49  paulk
1245 ;; Minor updates.
1246 ;;
1247 ;; Revision 1.5  2001/04/14 05:28:11  paulk
1248 ;; - All extra fontification added by jde-java-font-lock have a specific
1249 ;;   face.  So there is less font-lock implementation dependencies,
1250 ;;   greater flexibility to setup a color theme, and fontification can be
1251 ;;   kept consistent accross Emacs flavors :-) Notice that this change
1252 ;;   may require to redo some face customization :(
1253 ;;
1254 ;;
1255 ;; - For convenience all specific jde-java-font-lock faces are in the
1256 ;;   customization group `jde-java-font-lock-faces' which is a sub group
1257 ;;   of `font-lock-highlighting-faces' (Emacs) or `font-lock-faces'
1258 ;;   (XEmacs).
1259 ;;
1260 ;;
1261 ;; - Better fontification of numbers and imported package names.
1262 ;;
1263 ;;
1264 ;; - When used interactively the command
1265 ;;   `jde-java-font-lock-setup-keywords' automatically update
1266 ;;   fontification of all Java buffers.  This is very useful when you
1267 ;;   change your API file for example!
1268 ;;
1269 ;;
1270 ;; - The `jde-setup-syntax-coloring' is greatly enhanced.  On Emacs, it
1271 ;;   takes care of the current `global-font-lock-mode' setting.  Also, it
1272 ;;   no more use `font-lock-defaults-alist' (which is an obsolete
1273 ;;   variable on Emacs 21) but the preferred `font-lock-defaults' way to
1274 ;;   setup fontification.
1275 ;;
1276 ;; - Finally, jde-java-font-lock works in java-mode too and it can be
1277 ;;   used standalone if needed.
1278 ;;
1279 ;; Contributed by David Ponce.
1280 ;;
1281 ;; Revision 1.4  2001/01/17 18:59:03  paulk
1282 ;; Font-locking improvements from David Ponce
1283 ;;
1284 ;;    - You can now fontify user-defined identifiers with the new
1285 ;;     jde-java-font-lock-api-face.  These identifiers are read in the
1286 ;;     file specified by the `jde-java-font-lock-api-file' option.
1287 ;;
1288 ;;     The JDE provides a default file "jde-java-font-lock.api" to fontify class
1289 ;;     names of the core 'java' and 'javax' packages (JDK 1.3) and servlet
1290 ;;     API (JSDK 2.0).  To enable this fontification just put this file on
1291 ;;     your home directory, maybe modify it to suit your needs and execute
1292 ;;     the command:
1293 ;;
1294 ;;        M-x jde-java-font-lock-setup-keywords (or restart Emacs).
1295 ;;
1296 ;;     To improve reloading a cache file of regular expressions matching
1297 ;;     these names is created in the same directory (see the source for
1298 ;;     more details).
1299 ;;
1300 ;;   - Because the 'const' and 'goto' keywords are reserved, but not
1301 ;;     currently used they are now fontified with `font-lock-warning-face'.
1302 ;;
1303 ;;   - The 'default' keyword is now fontified with
1304 ;;     `font-lock-keyword-face'.  This was suggested by Stephane Nicolas
1305 ;;     s.nicolas@videotron.ca>.
1306 ;;
1307 ;; Revision 1.3  2000/12/18 05:22:45  paulk
1308 ;; *** empty log message ***
1309 ;;
1310 ;; Revision 1.2  2000/10/10 06:41:47  paulk
1311 ;; Fixed some XEmacs compatibility problems.
1312 ;;
1313 ;; Revision 1.1  2000/10/08 12:53:22  paulk
1314 ;; Initial revision.
1315 ;;
1316
1317 ;;; jde-java-font-lock.el ends here