[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/javaimp-wip af69f40efc: *** empty log message ***
From: |
Filipp Gunbin |
Subject: |
[elpa] scratch/javaimp-wip af69f40efc: *** empty log message *** |
Date: |
Mon, 18 Apr 2022 16:51:57 -0400 (EDT) |
branch: scratch/javaimp-wip
commit af69f40efc73d7c8dbe5739786e085bf161228e1
Author: Filipp Gunbin <fgunbin@okko.tv>
Commit: Filipp Gunbin <fgunbin@okko.tv>
*** empty log message ***
---
javaimp-parse.el | 74 +++++++++++++++++++++++++++++++++-----------------------
javaimp-tests.el | 13 +++++-----
javaimp-util.el | 19 ++++++++++-----
javaimp.el | 16 +++++++-----
4 files changed, 74 insertions(+), 48 deletions(-)
diff --git a/javaimp-parse.el b/javaimp-parse.el
index fb1d6bc6b7..4ac9df2aaf 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -215,9 +215,9 @@ is unchanged."
(save-excursion
(funcall parser arg))))
'(javaimp--parse-scope-array
- ;; anonymous-class should be before method/stmt because it
+ ;; anon-class should be before method/stmt because it
;; looks similar, but with "new" in front
- javaimp--parse-scope-anonymous-class
+ javaimp--parse-scope-anon-class
javaimp--parse-scope-class
javaimp--parse-scope-simple-stmt
javaimp--parse-scope-method-or-stmt
@@ -270,8 +270,8 @@ brace.")
(- (point) 2))
:open-brace brace-pos)))
-(defun javaimp--parse-scope-anonymous-class (brace-pos)
- "Attempts to parse 'anonymous-class' scope."
+(defun javaimp--parse-scope-anon-class (brace-pos)
+ "Attempts to parse 'anon-class' scope."
;; skip arg-list and ws
(when (and (progn
(javaimp--parse-skip-back-until)
@@ -285,8 +285,10 @@ brace.")
(setq start (match-beginning 0)
arglist (javaimp--parse-arglist (match-end 0) end t))
(when (= (length arglist) 1)
- (make-javaimp-scope :type 'anonymous-class
- :name (javaimp--parse-substr-before-< (caar
arglist))
+ (make-javaimp-scope :type 'anon-class
+ :name
+ (concat "<anon>"
+ (javaimp--parse-substr-before-< (caar
arglist)))
:start start
:open-brace brace-pos))))))
@@ -345,14 +347,19 @@ brace.")
:open-brace brace-pos)))
(defun javaimp--parse-scopes (count)
- "Attempts to parse COUNT enclosing scopes at point. Returns most
-nested one, with its parents sets accordingly. If COUNT is nil
-then goes all the way up. Examines and sets property
-'javaimp-parse-scope' at each scope's open brace. If neither of
-functions in `javaimp--parse-scope-hook' return non-nil then the
-property value is set to the symbol `unknown'. Additionally, if
-a scope is recognized, but any of its parents is 'unknown', then
-it's set to 'unknown' too."
+ "Attempts to parse COUNT enclosing scopes at point.
+Returns most nested one, with its parents sets accordingly. If
+COUNT is nil then goes all the way up.
+
+Examines and sets property 'javaimp-parse-scope' at each scope's
+open brace. If neither of functions in
+`javaimp--parse-scope-hook' return non-nil then the property
+value is set to the symbol `unknown'. Additionally, if a scope
+is recognized, but any of its parents is 'unknown', then it's set
+to 'unknown' too.
+
+If point is inside of any comment/string then this function does
+nothing."
(let ((state (syntax-ppss))
res)
(unless (syntax-ppss-context state)
@@ -364,6 +371,8 @@ it's set to 'unknown' too."
(when (= (char-after) ?{)
(let ((scope (get-text-property (point) 'javaimp-parse-scope)))
(unless scope
+
+ ;; TODO
(setq scope (or (run-hook-with-args-until-success
'javaimp--parse-scope-hook (point))
'unknown))
@@ -374,10 +383,10 @@ it's set to 'unknown' too."
(javaimp-scope-start scope))
(goto-char (javaimp-scope-start scope)))))
(setq state (syntax-ppss))))
- ;; FIXME don't do this every time
(let (parent reset-tail)
(while res
(if reset-tail
+ ;; overwrite property value with `unknown'
(when (javaimp-scope-p (car res))
(let ((pos (javaimp-scope-open-brace (car res))))
(put-text-property pos (1+ pos) 'javaimp-parse-scope
'unknown)))
@@ -395,7 +404,7 @@ it's set to 'unknown' too."
"Parses all scopes in this buffer which are after
`javaimp--parse-dirty-pos', if it points anywhere. Makes it
point nowhere when done."
- (unless javaimp--parse-dirty-pos
+ (unless javaimp--parse-dirty-pos ;init on first use
(setq javaimp--parse-dirty-pos (point-min-marker))
(javaimp--parse-setup-buffer))
(when (marker-position javaimp--parse-dirty-pos)
@@ -421,18 +430,13 @@ point nowhere when done."
(add-hook 'after-change-functions #'javaimp--parse-update-dirty-pos))
(defun javaimp--parse-enclosing-scope (&optional pred)
- "Return innermost enclosing scope matching PRED. This function
-is intended to use already set properties."
- (when (or (not javaimp--parse-dirty-pos)
- (marker-position javaimp--parse-dirty-pos))
- (error "Call javaimp--parse-all-scopes first"))
+ "Return innermost enclosing scope matching PRED."
(with-syntax-table javaimp-syntax-table
(let ((state (syntax-ppss)))
;; Move out of any comment/string
(when (nth 8 state)
(goto-char (nth 8 state))
(setq state (syntax-ppss)))
- ;; Go up until we get something
(catch 'found
(while t
(let ((res (save-excursion
@@ -441,6 +445,7 @@ is intended to use already set properties."
(or (null pred)
(funcall pred res)))
(throw 'found res))
+ ;; Go up until we get something
(if (nth 1 state)
(progn
(goto-char (nth 1 state))
@@ -528,14 +533,21 @@ either of symbols `normal' or 'static'."
(cons (and start-pos end-pos (cons start-pos end-pos))
class-alist)))
-(defun javaimp--parse-get-all-scopes (&optional pred parent-pred)
- "Return all scopes in the current buffer, optionally filtering
-them with PRED, and their parents with PARENT-PRED. Neither of
-them should move point."
+(defun javaimp--parse-get-all-scopes (&optional beg end pred parent-pred)
+ "Return all scopes in the current buffer between positions BEG
+and END, both exclusive, optionally filtering them with PRED, and
+their parents with PARENT-PRED. Neither of PRED or PARENT-PRED
+should move point. Note that parents may be outside of region
+given by BEG and END. BEG is the LIMIT argument to
+`previous-single-property-change', END defaults to end of
+accessible portion of the buffer."
(javaimp--parse-all-scopes)
- (let ((pos (point-max))
+ (let ((pos (or end (point-max)))
scope res)
- (while (setq pos (previous-single-property-change pos
'javaimp-parse-scope))
+ (while (and (setq pos (previous-single-property-change
+ pos 'javaimp-parse-scope nil beg))
+ (or (not beg)
+ (/= pos beg)))
(setq scope (get-text-property pos 'javaimp-parse-scope))
(when (and (javaimp-scope-p scope)
(or (null pred)
@@ -563,12 +575,14 @@ it with PRED, and its parents with PARENT-PRED."
(defun javaimp--parse-get-interface-abstract-methods ()
(let ((interfaces (javaimp--parse-get-all-scopes
- (lambda (scope)
- (javaimp-test-scope-type scope
+ nil nil
+ (lambda (s)
+ (javaimp-test-scope-type s
'(interface) javaimp--classlike-scope-types)))))
(seq-mapcat #'javaimp--parse-interface-abstract-methods
interfaces)))
+
(defmacro javaimp--parse-without-hook (&rest body)
"Execute BODY, temporarily removing
`javaimp--parse-update-dirty-pos' from `after-change-functions'
diff --git a/javaimp-tests.el b/javaimp-tests.el
index 33b46a68a7..e7dc31314b 100644
--- a/javaimp-tests.el
+++ b/javaimp-tests.el
@@ -102,18 +102,18 @@ extends Bar<? extends Baz<? extends Baz2>> {"
enum "Foo")
))
-(ert-deftest javaimp-test--parse-scope-anonymous-class ()
- (javaimp-test--single-parser #'javaimp--parse-scope-anonymous-class
+(ert-deftest javaimp-test--parse-scope-anon-class ()
+ (javaimp-test--single-parser #'javaimp--parse-scope-anon-class
'(" = new Object < Class1 , Class2 > ( 1 + 1 , baz ) {"
- anonymous-class "Object")
+ anon-class "Object")
`(,(subst-char-in-string
? ?\n
" = new Object < Class1 , Class2 > ( 1 + 1 , baz ) {")
- anonymous-class "Object")
+ anon-class "Object")
'(" = (obj.getField()).new Object<Class1, Class2>(1, baz) {"
- anonymous-class "Object")
+ anon-class "Object")
'(" = obj.new Object<>(1, baz) {"
- anonymous-class "Object")
+ anon-class "Object")
))
(ert-deftest javaimp-test--parse-scope-method-or-stmt ()
@@ -230,6 +230,7 @@ import static some_class.fun_2; // comment
(defun javaimp-test--check-named-scopes ()
(let* ((scopes (javaimp--parse-get-all-scopes
+ nil nil
(lambda (s)
(memq (javaimp-scope-type s) '(class interface enum
method)))
(lambda (s)
diff --git a/javaimp-util.el b/javaimp-util.el
index 3faa8fad57..7105323768 100644
--- a/javaimp-util.el
+++ b/javaimp-util.el
@@ -32,7 +32,7 @@
(defconst javaimp--all-scope-types
(append
- '(anonymous-class
+ '(anon-class
array
method
simple-statement
@@ -41,7 +41,7 @@
javaimp--classlike-scope-types))
(defconst javaimp--show-scopes-scope-type-abbrevs
- '((anonymous-class . "ac")
+ '((anon-class . "ac")
(statement . "st")
(simple-statement . "ss")
(array . "ar")
@@ -153,12 +153,19 @@ left."
(setq res (memq (javaimp-scope-type scope) parent-types)))
res))
-(defun javaimp--defun-scope-pred (&optional only-classes)
+(defun javaimp--defun-scope-pred (&optional additional)
+ "Return predicate which matches scopes in
+`javaimp--classlike-scope-types'. ADDITIONAL is a list of scope
+types. If it includes `method', then also method leafs are
+included. If it includes `anon-class', then also leafs and
+parents may be anonymous classes."
(let ((leaf-types (append javaimp--classlike-scope-types
- (unless only-classes '(method)))))
+ (when (memq 'method additional) '(method))
+ (when (memq 'anon-class additional)
'(anon-class))))
+ (parent-types (append javaimp--classlike-scope-types
+ (when (memq 'anon-class additional)
'(anon-class)))))
(lambda (s)
- (javaimp-test-scope-type s
- leaf-types javaimp--classlike-scope-types))))
+ (javaimp-test-scope-type s leaf-types parent-types))))
(defun javaimp--scope-same-parent-pred (parent)
(if parent
diff --git a/javaimp.el b/javaimp.el
index 5ccc37f847..5bf75317d5 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -571,9 +571,9 @@ If there's no such directive, then the last resort is just
(defun javaimp--get-buffer-classes ()
"Return fully-qualified names of all class-like scopes in the
-current buffer."
+current buffer. Anonymous classes are not included."
(let ((package (javaimp--parse-get-package))
- (scopes (javaimp--parse-get-all-scopes (javaimp--defun-scope-pred t))))
+ (scopes (javaimp--parse-get-all-scopes nil nil
(javaimp--defun-scope-pred))))
(mapcar (lambda (class)
(if package
(concat package "." class)
@@ -718,7 +718,7 @@ in a major mode hook."
(defun javaimp-imenu--get-forest ()
(let* ((defun-scopes
- (javaimp--parse-get-all-scopes (javaimp--defun-scope-pred)))
+ (javaimp--parse-get-all-scopes nil nil (javaimp--defun-scope-pred
'(method))))
(methods (seq-filter
(lambda (scope)
(eq (javaimp-scope-type scope) 'method))
@@ -811,12 +811,13 @@ opening brace."
(defun javaimp-show-scopes ()
"Show scopes in *javaimp-scopes* buffer."
- (interactive "P")
+ (interactive)
(let ((scopes
(save-excursion
(save-restriction
(widen)
- (javaimp--parse-get-all-scopes (javaimp--defun-scope-pred)))))
+ (javaimp--parse-get-all-scopes
+ nil nil (javaimp--defun-scope-pred '(method anon-class))))))
(source-buf (current-buffer))
(source-default-dir default-directory)
(buf (get-buffer-create "*javaimp-scopes*")))
@@ -913,7 +914,7 @@ nil."
(save-restriction
(widen)
(let* ((pos (point))
- (defun-pred (javaimp--defun-scope-pred))
+ (defun-pred (javaimp--defun-scope-pred '(method anon-class)))
(enc (javaimp--parse-get-enclosing-scope defun-pred))
(sibling-pred
(if (and enc (eq (javaimp-scope-type enc) 'method))
@@ -926,6 +927,9 @@ nil."
;; whose parent is enc.
(javaimp--scope-same-parent-pred enc)))
(siblings (javaimp--parse-get-all-scopes
+ (javaimp-scope-open-brace enc)
+ (ignore-errors
+ (1- (scan-lists (javaimp-scope-open-brace enc) 1 0)))
(lambda (s)
(and (funcall defun-pred s)
(funcall sibling-pred s)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] scratch/javaimp-wip af69f40efc: *** empty log message ***,
Filipp Gunbin <=