branch: externals/javaimp
commit 800129794a8def5ab062a354327e2990b84d2e8d
Author: Filipp Gunbin <[email protected]>
Commit: Filipp Gunbin <[email protected]>
Fix javaimp-end-of-defun to account for possible arrays in annotations
---
javaimp-parse.el | 11 +++++++----
javaimp.el | 36 +++++++++++++++++++++++-------------
2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/javaimp-parse.el b/javaimp-parse.el
index 17c3bbdec4..7c4afb93ca 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -192,7 +192,10 @@ skipping further backwards is done by the caller."
(if last-pos (goto-char last-pos))
(and (looking-at "\\_<")
;; Do not stop at vararg ellipsis like in
- ;; List<String>...
+ ;; "List<String>... ". FIXME Support other
+ ;; cases when ws is put before/after
+ ;; ellipsis, or no ws at all, which is valid
+ ;; Java syntax, although discouraged.
(not (string= (current-word t) "..."))))))))
(progn
(unless (eq last-skip t)
@@ -801,18 +804,18 @@ then no filtering is done."
(setq tmp (javaimp-scope-parent tmp)))))))
res))
-(defun javaimp-parse-get-enclosing-scope (&optional pred no-filter)
+(defun javaimp-parse-get-enclosing-scope (&optional pred no-filter-parents)
"Return copy of innermost enclosing scope at point. If PRED is
non-nil then the scope must satisfy it, otherwise the next outer
scope is tried.
Scope parents are filtered according to
-`javaimp-parse--scope-type-defun-p', but if NO-FILTER is non-nil
+`javaimp-parse--scope-type-defun-p', but if NO-FILTER-PARENTS is non-nil
then no filtering is done."
(save-excursion
(javaimp-parse--all-scopes))
(when-let* ((scope (javaimp-parse--enclosing-scope pred)))
- (javaimp-scope-copy scope (unless no-filter
+ (javaimp-scope-copy scope (unless no-filter-parents
#'javaimp-parse--scope-type-defun-p))))
(defun javaimp-parse-get-defun-decl-start (pos &optional bound)
diff --git a/javaimp.el b/javaimp.el
index c64d4275e0..6685133130 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -1108,19 +1108,29 @@ than BOUND. POS should not be in arglist or similar
list."
"Function to be used as `end-of-defun-function'."
;; This function is called after javaimp-beginning-of-defun, which
;; in the normal course will position the point before the
- ;; open-brace, so we can inspect property.
- (when-let* ((brace-pos
- (next-single-property-change (point) 'javaimp-parse-scope))
- (_ (get-text-property brace-pos 'javaimp-parse-scope))
- ;; When there're no siblings, javaimp-beginning-of-defun
- ;; moves to the parent start. In this case we should
- ;; stay inside the parent.
- (_ (eql (nth 1 (syntax-ppss))
- (save-excursion
- (nth 1 (syntax-ppss brace-pos))))))
- (ignore-errors
- (goto-char
- (scan-lists brace-pos 1 0)))))
+ ;; open-brace (for example, where javaimp--beg-of-defun-decl puts
+ ;; it), so we look for next property change. However we need to
+ ;; skip any array-init scopes which may occur within annotation
+ ;; values, like "@Annotation({"val1"})".
+ (let ((pos (point)))
+ (while-let ((_ pos)
+ (brace-pos (next-single-property-change pos
'javaimp-parse-scope))
+ (scope (get-text-property brace-pos 'javaimp-parse-scope))
+ (_ (eq (javaimp-scope-type scope) 'array-init)))
+ (setq pos (ignore-errors (scan-lists brace-pos 1 0))))
+ (when-let* ((_ pos)
+ (brace-pos (next-single-property-change pos
'javaimp-parse-scope))
+ (_ (get-text-property brace-pos 'javaimp-parse-scope))
+ ;; When there're no siblings,
+ ;; javaimp-beginning-of-defun moves to the parent
+ ;; start. In this case we should stay inside the
+ ;; parent.
+ (_ (eql (nth 1 (syntax-ppss))
+ (save-excursion
+ (nth 1 (syntax-ppss brace-pos))))))
+ (ignore-errors
+ (goto-char
+ (scan-lists brace-pos 1 0))))))
(defun javaimp--get-sibling-context ()
"Return list of the form (PARENT-START PREV-INDEX .