Function: srecode-insert-getset

srecode-insert-getset is an autoloaded, interactive and byte-compiled function defined in getset.el.gz.

Signature

(srecode-insert-getset &optional CLASS-IN FIELD-IN)

Documentation

Insert get/set methods for the current class.

CLASS-IN is the semantic tag of the class to update. FIELD-IN is the semantic tag, or string name, of the field to add. If you do not specify CLASS-IN or FIELD-IN then a class and field will be derived.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/srecode/getset.el.gz
;;;###autoload
(defun srecode-insert-getset (&optional class-in field-in)
  "Insert get/set methods for the current class.
CLASS-IN is the semantic tag of the class to update.
FIELD-IN is the semantic tag, or string name, of the field to add.
If you do not specify CLASS-IN or FIELD-IN then a class and field
will be derived."
  (interactive)

  (srecode-load-tables-for-mode major-mode)
  (srecode-load-tables-for-mode major-mode 'getset)

  (if (not (srecode-table))
      (error "No template table found for mode %s" major-mode))

  (if (not (srecode-template-get-table (srecode-table)
				       "getset-in-class"
				       "declaration"
				       'getset))
      (error "No templates for inserting get/set"))

  ;; Step 1: Try to derive the tag for the class we will use
  (semantic-fetch-tags)
  (let* ((class (or class-in (srecode-auto-choose-class (point))))
	 (tagstart (when class (semantic-tag-start class)))
	 (inclass (eq (semantic-current-tag-of-class 'type) class))
	 (field nil)
	 )

    (when (not class)
      (error "Move point to a class and try again"))

    ;; Step 2: Select a name for the field we will use.
    (when field-in
      (setq field field-in))

    (when (and inclass (not field))
      (setq field (srecode-auto-choose-field (point))))

    (when (not field)
      (setq field (srecode-query-for-field class)))

    ;; Step 3: Insert a new field if needed
    (when (stringp field)

      (goto-char (point))
      (srecode-position-new-field class inclass)

      (let* ((dict (srecode-create-dictionary))
	     (temp (srecode-template-get-table (srecode-table)
					       "getset-field"
					       "declaration"
					       'getset))
	     )
	(when (not temp)
	  (error "Getset templates for %s not loaded!" major-mode))
	(srecode-resolve-arguments temp dict)
	(srecode-dictionary-set-value dict "NAME" field)
	(when srecode-insert-getset-fully-automatic-flag
	  (srecode-dictionary-set-value dict "TYPE" "int"))
	(srecode-insert-fcn temp dict)

	(semantic-fetch-tags)
	(save-excursion
	  (goto-char tagstart)
	  ;; Refresh our class tag.
	  (setq class (srecode-auto-choose-class (point)))
	  )

	(let ((tmptag (semantic-deep-find-tags-by-name-regexp
		       field (current-buffer))))
	  (setq tmptag (semantic-find-tags-by-class 'variable tmptag))

	  (if tmptag
	      (setq field (car tmptag))
	    (error "Could not find new field %s" field)))
	)

      ;; Step 3.5: Insert an initializer if needed.
      ;; ...


      ;; Set up for the rest.
      )

    (if (not (semantic-tag-p field))
	(error "Must specify field for get/set.  (parts may not be impl'd yet.)"))

    ;; Set 4: Position for insertion of methods
    (srecode-position-new-methods class field)

    ;; Step 5: Insert the get/set methods
    (if (not (eq (semantic-current-tag) class))
	;; We are positioned on top of something else.
	;; insert a /n
	(insert "\n"))

    (let* ((dict (srecode-create-dictionary))
	   (srecode-semantic-selected-tag field)
	   (temp (srecode-template-get-table (srecode-table)
					     "getset-in-class"
					     "declaration"
					     'getset))
	   )
      (if (not temp)
	  (error "Getset templates for %s not loaded!" major-mode))
      (srecode-resolve-arguments temp dict)
      (srecode-dictionary-set-value dict "GROUPNAME"
				    (concat (semantic-tag-name field)
					    " Accessors"))
      (srecode-dictionary-set-value dict "NICENAME"
				    (srecode-strip-fieldname
				     (semantic-tag-name field)))
      (srecode-insert-fcn temp dict)
      )))