|
[CEDET-devel] Tags for anonymous java classes
From: <david.ponce@wa...> - 2004-08-24 13:00
|
Hi Eric,
Following users' requests to have semantic generate tags for anonymous
classes, you will find an implementation in the following patch.
As anonymous classes are part of variable initializers expression, I
considered them as member components of field declarations.
Also to have anonymous classes appear in imenu, I improved
semantic-imenu, and replaced `semantic-imenu-expandable-tag-class' by
an equivalent `semantic-imenu-expandable-tag-classes' that receives a
list of tag classes to expand instead of a single class.
wisent-java uses that to build sub menus for anonymous classes found
in variable definitions.
I did some quick tests and all seemed to work as expected :-)
However, I would like to have your feedback before to commit these
changes.
Thanks!
David
2004-08-24 David Ponce <david@...>
* cedet/semantic/semantic-imenu.el
(semantic-imenu-expandable-tag-classes): Rename from
`semantic-imenu-expandable-tag-class'. Accept a list of tag
classes. All uses changed.
* cedet/semantic/semantic-texi.el
(semantic-default-texi-setup): Update to use
`semantic-imenu-expandable-tag-classes'.
* cedet/semantic/doc/user-guide.texi
(imenu): Document `semantic-imenu-expandable-tag-classes' in place
of `semantic-imenu-expandable-tag-class'.
* cedet/semantic/wisent/wisent-java.el
(wisent-java-default-setup): Setup
`semantic-imenu-expandable-tag-classes' to expand types and
variables.
(semantic-tag-components): New java mode local override.
* cedet/semantic/wisent/wisent-java.wy
(prologue): Define `wisent-java-wy--anons'.
(field_declaration): Include definition of anonymous classes.
(variable_declarator): Handle definition of anonymous classes.
(class_instance_creation_expression): Ditto.
Index: semantic/semantic-imenu.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-imenu.el,v
retrieving revision 1.51
diff -c -r1.51 semantic-imenu.el
*** semantic/semantic-imenu.el 21 Mar 2004 07:45:33 -0000 1.51
--- semantic/semantic-imenu.el 24 Aug 2004 12:35:35 -0000
***************
*** 155,167 ****
(defvar semantic-imenu-auto-rebuild-running nil
"Non-nil if `semantic-imenu-rebuild-directory-indexes' is running.")
! (defvar semantic-imenu-expandable-tag-class 'type
! "Tags of this class will be given submenu with children.
! By default, a `type' has interesting children. In Texinfo, however,
! a `section' has interesting children.")
! (make-variable-buffer-local 'semantic-imenu-expandable-tag)
(semantic-varalias-obsolete 'semantic-imenu-expandable-token
! 'semantic-imenu-expandable-tag-class)
;;; Code:
(defun semantic-imenu-tag-overlay (tag)
--- 155,168 ----
(defvar semantic-imenu-auto-rebuild-running nil
"Non-nil if `semantic-imenu-rebuild-directory-indexes' is running.")
! (defvar semantic-imenu-expandable-tag-classes '(type)
! "List of expandable tag classes.
! Tags of those classes will be given submenu with children.
! By default, a `type' has interesting children. In Texinfo, however, a
! `section' has interesting children.")
! (make-variable-buffer-local 'semantic-imenu-expandable-tag-classes)
(semantic-varalias-obsolete 'semantic-imenu-expandable-token
! 'semantic-imenu-expandable-tag-classes)
;;; Code:
(defun semantic-imenu-tag-overlay (tag)
***************
*** 343,350 ****
(append index
;; do not create a menu separator in the parent menu
;; when creating a sub-menu
! (if (eq (semantic-tag-class (car item))
! semantic-imenu-expandable-tag-class)
(semantic-create-imenu-subindex item)
(cons
'("---")
--- 344,351 ----
(append index
;; do not create a menu separator in the parent menu
;; when creating a sub-menu
! (if (memq (semantic-tag-class (car item))
! semantic-imenu-expandable-tag-classes)
(semantic-create-imenu-subindex item)
(cons
'("---")
***************
*** 369,376 ****
(setq tag (car tags)
children (semantic-tag-components-with-overlays tag))
(if (and (not notypecheck)
! (eq (semantic-tag-class tag)
! semantic-imenu-expandable-tag-class)
children
)
;; to keep an homogeneous menu organisation, type menu items
--- 370,377 ----
(setq tag (car tags)
children (semantic-tag-components-with-overlays tag))
(if (and (not notypecheck)
! (memq (semantic-tag-class tag)
! semantic-imenu-expandable-tag-classes)
children
)
;; to keep an homogeneous menu organisation, type menu items
***************
*** 515,522 ****
(cond ((eq (length taglist) 1)
(semantic-format-tag-abbreviate
(car taglist) nil semantic-which-function-use-color))
! ((eq (semantic-tag-class (car taglist))
! semantic-imenu-expandable-tag-class)
(concat (semantic-format-tag-name
(car taglist) semantic-which-function-use-color) "."
;; recurse until we no longer have a type
--- 516,523 ----
(cond ((eq (length taglist) 1)
(semantic-format-tag-abbreviate
(car taglist) nil semantic-which-function-use-color))
! ((memq (semantic-tag-class (car taglist))
! semantic-imenu-expandable-tag-classes)
(concat (semantic-format-tag-name
(car taglist) semantic-which-function-use-color) "."
;; recurse until we no longer have a type
Index: semantic/semantic-texi.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/semantic-texi.el,v
retrieving revision 1.29
diff -c -r1.29 semantic-texi.el
*** semantic/semantic-texi.el 29 Apr 2004 10:10:52 -0000 1.29
--- semantic/semantic-texi.el 24 Aug 2004 12:35:36 -0000
***************
*** 354,360 ****
semantic-symbol->name-assoc-list '((section . "Section")
(def . "Definition")
)
! semantic-imenu-expandable-tag-class 'section
semantic-imenu-bucketize-file nil
semantic-imenu-bucketize-type-members nil
senator-step-at-start-end-tag-classes '(section)
--- 354,360 ----
semantic-symbol->name-assoc-list '((section . "Section")
(def . "Definition")
)
! semantic-imenu-expandable-tag-classes '(section)
semantic-imenu-bucketize-file nil
semantic-imenu-bucketize-type-members nil
senator-step-at-start-end-tag-classes '(section)
Index: semantic/doc/user-guide.texi
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/doc/user-guide.texi,v
retrieving revision 1.18
diff -c -r1.18 user-guide.texi
*** semantic/doc/user-guide.texi 13 Apr 2004 14:04:31 -0000 1.18
--- semantic/doc/user-guide.texi 24 Aug 2004 12:35:36 -0000
***************
*** 217,226 ****
When adding support to a language, this variable may need to be set:
! @defvar semantic-imenu-expandable-tag-class
! Tags of this class will be given submenu with children.
! By default, a @code{type} has interesting children. In Texinfo, however,
! a @code{section} has interesting children.
@end defvar
@node senator
--- 217,228 ----
When adding support to a language, this variable may need to be set:
! @defvar semantic-imenu-expandable-tag-classes
! @anchor{semantic-imenu-expandable-tag-classes}
! List of expandable tag classes.
! Tags of those classes will be given submenu with children.
! By default, a @code{type} has interesting children. In Texinfo, however, a
! @code{section} has interesting children.
@end defvar
@node senator
Index: semantic/wisent/wisent-java.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-java.el,v
retrieving revision 1.46
diff -c -r1.46 wisent-java.el
*** semantic/wisent/wisent-java.el 29 Apr 2004 10:10:53 -0000 1.46
--- semantic/wisent/wisent-java.el 24 Aug 2004 12:35:36 -0000
***************
*** 88,93 ****
--- 88,94 ----
semantic-tag-expand-function 'wisent-java-expand-tag
;; Environment
semantic-imenu-summary-function 'semantic-format-tag-prototype
+ semantic-imenu-expandable-tag-classes '(type variable)
imenu-create-index-function 'semantic-create-imenu-index
semantic-type-relation-separator-character '(".")
semantic-command-separation-character ";"
***************
*** 115,120 ****
--- 116,128 ----
;;; Overridden Semantic API.
;;
+ (define-mode-local-override semantic-tag-components java-mode (tag)
+ "Return a list of components for TAG."
+ (if (semantic-tag-of-class-p tag 'function)
+ (semantic-tag-function-arguments tag)
+ ;; Simply return the value of the :members attribute.
+ (semantic-tag-get-attribute tag :members)))
+
(define-mode-local-override semantic-get-local-variables
java-mode ()
"Get local variable declarations from the current context."
Index: semantic/wisent/wisent-java.wy
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-java.wy,v
retrieving revision 1.21
diff -c -r1.21 wisent-java.wy
*** semantic/wisent/wisent-java.wy 15 Jun 2004 18:20:39 -0000 1.21
--- semantic/wisent/wisent-java.wy 24 Aug 2004 12:35:36 -0000
***************
*** 50,55 ****
--- 50,57 ----
%{
;; Stack of enum names in scope.
(defvar wisent-java-wy--enums nil)
+ ;; Stack of anonymous class declarations found in an expression.
+ (defvar wisent-java-wy--anons nil)
}
%package wisent-java-wy
***************
*** 866,875 ****
;;
field_declaration
: modifiers_opt type variable_declarators SEMICOLON
! (EXPANDTAG
! (VARIABLE-TAG $3 $2 nil
! :typemodifiers $1)
! )
;
variable_declarators
--- 868,880 ----
;;
field_declaration
: modifiers_opt type variable_declarators SEMICOLON
! (let* ((decls (mapcar 'car $3))
! (anons (apply 'nconc (nreverse (mapcar 'cdr $3)))))
! (EXPANDTAG
! (VARIABLE-TAG decls $2 nil
! :typemodifiers $1
! :members anons)
! ))
;
variable_declarators
***************
*** 881,889 ****
variable_declarator
: variable_declarator_id
! (cons $1 $region)
! | variable_declarator_id EQ variable_initializer
! (cons $1 $region)
;
variable_declarator_id
--- 886,897 ----
variable_declarator
: variable_declarator_id
! (cons (cons $1 $region) nil)
! | variable_declarator_id
! ;; Clean-up the stack of anonymous class declarations
! (setq wisent-java-wy--anons nil)
! EQ variable_initializer
! (cons (cons $1 $region) wisent-java-wy--anons)
;
variable_declarator_id
***************
*** 1475,1486 ****
;
class_instance_creation_expression
! : NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body_opt
! | NEW type_arguments class_or_interface_type LPAREN argument_list_opt RPAREN class_body_opt
| primary DOT NEW type_arguments_opt IDENTIFIER type_arguments_opt
LPAREN argument_list_opt RPAREN class_body_opt
| name DOT NEW type_arguments_opt IDENTIFIER type_arguments_opt
LPAREN argument_list_opt RPAREN class_body_opt
;
argument_list_opt
--- 1483,1520 ----
;
class_instance_creation_expression
! : NEW class_or_interface_type
! LPAREN argument_list_opt RPAREN class_body_opt
! (when $6
! (setq wisent-java-wy--anons
! (nconc wisent-java-wy--anons
! (EXPANDTAG
! (TYPE-TAG (concat $2 "$") "class" $6 nil))))
! )
! | NEW type_arguments class_or_interface_type
! LPAREN argument_list_opt RPAREN class_body_opt
! (when $7
! (setq wisent-java-wy--anons
! (nconc wisent-java-wy--anons
! (EXPANDTAG
! (TYPE-TAG (concat $3 "$") "class" $7 nil))))
! )
| primary DOT NEW type_arguments_opt IDENTIFIER type_arguments_opt
LPAREN argument_list_opt RPAREN class_body_opt
+ (when $10
+ (setq wisent-java-wy--anons
+ (nconc wisent-java-wy--anons
+ (EXPANDTAG
+ (TYPE-TAG (concat $5 "$") "class" $10 nil))))
+ )
| name DOT NEW type_arguments_opt IDENTIFIER type_arguments_opt
LPAREN argument_list_opt RPAREN class_body_opt
+ (when $10
+ (setq wisent-java-wy--anons
+ (nconc wisent-java-wy--anons
+ (EXPANDTAG
+ (TYPE-TAG (concat $5 "$") "class" $10 nil))))
+ )
;
argument_list_opt
|
| Thread | Author | Date |
|---|---|---|
| [CEDET-devel] Tags for anonymous java classes | <david.ponce@wa...> |