aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2010-07-31 20:01:08 +0000
committerAlan Mackenzie2010-07-31 20:01:08 +0000
commit452ea85502011e18e4b290fbcb4fe461ab6aace9 (patch)
tree128bd2eda1152cb4b0dbba1b241c266f453e4ba9
parent3776670694ae5034dd68cce55b75f927768d4911 (diff)
downloademacs-452ea85502011e18e4b290fbcb4fe461ab6aace9.tar.gz
emacs-452ea85502011e18e4b290fbcb4fe461ab6aace9.zip
Enhance Java Mode to handle Java 5.0 (Tiger) and Java 6 (Mustang).
Contributed by Nathaniel Flath.
-rw-r--r--lisp/ChangeLog26
-rw-r--r--lisp/progmodes/cc-engine.el319
-rw-r--r--lisp/progmodes/cc-fonts.el7
-rw-r--r--lisp/progmodes/cc-langs.el38
-rw-r--r--lisp/progmodes/cc-mode.el2
-rw-r--r--lisp/progmodes/cc-vars.el26
6 files changed, 248 insertions, 170 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 009eb0712c1..cba5e645f56 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,29 @@
12010-07-31 Alan Mackenzie <acm@muc.de>
2 Enhanced Java Mode to handle Java 5.0 (Tiger) and Java 6
3 (Mustang). Contributed by Nathaniel Flath. The following
4 functions were modified or created:
5
6 * progmodes/cc-vars.el (c-offsets-alist, c-inside-block-syms)
7 (objc-font-lock-extra-types):
8
9 * progmodes/cc-mode.el (c-basic-common-init):
10
11 * progmodes/cc-langs.el (c-make-mode-syntax-table)
12 (c++-make-template-syntax-table)
13 (c-identifier-syntax-modifications, c-symbol-start, c-operators)
14 (c-<-op-cont-regexp, c->-op-cont-regexp, c-class-decl-kwds)
15 (c-brace-list-decl-kwds, c-modifier-kwds, c-prefix-spec-kwds-re)
16 (c-type-list-kwds, c-decl-prefix-re, c-opt-type-suffix-key):
17
18
19 * progmodes/cc-fonts.el (c-make-inverse-face)
20 (c-basic-matchers-after):
21
22 * progmodes/cc-engine.el (c-forward-keyword-clause)
23 (c-forward-<>-arglist, c-forward-<>-arglist-recur)
24 (c-forward-name, c-forward-type, c-forward-decl-or-cast-1)
25 (c-guess-continued-construct, c-guess-basic-syntax):
26
12010-07-31 Jan Djärv <jan.h.d@swipnet.se> 272010-07-31 Jan Djärv <jan.h.d@swipnet.se>
2 28
3 * faces.el (face-all-attributes): Improved documentation (Bug#6767). 29 * faces.el (face-all-attributes): Improved documentation (Bug#6767).
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 9bbf82a0449..d87db0fe8b3 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -5401,6 +5401,7 @@ comment at the start of cc-engine.el for more info."
5401 ;; `nconc' doesn't mind that the tail of 5401 ;; `nconc' doesn't mind that the tail of
5402 ;; `c-record-found-types' is t. 5402 ;; `c-record-found-types' is t.
5403 (nconc c-record-found-types c-record-type-identifiers))) 5403 (nconc c-record-found-types c-record-type-identifiers)))
5404 (if (c-major-mode-is 'java-mode) (c-fontify-recorded-types-and-refs))
5404 t) 5405 t)
5405 5406
5406 (goto-char start) 5407 (goto-char start)
@@ -5420,7 +5421,6 @@ comment at the start of cc-engine.el for more info."
5420 ;; List that collects the positions after the argument 5421 ;; List that collects the positions after the argument
5421 ;; separating ',' in the arglist. 5422 ;; separating ',' in the arglist.
5422 arg-start-pos) 5423 arg-start-pos)
5423
5424 ;; If the '<' has paren open syntax then we've marked it as an angle 5424 ;; If the '<' has paren open syntax then we've marked it as an angle
5425 ;; bracket arglist before, so skip to the end. 5425 ;; bracket arglist before, so skip to the end.
5426 (if (and (not c-parse-and-markup-<>-arglists) 5426 (if (and (not c-parse-and-markup-<>-arglists)
@@ -5431,7 +5431,6 @@ comment at the start of cc-engine.el for more info."
5431 (if (and (c-go-up-list-forward) 5431 (if (and (c-go-up-list-forward)
5432 (eq (char-before) ?>)) 5432 (eq (char-before) ?>))
5433 t 5433 t
5434
5435 ;; Got unmatched paren angle brackets. We don't clear the paren 5434 ;; Got unmatched paren angle brackets. We don't clear the paren
5436 ;; syntax properties and retry, on the basis that it's very 5435 ;; syntax properties and retry, on the basis that it's very
5437 ;; unlikely that paren angle brackets become operators by code 5436 ;; unlikely that paren angle brackets become operators by code
@@ -5441,70 +5440,51 @@ comment at the start of cc-engine.el for more info."
5441 nil)) 5440 nil))
5442 5441
5443 (forward-char) 5442 (forward-char)
5443
5444 (unless (looking-at c-<-op-cont-regexp) 5444 (unless (looking-at c-<-op-cont-regexp)
5445 (while (and 5445 (while (and
5446 (progn 5446 (progn
5447 (c-forward-syntactic-ws)
5448 (let ((orig-record-found-types c-record-found-types))
5449 (when (or (and c-record-type-identifiers all-types)
5450 (c-major-mode-is 'java-mode))
5451 ;; All encountered identifiers are types, so set the
5452 ;; promote flag and parse the type.
5453 (progn
5454 (c-forward-syntactic-ws)
5455 (if (looking-at "\\?")
5456 (forward-char)
5457 (when (looking-at c-identifier-start)
5458 (let ((c-promote-possible-types t)
5459 (c-record-found-types t))
5460 (c-forward-type))))
5447 5461
5448 (when c-record-type-identifiers 5462 (c-forward-syntactic-ws)
5449 (if all-types
5450
5451 ;; All encountered identifiers are types, so set the
5452 ;; promote flag and parse the type.
5453 (progn
5454 (c-forward-syntactic-ws)
5455 (when (looking-at c-identifier-start)
5456 (let ((c-promote-possible-types t))
5457 (c-forward-type))))
5458
5459 ;; Check if this arglist argument is a sole type. If
5460 ;; it's known then it's recorded in
5461 ;; `c-record-type-identifiers'. If it only is found
5462 ;; then it's recorded in `c-record-found-types' which we
5463 ;; might roll back if it turns out that this isn't an
5464 ;; angle bracket arglist afterall.
5465 (when (memq (char-before) '(?, ?<))
5466 (let ((orig-record-found-types c-record-found-types))
5467 (c-forward-syntactic-ws)
5468 (and (memq (c-forward-type) '(known found))
5469 (not (looking-at "[,>]"))
5470 ;; A found type was recorded but it's not the
5471 ;; only thing in the arglist argument, so reset
5472 ;; `c-record-found-types'.
5473 (setq c-record-found-types
5474 orig-record-found-types))))))
5475 5463
5476 (setq pos (point)) 5464 (when (or (looking-at "extends")
5477 (or (when (eq (char-after) ?>) 5465 (looking-at "super"))
5478 ;; Must check for '>' at the very start separately, 5466 (forward-word)
5479 ;; since the regexp below has to avoid ">>" without 5467 (c-forward-syntactic-ws)
5480 ;; using \\=. 5468 (let ((c-promote-possible-types t)
5481 (forward-char) 5469 (c-record-found-types t))
5482 t) 5470 (c-forward-type)
5483 5471 (c-forward-syntactic-ws))))))
5484 ;; Note: These regexps exploit the match order in \| so 5472
5485 ;; that "<>" is matched by "<" rather than "[^>:-]>". 5473 (setq pos (point))
5486 (c-syntactic-re-search-forward 5474
5487 (if c-restricted-<>-arglists 5475 (or
5488 ;; Stop on ',', '|', '&', '+' and '-' to catch 5476 ;; Note: These regexps exploit the match order in \| so
5489 ;; common binary operators that could be between 5477 ;; that "<>" is matched by "<" rather than "[^>:-]>".
5490 ;; two comparison expressions "a<b" and "c>d". 5478 (c-syntactic-re-search-forward
5491 "[<;{},|&+-]\\|\\([^>:-]>\\)" 5479 ;; Stop on ',', '|', '&', '+' and '-' to catch
5492 ;; Otherwise we still stop on ',' to find the 5480 ;; common binary operators that could be between
5493 ;; argument start positions. 5481 ;; two comparison expressions "a<b" and "c>d".
5494 "[<;{},]\\|\\([^>:-]>\\)") 5482 "[<;{},|+&-]\\|[>)]"
5495 nil 'move t t 1) 5483 nil t t)
5496 5484 t))
5497 ;; If the arglist starter has lost its open paren
5498 ;; syntax but not the closer, we won't find the
5499 ;; closer above since we only search in the
5500 ;; balanced sexp. In that case we stop just short
5501 ;; of it so check if the following char is the closer.
5502 (when (eq (char-after) ?>)
5503 (forward-char)
5504 t)))
5505 5485
5506 (cond 5486 (cond
5507 ((eq (char-before) ?>) 5487 ((eq (char-before) ?>)
5508 ;; Either an operator starting with '>' or the end of 5488 ;; Either an operator starting with '>' or the end of
5509 ;; the angle bracket arglist. 5489 ;; the angle bracket arglist.
5510 5490
@@ -5526,7 +5506,6 @@ comment at the start of cc-engine.el for more info."
5526 5506
5527 ((eq (char-before) ?<) 5507 ((eq (char-before) ?<)
5528 ;; Either an operator starting with '<' or a nested arglist. 5508 ;; Either an operator starting with '<' or a nested arglist.
5529
5530 (setq pos (point)) 5509 (setq pos (point))
5531 (let (id-start id-end subres keyword-match) 5510 (let (id-start id-end subres keyword-match)
5532 (if (if (looking-at c-<-op-cont-regexp) 5511 (if (if (looking-at c-<-op-cont-regexp)
@@ -5546,14 +5525,14 @@ comment at the start of cc-engine.el for more info."
5546 (when (or (setq keyword-match 5525 (when (or (setq keyword-match
5547 (looking-at c-opt-<>-sexp-key)) 5526 (looking-at c-opt-<>-sexp-key))
5548 (not (looking-at c-keywords-regexp))) 5527 (not (looking-at c-keywords-regexp)))
5549 (setq id-start (point)))) 5528 (setq id-start (point))))
5550 5529
5551 (setq subres 5530 (setq subres
5552 (let ((c-record-type-identifiers nil) 5531 (let ((c-promote-possible-types t)
5553 (c-record-found-types nil)) 5532 (c-record-found-types t))
5554 (c-forward-<>-arglist-recur 5533 (c-forward-<>-arglist-recur
5555 (and keyword-match 5534 (and keyword-match
5556 (c-keyword-member 5535 (c-keyword-member
5557 (c-keyword-sym (match-string 1)) 5536 (c-keyword-sym (match-string 1))
5558 'c-<>-type-kwds))))) 5537 'c-<>-type-kwds)))))
5559 ))) 5538 )))
@@ -5574,14 +5553,16 @@ comment at the start of cc-engine.el for more info."
5574 (c-forward-syntactic-ws) 5553 (c-forward-syntactic-ws)
5575 (looking-at c-opt-identifier-concat-key))) 5554 (looking-at c-opt-identifier-concat-key)))
5576 (c-record-ref-id (cons id-start id-end)) 5555 (c-record-ref-id (cons id-start id-end))
5577 (c-record-type-id (cons id-start id-end)))))) 5556 (c-record-type-id (cons id-start id-end))))))
5578 t) 5557 t)
5579 5558
5580 ((and (eq (char-before) ?,) 5559 ((and (not c-restricted-<>-arglists)
5581 (not c-restricted-<>-arglists)) 5560 (or (and (eq (char-before) ?&)
5582 ;; Just another argument. Record the position. The 5561 (not (eq (char-after) ?&)))
5583 ;; type check stuff that made us stop at it is at 5562 (eq (char-before) ?,)))
5584 ;; the top of the loop. 5563 ;; Just another argument. Record the position. The
5564 ;; type check stuff that made us stop at it is at
5565 ;; the top of the loop.
5585 (setq arg-start-pos (cons (point) arg-start-pos))) 5566 (setq arg-start-pos (cons (point) arg-start-pos)))
5586 5567
5587 (t 5568 (t
@@ -5590,7 +5571,6 @@ comment at the start of cc-engine.el for more info."
5590 ;; it's useless to try to find a surrounding arglist 5571 ;; it's useless to try to find a surrounding arglist
5591 ;; if we're nested. 5572 ;; if we're nested.
5592 (throw 'angle-bracket-arglist-escape nil)))))) 5573 (throw 'angle-bracket-arglist-escape nil))))))
5593
5594 (if res 5574 (if res
5595 (or c-record-found-types t))))) 5575 (or c-record-found-types t)))))
5596 5576
@@ -5793,9 +5773,8 @@ comment at the start of cc-engine.el for more info."
5793 ((and c-recognize-<>-arglists 5773 ((and c-recognize-<>-arglists
5794 (eq (char-after) ?<)) 5774 (eq (char-after) ?<))
5795 ;; Maybe an angle bracket arglist. 5775 ;; Maybe an angle bracket arglist.
5796 5776 (when (let ((c-record-type-identifiers t)
5797 (when (let (c-record-type-identifiers 5777 (c-record-found-types t))
5798 c-record-found-types)
5799 (c-forward-<>-arglist nil)) 5778 (c-forward-<>-arglist nil))
5800 5779
5801 (c-add-type start (1+ pos)) 5780 (c-add-type start (1+ pos))
@@ -5844,6 +5823,9 @@ comment at the start of cc-engine.el for more info."
5844 ;; `c-record-type-identifiers' is non-nil. 5823 ;; `c-record-type-identifiers' is non-nil.
5845 ;; 5824 ;;
5846 ;; This function might do hidden buffer changes. 5825 ;; This function might do hidden buffer changes.
5826 (when (looking-at "<")
5827 (c-forward-<>-arglist t)
5828 (c-forward-syntactic-ws))
5847 5829
5848 (let ((start (point)) pos res name-res id-start id-end id-range) 5830 (let ((start (point)) pos res name-res id-start id-end id-range)
5849 5831
@@ -6043,6 +6025,18 @@ comment at the start of cc-engine.el for more info."
6043 6025
6044 res)) 6026 res))
6045 6027
6028(defun c-forward-annotation ()
6029 ;; Used for Java code only at the moment. Assumes point is on the
6030 ;; @, moves forward an annotation. returns nil if there is no
6031 ;; annotation at point.
6032 (and (looking-at "@")
6033 (progn (forward-char) t)
6034 (c-forward-type)
6035 (progn (c-forward-syntactic-ws) t)
6036 (if (looking-at "(")
6037 (c-go-list-forward)
6038 t)))
6039
6046 6040
6047;; Handling of large scale constructs like statements and declarations. 6041;; Handling of large scale constructs like statements and declarations.
6048 6042
@@ -6212,6 +6206,9 @@ comment at the start of cc-engine.el for more info."
6212 (save-rec-type-ids c-record-type-identifiers) 6206 (save-rec-type-ids c-record-type-identifiers)
6213 (save-rec-ref-ids c-record-ref-identifiers)) 6207 (save-rec-ref-ids c-record-ref-identifiers))
6214 6208
6209 (while (c-forward-annotation)
6210 (c-forward-syntactic-ws))
6211
6215 ;; Check for a type. Unknown symbols are treated as possible 6212 ;; Check for a type. Unknown symbols are treated as possible
6216 ;; types, but they could also be specifiers disguised through 6213 ;; types, but they could also be specifiers disguised through
6217 ;; macros like __INLINE__, so we recognize both types and known 6214 ;; macros like __INLINE__, so we recognize both types and known
@@ -6545,13 +6542,14 @@ comment at the start of cc-engine.el for more info."
6545 ;; CASE 3 6542 ;; CASE 3
6546 (when (= (point) start) 6543 (when (= (point) start)
6547 ;; Got a plain list of identifiers. If a colon follows it's 6544 ;; Got a plain list of identifiers. If a colon follows it's
6548 ;; a valid label. Otherwise the last one probably is the 6545 ;; a valid label. Otherwise the last one probably is the
6549 ;; declared identifier and we should back up to the previous 6546 ;; declared identifier and we should back up to the previous
6550 ;; type, providing it isn't a cast. 6547 ;; type, providing it isn't a cast.
6551 (if (eq (char-after) ?:) 6548 (if (and (eq (char-after) ?:)
6552 ;; If we've found a specifier keyword then it's a 6549 (not (c-major-mode-is 'java-mode)))
6553 ;; declaration regardless. 6550 ;; If we've found a specifier keyword then it's a
6554 (throw 'at-decl-or-cast (eq at-decl-or-cast t)) 6551 ;; declaration regardless.
6552 (throw 'at-decl-or-cast (eq at-decl-or-cast t))
6555 (setq backup-if-not-cast t) 6553 (setq backup-if-not-cast t)
6556 (throw 'at-decl-or-cast t))) 6554 (throw 'at-decl-or-cast t)))
6557 6555
@@ -8512,7 +8510,7 @@ comment at the start of cc-engine.el for more info."
8512 ;; 8510 ;;
8513 ;; This function might do hidden buffer changes. 8511 ;; This function might do hidden buffer changes.
8514 8512
8515 (let (special-brace-list) 8513 (let (special-brace-list placeholder)
8516 (goto-char indent-point) 8514 (goto-char indent-point)
8517 (skip-chars-forward " \t") 8515 (skip-chars-forward " \t")
8518 8516
@@ -8619,6 +8617,22 @@ comment at the start of cc-engine.el for more info."
8619 (c-add-stmt-syntax 'func-decl-cont nil t 8617 (c-add-stmt-syntax 'func-decl-cont nil t
8620 containing-sexp paren-state)) 8618 containing-sexp paren-state))
8621 8619
8620 ;;CASE F: continued statement and the only preceding items are
8621 ;;annotations.
8622 ((and (c-major-mode-is 'java-mode)
8623 (setq placeholder (point))
8624 (c-beginning-of-statement-1)
8625 (progn
8626 (while (and (c-forward-annotation)
8627 (< (point) placeholder))
8628 (c-forward-syntactic-ws))
8629 t)
8630 (prog1
8631 (>= (point) placeholder)
8632 (goto-char placeholder)))
8633 (c-beginning-of-statement-1 containing-sexp)
8634 (c-add-syntax 'annotation-var-cont (point)))
8635
8622 ;; CASE D: continued statement. 8636 ;; CASE D: continued statement.
8623 (t 8637 (t
8624 (c-beginning-of-statement-1 containing-sexp) 8638 (c-beginning-of-statement-1 containing-sexp)
@@ -8718,7 +8732,6 @@ comment at the start of cc-engine.el for more info."
8718 (when (and containing-sexp 8732 (when (and containing-sexp
8719 (eq (char-after containing-sexp) ?\()) 8733 (eq (char-after containing-sexp) ?\())
8720 (setq c-stmt-delim-chars c-stmt-delim-chars-with-comma)) 8734 (setq c-stmt-delim-chars c-stmt-delim-chars-with-comma))
8721
8722 ;; cache char before and after indent point, and move point to 8735 ;; cache char before and after indent point, and move point to
8723 ;; the most likely position to perform the majority of tests 8736 ;; the most likely position to perform the majority of tests
8724 (goto-char indent-point) 8737 (goto-char indent-point)
@@ -9468,23 +9481,36 @@ comment at the start of cc-engine.el for more info."
9468 (c-add-syntax 'objc-method-args-cont placeholder)) 9481 (c-add-syntax 'objc-method-args-cont placeholder))
9469 9482
9470 ;; CASE 5L: we are at the first argument of a template 9483 ;; CASE 5L: we are at the first argument of a template
9471 ;; arglist that begins on the previous line. 9484 ;; arglist that begins on the previous line.
9472 ((and c-recognize-<>-arglists 9485 ((and c-recognize-<>-arglists
9473 (eq (char-before) ?<) 9486 (eq (char-before) ?<)
9474 (setq placeholder (1- (point))) 9487 (not (and c-overloadable-operators-regexp
9475 (not (and c-overloadable-operators-regexp 9488 (c-after-special-operator-id lim))))
9476 (c-after-special-operator-id lim)))) 9489 (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
9477 (c-beginning-of-statement-1 (c-safe-position (point) paren-state)) 9490 (c-add-syntax 'template-args-cont (c-point 'boi)))
9478 (c-add-syntax 'template-args-cont (c-point 'boi) placeholder)) 9491
9479 9492 ;; CASE 5Q: we are at a statement within a macro.
9480 ;; CASE 5Q: we are at a statement within a macro. 9493 (macro-start
9481 (macro-start 9494 (c-beginning-of-statement-1 containing-sexp)
9482 (c-beginning-of-statement-1 containing-sexp) 9495 (c-add-stmt-syntax 'statement nil t containing-sexp paren-state))
9483 (c-add-stmt-syntax 'statement nil t containing-sexp paren-state)) 9496
9484 9497 ;;CASE 5N: We are at a tompmost continuation line and the only
9485 ;; CASE 5M: we are at a topmost continuation line 9498 ;;preceding items are annotations.
9486 (t 9499 ((and (c-major-mode-is 'java-mode)
9487 (c-beginning-of-statement-1 (c-safe-position (point) paren-state)) 9500 (setq placeholder (point))
9501 (c-beginning-of-statement-1)
9502 (progn
9503 (while (and (c-forward-annotation))
9504 (c-forward-syntactic-ws))
9505 t)
9506 (prog1
9507 (>= (point) placeholder)
9508 (goto-char placeholder)))
9509 (c-add-syntax 'annotation-top-cont (c-point 'boi)))
9510
9511 ;; CASE 5M: we are at a topmost continuation line
9512 (t
9513 (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
9488 (when (c-major-mode-is 'objc-mode) 9514 (when (c-major-mode-is 'objc-mode)
9489 (setq placeholder (point)) 9515 (setq placeholder (point))
9490 (while (and (c-forward-objc-directive) 9516 (while (and (c-forward-objc-directive)
@@ -9495,43 +9521,20 @@ comment at the start of cc-engine.el for more info."
9495 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) 9521 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
9496 )) 9522 ))
9497 9523
9498 ;; (CASE 6 has been removed.)
9499 9524
9500 ;; CASE 19: line is an expression, not a statement, and is directly 9525 ;; (CASE 6 has been removed.)
9501 ;; contained by a template delimiter. Most likely, we are in a
9502 ;; template arglist within a statement. This case is based on CASE
9503 ;; 7. At some point in the future, we may wish to create more
9504 ;; syntactic symbols such as `template-intro',
9505 ;; `template-cont-nonempty', etc., and distinguish between them as we
9506 ;; do for `arglist-intro' etc. (2009-12-07).
9507 ((and c-recognize-<>-arglists
9508 (setq containing-< (c-up-list-backward indent-point containing-sexp))
9509 (eq (char-after containing-<) ?\<))
9510 (setq placeholder (c-point 'boi containing-<))
9511 (goto-char containing-sexp) ; Most nested Lbrace/Lparen (but not
9512 ; '<') before indent-point.
9513 (if (>= (point) placeholder)
9514 (progn
9515 (forward-char)
9516 (skip-chars-forward " \t"))
9517 (goto-char placeholder))
9518 (c-add-stmt-syntax 'template-args-cont (list containing-<) t
9519 (c-most-enclosing-brace c-state-cache (point))
9520 paren-state))
9521
9522 9526
9523 ;; CASE 7: line is an expression, not a statement. Most 9527 ;; CASE 7: line is an expression, not a statement. Most
9524 ;; likely we are either in a function prototype or a function 9528 ;; likely we are either in a function prototype or a function
9525 ;; call argument list, or a template argument list. 9529 ;; call argument list
9526 ((not (or (and c-special-brace-lists 9530 ((not (or (and c-special-brace-lists
9527 (save-excursion 9531 (save-excursion
9528 (goto-char containing-sexp) 9532 (goto-char containing-sexp)
9529 (c-looking-at-special-brace-list))) 9533 (c-looking-at-special-brace-list)))
9530 (eq (char-after containing-sexp) ?{) 9534 (eq (char-after containing-sexp) ?{)))
9531 (eq (char-after containing-sexp) ?<))) 9535 (cond
9532 (cond
9533 9536
9534 ;; CASE 7A: we are looking at the arglist closing paren. 9537 ;; CASE 7A: we are looking at the arglist closing paren.
9535 ;; C.f. case 7F. 9538 ;; C.f. case 7F.
9536 ((memq char-after-ip '(?\) ?\])) 9539 ((memq char-after-ip '(?\) ?\]))
9537 (goto-char containing-sexp) 9540 (goto-char containing-sexp)
@@ -9543,12 +9546,34 @@ comment at the start of cc-engine.el for more info."
9543 (skip-chars-forward " \t")) 9546 (skip-chars-forward " \t"))
9544 (goto-char placeholder)) 9547 (goto-char placeholder))
9545 (c-add-stmt-syntax 'arglist-close (list containing-sexp) t 9548 (c-add-stmt-syntax 'arglist-close (list containing-sexp) t
9546 (c-most-enclosing-brace paren-state (point)) 9549 (c-most-enclosing-brace paren-state (point))
9547 paren-state)) 9550 paren-state))
9548 9551
9549 ;; CASE 7B: Looking at the opening brace of an 9552 ;; CASE 19: line is an expression, not a statement, and is directly
9550 ;; in-expression block or brace list. C.f. cases 4, 16A 9553 ;; contained by a template delimiter. Most likely, we are in a
9551 ;; and 17E. 9554 ;; template arglist within a statement. This case is based on CASE
9555 ;; 7. At some point in the future, we may wish to create more
9556 ;; syntactic symbols such as `template-intro',
9557 ;; `template-cont-nonempty', etc., and distinguish between them as we
9558 ;; do for `arglist-intro' etc. (2009-12-07).
9559 ((and c-recognize-<>-arglists
9560 (setq containing-< (c-up-list-backward indent-point containing-sexp))
9561 (eq (char-after containing-<) ?\<))
9562 (setq placeholder (c-point 'boi containing-<))
9563 (goto-char containing-sexp) ; Most nested Lbrace/Lparen (but not
9564 ; '<') before indent-point.
9565 (if (>= (point) placeholder)
9566 (progn
9567 (forward-char)
9568 (skip-chars-forward " \t"))
9569 (goto-char placeholder))
9570 (c-add-stmt-syntax 'template-args-cont (list containing-<) t
9571 (c-most-enclosing-brace c-state-cache (point))
9572 paren-state))
9573
9574 ;; CASE 7B: Looking at the opening brace of an
9575 ;; in-expression block or brace list. C.f. cases 4, 16A
9576 ;; and 17E.
9552 ((and (eq char-after-ip ?{) 9577 ((and (eq char-after-ip ?{)
9553 (progn 9578 (progn
9554 (setq placeholder (c-inside-bracelist-p (point) 9579 (setq placeholder (c-inside-bracelist-p (point)
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 907c308daca..219eb25368c 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -194,6 +194,10 @@
194 (unless (face-property-instance oldface 'reverse) 194 (unless (face-property-instance oldface 'reverse)
195 (invert-face newface))))) 195 (invert-face newface)))))
196 196
197(defvar c-annotation-face (make-face 'c-annotation-face)
198 "Face used to highlight annotations in java-mode and other modes that may wish to use it.")
199(set-face-foreground 'c-annotation-face "blue")
200
197(eval-and-compile 201(eval-and-compile
198 ;; We need the following functions during compilation since they're 202 ;; We need the following functions during compilation since they're
199 ;; called when the `c-lang-defconst' initializers are evaluated. 203 ;; called when the `c-lang-defconst' initializers are evaluated.
@@ -1538,6 +1542,9 @@ higher."
1538 '((c-fontify-types-and-refs ((c-promote-possible-types t)) 1542 '((c-fontify-types-and-refs ((c-promote-possible-types t))
1539 (c-forward-keyword-clause 1) 1543 (c-forward-keyword-clause 1)
1540 (if (> (point) limit) (goto-char limit)))))))) 1544 (if (> (point) limit) (goto-char limit))))))))
1545
1546 ,@(when (c-major-mode-is 'java-mode)
1547 `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
1541 )) 1548 ))
1542 1549
1543(c-lang-defconst c-matchers-1 1550(c-lang-defconst c-matchers-1
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index d3669f259de..ae0ed1b928a 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -359,7 +359,7 @@ The syntax tables aren't stored directly since they're quite large."
359 (let ((table (make-syntax-table))) 359 (let ((table (make-syntax-table)))
360 (c-populate-syntax-table table) 360 (c-populate-syntax-table table)
361 ;; Mode specific syntaxes. 361 ;; Mode specific syntaxes.
362 ,(cond ((c-major-mode-is 'objc-mode) 362 ,(cond ((or (c-major-mode-is 'objc-mode) (c-major-mode-is 'java-mode))
363 ;; Let '@' be part of symbols in ObjC to cope with 363 ;; Let '@' be part of symbols in ObjC to cope with
364 ;; its compiler directives as single keyword tokens. 364 ;; its compiler directives as single keyword tokens.
365 ;; This is then necessary since it's assumed that 365 ;; This is then necessary since it's assumed that
@@ -382,7 +382,7 @@ The syntax tables aren't stored directly since they're quite large."
382 ;; '<' and '>' characters. Therefore this syntax table might go 382 ;; '<' and '>' characters. Therefore this syntax table might go
383 ;; away when CC Mode handles templates correctly everywhere. 383 ;; away when CC Mode handles templates correctly everywhere.
384 t nil 384 t nil
385 c++ `(lambda () 385 (java c++) `(lambda ()
386 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table)))) 386 (let ((table (funcall ,(c-lang-const c-make-mode-syntax-table))))
387 (modify-syntax-entry ?< "(>" table) 387 (modify-syntax-entry ?< "(>" table)
388 (modify-syntax-entry ?> ")<" table) 388 (modify-syntax-entry ?> ")<" table)
@@ -425,7 +425,7 @@ the new syntax, as accepted by `modify-syntax-entry'."
425 ;; it as an indentifier character since it's often used in various 425 ;; it as an indentifier character since it's often used in various
426 ;; machine generated identifiers. 426 ;; machine generated identifiers.
427 t '((?_ . "w") (?$ . "w")) 427 t '((?_ . "w") (?$ . "w"))
428 objc (append '((?@ . "w")) 428 (objc java) (append '((?@ . "w"))
429 (c-lang-const c-identifier-syntax-modifications)) 429 (c-lang-const c-identifier-syntax-modifications))
430 awk '((?_ . "w"))) 430 awk '((?_ . "w")))
431(c-lang-defvar c-identifier-syntax-modifications 431(c-lang-defvar c-identifier-syntax-modifications
@@ -502,9 +502,10 @@ parameters \(point-min), \(point-max) and <buffer size>."
502 502
503(c-lang-defconst c-symbol-start 503(c-lang-defconst c-symbol-start
504 "Regexp that matches the start of a symbol, i.e. any identifier or 504 "Regexp that matches the start of a symbol, i.e. any identifier or
505keyword. It's unspecified how far it matches. Does not contain a \\| 505keyword. It's unspecified how far it matches. Does not contain a \\|
506operator at the top level." 506operator at the top level."
507 t (concat "[" c-alpha "_]") 507 t (concat "[" c-alpha "_]")
508 java (concat "[" c-alpha "_@]")
508 objc (concat "[" c-alpha "@]") 509 objc (concat "[" c-alpha "@]")
509 pike (concat "[" c-alpha "_`]")) 510 pike (concat "[" c-alpha "_`]"))
510(c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) 511(c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
@@ -859,7 +860,7 @@ since CC Mode treats every identifier as an expression."
859 860
860 ;; Primary. 861 ;; Primary.
861 ,@(c-lang-const c-identifier-ops) 862 ,@(c-lang-const c-identifier-ops)
862 ,@(cond ((c-major-mode-is 'c++-mode) 863 ,@(cond ((or (c-major-mode-is 'c++-mode) (c-major-mode-is 'java-mode))
863 `((postfix-if-paren "<" ">"))) ; Templates. 864 `((postfix-if-paren "<" ">"))) ; Templates.
864 ((c-major-mode-is 'pike-mode) 865 ((c-major-mode-is 'pike-mode)
865 `((prefix "global" "predef"))) 866 `((prefix "global" "predef")))
@@ -1118,6 +1119,7 @@ operators."
1118 t 1119 t
1119 "\\`<." 1120 "\\`<."
1120 (lambda (op) (substring op 1))))) 1121 (lambda (op) (substring op 1)))))
1122
1121(c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp)) 1123(c-lang-defvar c-<-op-cont-regexp (c-lang-const c-<-op-cont-regexp))
1122 1124
1123(c-lang-defconst c->-op-cont-regexp 1125(c-lang-defconst c->-op-cont-regexp
@@ -1127,7 +1129,13 @@ operators."
1127 (c-filter-ops (c-lang-const c-all-op-syntax-tokens) 1129 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1128 t 1130 t
1129 "\\`>." 1131 "\\`>."
1130 (lambda (op) (substring op 1))))) 1132 (lambda (op) (substring op 1))))
1133 java (c-make-keywords-re nil
1134 (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1135 t
1136 "\\`>[^>]\\|\\`>>[^>]"
1137 (lambda (op) (substring op 1)))))
1138
1131(c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp)) 1139(c-lang-defvar c->-op-cont-regexp (c-lang-const c->-op-cont-regexp))
1132 1140
1133(c-lang-defconst c-stmt-delim-chars 1141(c-lang-defconst c-stmt-delim-chars
@@ -1628,7 +1636,7 @@ following identifier as a type; the keyword must also be present on
1628 c++ '("class" "struct" "union") 1636 c++ '("class" "struct" "union")
1629 objc '("struct" "union" 1637 objc '("struct" "union"
1630 "@interface" "@implementation" "@protocol") 1638 "@interface" "@implementation" "@protocol")
1631 java '("class" "interface") 1639 java '("class" "@interface" "interface")
1632 idl '("component" "eventtype" "exception" "home" "interface" "struct" 1640 idl '("component" "eventtype" "exception" "home" "interface" "struct"
1633 "union" "valuetype" 1641 "union" "valuetype"
1634 ;; In CORBA PSDL: 1642 ;; In CORBA PSDL:
@@ -1651,7 +1659,7 @@ If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
1651`c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses 1659`c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
1652will be handled." 1660will be handled."
1653 t '("enum") 1661 t '("enum")
1654 (java awk) nil) 1662 (awk) nil)
1655 1663
1656(c-lang-defconst c-brace-list-key 1664(c-lang-defconst c-brace-list-key
1657 ;; Regexp matching the start of declarations where the following 1665 ;; Regexp matching the start of declarations where the following
@@ -1772,7 +1780,7 @@ will be handled."
1772 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn") 1780 "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
1773 ;; Note: "const" is not used in Java, but it's still a reserved keyword. 1781 ;; Note: "const" is not used in Java, but it's still a reserved keyword.
1774 java '("abstract" "const" "final" "native" "private" "protected" "public" 1782 java '("abstract" "const" "final" "native" "private" "protected" "public"
1775 "static" "strictfp" "synchronized" "transient" "volatile") 1783 "static" "strictfp" "synchronized" "transient" "volatile" "@[A-Za-z0-9]+")
1776 pike '("final" "inline" "local" "nomask" "optional" "private" "protected" 1784 pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
1777 "public" "static" "variant")) 1785 "public" "static" "variant"))
1778 1786
@@ -1858,7 +1866,11 @@ one of `c-type-list-kwds', `c-ref-list-kwds',
1858 1866
1859(c-lang-defconst c-prefix-spec-kwds-re 1867(c-lang-defconst c-prefix-spec-kwds-re
1860 ;; Adorned regexp of `c-prefix-spec-kwds'. 1868 ;; Adorned regexp of `c-prefix-spec-kwds'.
1861 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))) 1869 t (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds))
1870 java (replace-regexp-in-string
1871 "\\\\\\[" "["
1872 (replace-regexp-in-string "\\\\\\+" "+" (c-make-keywords-re t (c-lang-const c-prefix-spec-kwds)))))
1873
1862(c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re)) 1874(c-lang-defvar c-prefix-spec-kwds-re (c-lang-const c-prefix-spec-kwds-re))
1863 1875
1864(c-lang-defconst c-specifier-key 1876(c-lang-defconst c-specifier-key
@@ -1950,7 +1962,7 @@ or variable identifier (that's being defined)."
1950 t nil 1962 t nil
1951 c++ '("operator") 1963 c++ '("operator")
1952 objc '("@class") 1964 objc '("@class")
1953 java '("import" "new" "extends" "implements" "throws") 1965 java '("import" "new" "extends" "super" "implements" "throws")
1954 idl '("manages" "native" "primarykey" "supports" 1966 idl '("manages" "native" "primarykey" "supports"
1955 ;; In CORBA PSDL: 1967 ;; In CORBA PSDL:
1956 "as" "implements" "of" "scope") 1968 "as" "implements" "of" "scope")
@@ -2499,7 +2511,7 @@ more info."
2499 ;; in all languages except Java for when a cpp macro definition 2511 ;; in all languages except Java for when a cpp macro definition
2500 ;; begins with a declaration. 2512 ;; begins with a declaration.
2501 t "\\([\{\}\(\);,]+\\)" 2513 t "\\([\{\}\(\);,]+\\)"
2502 java "\\([\{\}\(;,]+\\)" 2514 java "\\([\{\}\(;,<]+\\)"
2503 ;; Match "<" in C++ to get the first argument in a template arglist. 2515 ;; Match "<" in C++ to get the first argument in a template arglist.
2504 ;; In that case there's an additional check in `c-find-decl-spots' 2516 ;; In that case there's an additional check in `c-find-decl-spots'
2505 ;; that it got open paren syntax. 2517 ;; that it got open paren syntax.
@@ -2759,7 +2771,7 @@ It's undefined whether identifier syntax (see `c-identifier-syntax-table')
2759is in effect or not." 2771is in effect or not."
2760 t nil 2772 t nil
2761 (c c++ objc pike) "\\(\\.\\.\\.\\)" 2773 (c c++ objc pike) "\\(\\.\\.\\.\\)"
2762 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\)")) 2774 java (concat "\\(\\[" (c-lang-const c-simple-ws) "*\\]\\|\\.\\.\\.\\)"))
2763(c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key)) 2775(c-lang-defvar c-opt-type-suffix-key (c-lang-const c-opt-type-suffix-key))
2764 2776
2765(c-lang-defvar c-known-type-key 2777(c-lang-defvar c-known-type-key
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 070d044c199..f9917ce406e 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -522,7 +522,7 @@ that requires a literal mode spec at compile time."
522 522
523 (when (or c-recognize-<>-arglists 523 (when (or c-recognize-<>-arglists
524 (c-major-mode-is 'awk-mode) 524 (c-major-mode-is 'awk-mode)
525 (c-major-mode-is '(c-mode c++-mode objc-mode))) 525 (c-major-mode-is '(java-mode c-mode c++-mode objc-mode)))
526 ;; We'll use the syntax-table text property to change the syntax 526 ;; We'll use the syntax-table text property to change the syntax
527 ;; of some chars for this language, so do the necessary setup for 527 ;; of some chars for this language, so do the necessary setup for
528 ;; that. 528 ;; that.
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index 82015687cb2..f61c2a9fd06 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -1056,9 +1056,13 @@ can always override the use of `c-default-style' by making calls to
1056 ;; Anchor pos: Boi at the topmost intro line. 1056 ;; Anchor pos: Boi at the topmost intro line.
1057 (knr-argdecl . 0) 1057 (knr-argdecl . 0)
1058 ;; Anchor pos: At the beginning of the first K&R argdecl. 1058 ;; Anchor pos: At the beginning of the first K&R argdecl.
1059 (topmost-intro . 0) 1059 (topmost-intro . 0)
1060 ;; Anchor pos: Bol at the last line of previous construct. 1060 ;; Anchor pos: Bol at the last line of previous construct.
1061 (topmost-intro-cont . c-lineup-topmost-intro-cont) 1061 (topmost-intro-cont . c-lineup-topmost-intro-cont)
1062 ;;Anchor pos: Bol at the topmost annotation line
1063 (annotation-top-cont . 0)
1064 ;;Anchor pos: Bol at the topmost annotation line
1065 (annotation-var-cont . +)
1062 ;; Anchor pos: Boi at the topmost intro line. 1066 ;; Anchor pos: Boi at the topmost intro line.
1063 (member-init-intro . +) 1067 (member-init-intro . +)
1064 ;; Anchor pos: Boi at the func decl arglist open. 1068 ;; Anchor pos: Boi at the func decl arglist open.
@@ -1285,12 +1289,16 @@ Here is the current list of valid syntactic element symbols:
1285 between them; in C++ and Java, throws declarations 1289 between them; in C++ and Java, throws declarations
1286 and other things can appear in this context. 1290 and other things can appear in this context.
1287 knr-argdecl-intro -- First line of a K&R C argument declaration. 1291 knr-argdecl-intro -- First line of a K&R C argument declaration.
1288 knr-argdecl -- Subsequent lines in a K&R C argument declaration. 1292 knr-argdecl -- Subsequent lines in a K&R C argument declaration.
1289 topmost-intro -- The first line in a topmost construct definition. 1293 topmost-intro -- The first line in a topmost construct definition.
1290 topmost-intro-cont -- Topmost definition continuation lines. 1294 topmost-intro-cont -- Topmost definition continuation lines.
1291 member-init-intro -- First line in a member initialization list. 1295 annotation-top-cont -- Topmost definition continuation line where only
1292 member-init-cont -- Subsequent member initialization list lines. 1296 annotations are on previous lines.
1293 inher-intro -- First line of a multiple inheritance list. 1297 annotation-var-cont -- A continuation of a C (or like) statement where
1298 only annotations are on previous lines.
1299 member-init-intro -- First line in a member initialization list.
1300 member-init-cont -- Subsequent member initialization list lines.
1301 inher-intro -- First line of a multiple inheritance list.
1294 inher-cont -- Subsequent multiple inheritance lines. 1302 inher-cont -- Subsequent multiple inheritance lines.
1295 block-open -- Statement block open brace. 1303 block-open -- Statement block open brace.
1296 block-close -- Statement block close brace. 1304 block-close -- Statement block close brace.
@@ -1376,7 +1384,7 @@ Here is the current list of valid syntactic element symbols:
1376 '(defun-block-intro block-open block-close statement statement-cont 1384 '(defun-block-intro block-open block-close statement statement-cont
1377 statement-block-intro statement-case-intro statement-case-open 1385 statement-block-intro statement-case-intro statement-case-open
1378 substatement substatement-open substatement-label case-label label 1386 substatement substatement-open substatement-label case-label label
1379 do-while-closure else-clause catch-clause inlambda)) 1387 do-while-closure else-clause catch-clause inlambda annotation-var-cont))
1380 1388
1381(defcustom c-style-variables-are-local-p t 1389(defcustom c-style-variables-are-local-p t
1382 "*Whether style variables should be buffer local by default. 1390 "*Whether style variables should be buffer local by default.
@@ -1577,7 +1585,7 @@ names)."))
1577 :group 'c) 1585 :group 'c)
1578 1586
1579(defcustom java-font-lock-extra-types 1587(defcustom java-font-lock-extra-types
1580 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw*")) 1588 (list (concat "[" c-upper "]\\sw*[" c-lower "]\\sw"))
1581 (c-make-font-lock-extra-types-blurb "Java" "java-mode" (concat 1589 (c-make-font-lock-extra-types-blurb "Java" "java-mode" (concat
1582"For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means 1590"For example, a value of (\"[" c-upper "]\\\\sw*[" c-lower "]\\\\sw*\") means
1583capitalized words are treated as type names (the requirement for a 1591capitalized words are treated as type names (the requirement for a