Skip to content

Commit

Permalink
More completion infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Espen Wiborg committed Mar 4, 2009
1 parent a0ceb33 commit 98829f5
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions src/main/lisp/malabar-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,12 @@ e.g. `malabar-choose'."
"")))

(defun malabar-get-superclass-at-point ()
(malabar-qualify-class-name-in-buffer
(or (car (semantic-tag-type-superclasses (malabar-get-class-tag-at-point)))
"Object")))
(malabar-qualify-class-name-in-buffer (malabar-get-superclass (malabar-get-class-tag-at-point))))

(defun malabar-get-superclass (class-tag)
(or (car (semantic-tag-type-superclasses class-tag))
"Object"))

(defun malabar-override-method-make-choose-spec (method-spec)
(cons (malabar-create-simplified-method-signature method-spec)
method-spec))
Expand Down Expand Up @@ -1012,4 +1014,50 @@ accessible constructors."
(t
'unknown)))

(defun malabar--resolve-type-of (exp-and-kind &optional relative-type)
(let ((expression (car exp-and-kind))
(kind (cdr exp-and-kind)))
(or (case kind ;; Some expression kinds have statically determinable types
(string-literal "java.lang.String")
(constructor-call
(string-match "^new \\([A-Za-z_][^(]*\\)" expression)
(match-string 1 expression))
((array-reference unknown)
(error "Cannot (yet) resolve type of %s (%s)" expression kind)))
(cond (relative-type
;; TODO: Resolve exp-and-kind in relative-type
nil)
;; Resolve exp-and-kind in class at point
(t
(malabar--resolve-type-of-locally exp kind (malabar-get-class-tag-at-point)))))))

(defun malabar--find-tag-named (name tag-list)
(find name tag-list
:key #'semantic-tag-name
:test #'equal))

(defun malabar--find-member-named (name type-tag)
(malabar--find-tag-named name (semantic-tag-type-members type-tag)))

(defun malabar--resolve-type-of-locally (exp kind class-tag)
(save-excursion
(let* ((expression (if (eq kind 'function-call)
(progn (string-match "^[^(]+" exp)
(match-string 0 exp))
exp))
(local-type (let ((local-variable (and (eq kind 'variable)
(malabar--find-tag-named expression (semantic-get-local-variables))))
(member (malabar--find-member-named expression class-tag)))
(semantic-tag-type (or local-variable
member)))))
(or local-type
(malabar--resolve-type-of (cons exp kind) (malabar-get-superclass class-tag))
(some (lambda (i)
(malabar--resolve-type-of (cons exp kind) i))
(semantic-tag-type-interfaces class-tag))
(when (and (not (member "static" (semantic-tag-modifiers class-tag)))
(not (semantic-up-context (semantic-tag-start class-tag) 'type)))
(malabar--resolve-type-of-locally exp kind (semantic-current-tag-of-class 'type)))
(error "Failed to resolve type of %s (%s)" exp kind)))))

(provide 'malabar-mode)

0 comments on commit 98829f5

Please sign in to comment.