emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phpinspect 2aac7a273e: Support @method annotations for


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 2aac7a273e: Support @method annotations for static methods
Date: Fri, 2 Aug 2024 06:58:54 -0400 (EDT)

branch: externals/phpinspect
commit 2aac7a273ea858961e9a702e78e5c1567585b908
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Support @method annotations for static methods
---
 phpinspect-index.el                                | 59 ++++++++++++++--------
 phpinspect-parser.el                               |  2 +-
 phpinspect-serialize.el                            |  2 +-
 test/fixtures/Array.eld                            |  2 +-
 test/fixtures/Block.eld                            |  2 +-
 test/fixtures/Functions.eld                        |  2 +-
 test/fixtures/IncompleteClass.eld                  |  2 +-
 test/fixtures/IncompleteClassBlockedNamespace.eld  |  2 +-
 .../fixtures/IncompleteClassMultipleNamespaces.eld |  2 +-
 test/fixtures/IndexClass1-indexed.eld              |  2 +-
 test/fixtures/IndexClass1.eld                      |  2 +-
 test/fixtures/IndexClass2-indexed.eld              |  2 +-
 test/fixtures/IndexClass2.eld                      |  2 +-
 test/fixtures/NamespacedClass.eld                  |  2 +-
 test/fixtures/NamespacedFunctions.eld              |  2 +-
 test/fixtures/ShortFunction.eld                    |  2 +-
 test/fixtures/SmallNamespacedClass.eld             |  2 +-
 test/fixtures/TwoShortFunctions.eld                |  2 +-
 test/fixtures/Variable.eld                         |  2 +-
 test/fixtures/Word.eld                             |  2 +-
 test/test-index.el                                 | 43 ++++++++++++++++
 21 files changed, 100 insertions(+), 40 deletions(-)

diff --git a/phpinspect-index.el b/phpinspect-index.el
index 6b8aa03693..6c999d0fed 100644
--- a/phpinspect-index.el
+++ b/phpinspect-index.el
@@ -190,33 +190,43 @@ function (think \"new\" statements, return types etc.)."
 (defun phpinspect-doc-block-p (token)
   (phpinspect-token-type-p token :doc-block))
 
-
 (defsubst phpinspect--index-method-annotations (type-resolver comment)
   (let ((annotations (seq-filter #'phpinspect-method-annotation-p comment))
+        (static-methods)
         (methods))
     (dolist (annotation annotations)
-      (let ((return-type) (name) (arg-list))
-        (when (> (length annotation) 2)
-          (cond ((and (phpinspect-word-p (nth 1 annotation))
-                      (phpinspect-word-p (nth 2 annotation))
-                      (phpinspect-list-p (nth 3 annotation)))
-                 (setq return-type (cadr (nth 1 annotation)))
-                 (setq name (cadr (nth 2 annotation)))
-                 (setq arg-list (nth 3 annotation)))
-                ((and (phpinspect-word-p (nth 1 annotation))
-                      (phpinspect-list-p (nth 2 annotation)))
-                 (setq return-type "void")
-                 (setq name (cadr (nth 1 annotation)))
-                 (setq arg-list (nth 2 annotation))))
-
-          (when name
+      (let ((return-type) (name) (arg-list) (static))
+        ;; Annotation is static
+        (when (phpinspect--match-sequence (take 2 annotation)
+                :m :method-annotation :m '(:word "static"))
+          (setcdr annotation (cddr annotation))
+          (setq static t))
+
+        (cond
+         ((phpinspect--match-sequence annotation
+            :m :method-annotation
+            :f #'phpinspect-word-p
+            :f #'phpinspect-word-p
+            :f #'phpinspect-list-p)
+          (setq return-type (cadr (nth 1 annotation)))
+          (setq name (cadr (nth 2 annotation)))
+          (setq arg-list (nth 3 annotation)))
+         ((phpinspect--match-sequence annotation
+            :m :method-annotation
+            :f #'phpinspect-word-p
+            :f #'phpinspect-list-p)
+          (setq return-type "void")
+          (setq name (cadr (nth 1 annotation)))
+          (setq arg-list (nth 2 annotation))))
+
+        (when name
             (push (phpinspect--make-function
                    :scope '(:public)
                    :name name
                    :return-type (funcall type-resolver (phpinspect--make-type 
:name return-type))
                    :arguments (phpinspect--index-function-arg-list 
type-resolver arg-list))
-                  methods)))))
-    methods))
+                  (if static static-methods methods)))))
+    (list static-methods methods)))
 
 (defun phpinspect--index-class (imports type-resolver location-resolver class 
&optional doc-block)
   "Create an alist with relevant attributes of a parsed class."
@@ -317,7 +327,11 @@ function (think \"new\" statements, return types etc.)."
     ;; Dirty hack that assumes the constructor argument names to be the same 
as the object
     ;; attributes' names.
     ;;;
-    ;; TODO: actually check the types of the variables assigned to object 
attributes
+    ;; TODO: actually check the types of the variables assigned to object 
properties
+    ;;
+    ;; Note: The indexing code in phpinspect-buffer does check the variable
+    ;; types which are actually assigned to object properties for classes 
opened
+    ;; in buffers.
     (let* ((constructor-sym (phpinspect-intern-name "__construct"))
            (constructor (seq-find (lambda (method)
                                     (eq (phpinspect--function-name-symbol 
method)
@@ -339,8 +353,11 @@ function (think \"new\" statements, return types etc.)."
 
     ;; Add method annotations to methods
     (when doc-block
-      (setq methods
-            (nconc methods (phpinspect--index-method-annotations type-resolver 
doc-block))))
+      (let ((result-tuple (phpinspect--index-method-annotations type-resolver 
doc-block)))
+        (setq static-methods
+              (nconc static-methods (car result-tuple)))
+        (setq methods
+              (nconc methods (cadr result-tuple)))))
 
     `(,class-name .
                   (phpinspect--indexed-class
diff --git a/phpinspect-parser.el b/phpinspect-parser.el
index beb32f721f..61f41f69fc 100644
--- a/phpinspect-parser.el
+++ b/phpinspect-parser.el
@@ -483,7 +483,7 @@ nature like argument lists"
                        (phpinspect--parse-annotation-parameters 2)))
               ((string= annotation-name "method")
                (cons :method-annotation
-                     (phpinspect--parse-annotation-parameters 3)))
+                     (phpinspect--parse-annotation-parameters 4)))
               (t
                (list :annotation annotation-name))))
     (list :annotation nil)))
diff --git a/phpinspect-serialize.el b/phpinspect-serialize.el
index 4c11e840c8..79ba1e5611 100644
--- a/phpinspect-serialize.el
+++ b/phpinspect-serialize.el
@@ -107,7 +107,7 @@
 
 (defun phpinspect--serialize-import (import)
   `(cons
-    (phpinspect-intern-name ,(symbol-name (car import)))
+    (phpinspect-intern-name ,(phpinspect-name-string (car import)))
     ,(phpinspect--serialize-type (cdr import))))
 
 (provide 'phpinspect-serialize)
diff --git a/test/fixtures/Array.eld b/test/fixtures/Array.eld
index 5f4da96e33..80b28e2ede 100644
--- a/test/fixtures/Array.eld
+++ b/test/fixtures/Array.eld
@@ -1 +1 @@
-(:root (:array (:string "item1") (:comma ",") (:string "item2") (:comma ",") 
(:string "item3")) (:terminator ";") (:array (:string "item1") (:fat-arrow 
"=>") (:string "item2") (:comma ",") (:string "item3") (:fat-arrow "=>") 
(:string "item4")))
\ No newline at end of file
+(:root (:array (:string "item1") (:comma ",") (:string "item2") (:comma ",") 
(:string "item3")) (:terminator ";") (:array (:string "item1") (:fat-arrow 
"=>") (:string "item2") (:comma ",") (:string "item3") (:fat-arrow "=>") 
(:string "item4")))
diff --git a/test/fixtures/Block.eld b/test/fixtures/Block.eld
index cbeaf11352..427b1f1928 100644
--- a/test/fixtures/Block.eld
+++ b/test/fixtures/Block.eld
@@ -1 +1 @@
-(:root (:block (:word "return") (:word "new") (:word "Response") (:list 
(:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word 
"render")) (:list (:string "domain/manage.html.twig") (:comma ",") (:array 
(:string "domain") (:fat-arrow "=>") (:variable "this") (:object-attrib (:word 
"repo")) (:object-attrib (:word "find")) (:list (:variable "name")) (:comma 
",") (:string "users") (:fat-arrow "=>") (:variable "this") (:object-attrib 
(:word "user_repo")) (:object-attrib (:w [...]
\ No newline at end of file
+(:root (:block (:word "return") (:word "new") (:word "Response") (:list 
(:variable "this") (:object-attrib (:word "twig")) (:object-attrib (:word 
"render")) (:list (:string "domain/manage.html.twig") (:comma ",") (:array 
(:string "domain") (:fat-arrow "=>") (:variable "this") (:object-attrib (:word 
"repo")) (:object-attrib (:word "find")) (:list (:variable "name")) (:comma 
",") (:string "users") (:fat-arrow "=>") (:variable "this") (:object-attrib 
(:word "user_repo")) (:object-attrib (:w [...]
diff --git a/test/fixtures/Functions.eld b/test/fixtures/Functions.eld
index 3eb42c5942..d8ca777249 100644
--- a/test/fixtures/Functions.eld
+++ b/test/fixtures/Functions.eld
@@ -1 +1 @@
-(:root (:function (:declaration (:word "function") (:word 
"MergeTwoArraysAndSomeOtherStuff") (:list (:word "array") (:variable "array1") 
(:comma ",") (:variable "untyped_variable")) (:word "Response")) (:block 
(:variable "merged") (:assignment "=") (:word "array_merge") (:list (:variable 
"array_1") (:comma ",") (:variable "untyped_variable")) (:terminator ";") 
(:variable "mapped") (:assignment "=") (:word "arrap_map") (:list (:function 
(:declaration (:word "function") (:list (:variable " [...]
\ No newline at end of file
+(:root (:function (:declaration (:word "function") (:word 
"MergeTwoArraysAndSomeOtherStuff") (:list (:word "array") (:variable "array1") 
(:comma ",") (:variable "untyped_variable")) (:word "Response")) (:block 
(:variable "merged") (:assignment "=") (:word "array_merge") (:list (:variable 
"array_1") (:comma ",") (:variable "untyped_variable")) (:terminator ";") 
(:variable "mapped") (:assignment "=") (:word "arrap_map") (:list (:function 
(:declaration (:word "function") (:list (:variable " [...]
diff --git a/test/fixtures/IncompleteClass.eld 
b/test/fixtures/IncompleteClass.eld
index 19627636d9..e4e7d734cc 100644
--- a/test/fixtures/IncompleteClass.eld
+++ b/test/fixtures/IncompleteClass.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use 
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use 
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (: [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use 
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use 
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (: [...]
diff --git a/test/fixtures/IncompleteClassBlockedNamespace.eld 
b/test/fixtures/IncompleteClassBlockedNamespace.eld
index 96c2489efd..a599875aa2 100644
--- a/test/fixtures/IncompleteClassBlockedNamespace.eld
+++ b/test/fixtures/IncompleteClassBlockedNamespace.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block 
(:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) 
(:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") ( [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:incomplete-block 
(:use (:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) 
(:use (:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") ( [...]
diff --git a/test/fixtures/IncompleteClassMultipleNamespaces.eld 
b/test/fixtures/IncompleteClassMultipleNamespaces.eld
index 77449f51c5..a674fa85bf 100644
--- a/test/fixtures/IncompleteClassMultipleNamespaces.eld
+++ b/test/fixtures/IncompleteClassMultipleNamespaces.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "Circus\\Artist") (:block (:use (:word 
"Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word 
"App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (:terminator  [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "Circus\\Artist") (:block (:use (:word 
"Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use (:word 
"App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (:terminator  [...]
diff --git a/test/fixtures/IndexClass1-indexed.eld 
b/test/fixtures/IndexClass1-indexed.eld
index 8f4f9e83d5..532c59bea0 100644
--- a/test/fixtures/IndexClass1-indexed.eld
+++ b/test/fixtures/IndexClass1-indexed.eld
@@ -1 +1 @@
-`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons 
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil 
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t) 
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" 
:collection nil :contains nil :fully-qualified t)) (declaration \, 
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons 
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
\ No newline at end of file
+`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons 
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil 
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t) 
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" 
:collection nil :contains nil :fully-qualified t)) (declaration \, 
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons 
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
diff --git a/test/fixtures/IndexClass1.eld b/test/fixtures/IndexClass1.eld
index b9fdeb1e44..8ccf155b4c 100644
--- a/test/fixtures/IndexClass1.eld
+++ b/test/fixtures/IndexClass1.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use 
(:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) 
(:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") 
(:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator 
";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private 
(:class-variable "user") (: [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use 
(:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) 
(:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") 
(:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator 
";")) (:doc-block (:var-annotation (:word "App\\\\Entity\\\\User"))) (:private 
(:class-variable "user") (: [...]
diff --git a/test/fixtures/IndexClass2-indexed.eld 
b/test/fixtures/IndexClass2-indexed.eld
index 4edc18610c..e557b5c1e9 100644
--- a/test/fixtures/IndexClass2-indexed.eld
+++ b/test/fixtures/IndexClass2-indexed.eld
@@ -1 +1 @@
-`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons 
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil 
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t) 
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" 
:collection nil :contains nil :fully-qualified t)) (declaration \, 
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons 
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
\ No newline at end of file
+`(phpinspect--root-index (imports \, (list)) (classes \, (list (cons 
(phpinspect--make-type :name "\\App\\Entity\\AuthToken" :collection nil 
:contains nil :fully-qualified t) `(phpinspect--indexed-class (complete \, t) 
(class-name \, (phpinspect--make-type :name "\\App\\Entity\\AuthToken" 
:collection nil :contains nil :fully-qualified t)) (declaration \, 
'(:declaration (:word "class") (:word "AuthToken"))) (imports \, (list (cons 
(phpinspect-intern-name "ORM") (phpinspect--make-type :nam [...]
diff --git a/test/fixtures/IndexClass2.eld b/test/fixtures/IndexClass2.eld
index 85057367c8..691272b1e9 100644
--- a/test/fixtures/IndexClass2.eld
+++ b/test/fixtures/IndexClass2.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use 
(:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) 
(:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") 
(:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator 
";")) (:private (:class-variable "extra") (:terminator ";")) (:doc-block 
(:var-annotation (:word "App\\\\E [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Entity") (:terminator ";") (:use 
(:word "Doctrine\\ORM\\Mapping") (:word "as") (:word "ORM") (:terminator ";")) 
(:doc-block (:annotation "ORM\\Entity")) (:class (:declaration (:word "class") 
(:word "AuthToken")) (:block (:private (:class-variable "token") (:terminator 
";")) (:private (:class-variable "extra") (:terminator ";")) (:doc-block 
(:var-annotation (:word "App\\\\E [...]
diff --git a/test/fixtures/NamespacedClass.eld 
b/test/fixtures/NamespacedClass.eld
index d8b6d51e24..fc41a5e4e1 100644
--- a/test/fixtures/NamespacedClass.eld
+++ b/test/fixtures/NamespacedClass.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use 
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use 
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (: [...]
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") (:use 
(:word "Symfony\\Component\\HttpFoundation\\Response") (:terminator ";")) (:use 
(:word "App\\Entity\\Address") (:terminator ";")) (:use (:word 
"Symfony\\Component\\HttpFoundation\\RedirectResponse") (:terminator ";")) 
(:use (:word "App\\Repository\\AddressRepository") (:terminator ";")) (:use 
(:word "App\\Repository\\UserRepository") (: [...]
diff --git a/test/fixtures/NamespacedFunctions.eld 
b/test/fixtures/NamespacedFunctions.eld
index e2e65c2000..7a627e9581 100644
--- a/test/fixtures/NamespacedFunctions.eld
+++ b/test/fixtures/NamespacedFunctions.eld
@@ -1 +1 @@
-(:root (:namespace (:word "App\\Functions") (:terminator ";") (:function 
(:declaration (:word "function") (:word "MergeTwoArraysAndSomeOtherStuff") 
(:list (:word "array") (:variable "array1") (:comma ",") (:variable 
"untyped_variable")) (:word "Response")) (:block (:variable "merged") 
(:assignment "=") (:word "array_merge") (:list (:variable "array_1") (:comma 
",") (:variable "untyped_variable")) (:terminator ";") (:variable "mapped") 
(:assignment "=") (:word "arrap_map") (:list (:functi [...]
\ No newline at end of file
+(:root (:namespace (:word "App\\Functions") (:terminator ";") (:function 
(:declaration (:word "function") (:word "MergeTwoArraysAndSomeOtherStuff") 
(:list (:word "array") (:variable "array1") (:comma ",") (:variable 
"untyped_variable")) (:word "Response")) (:block (:variable "merged") 
(:assignment "=") (:word "array_merge") (:list (:variable "array_1") (:comma 
",") (:variable "untyped_variable")) (:terminator ";") (:variable "mapped") 
(:assignment "=") (:word "arrap_map") (:list (:functi [...]
diff --git a/test/fixtures/ShortFunction.eld b/test/fixtures/ShortFunction.eld
index 201b9c6770..48468fa14f 100644
--- a/test/fixtures/ShortFunction.eld
+++ b/test/fixtures/ShortFunction.eld
@@ -1 +1 @@
-(:root (:function (:declaration (:word "function") (:word "work") (:list)) 
(:block (:word "return") (:variable "variable") (:terminator ";"))))
\ No newline at end of file
+(:root (:function (:declaration (:word "function") (:word "work") (:list)) 
(:block (:word "return") (:variable "variable") (:terminator ";"))))
diff --git a/test/fixtures/SmallNamespacedClass.eld 
b/test/fixtures/SmallNamespacedClass.eld
index e7c4107ef4..39624fc325 100644
--- a/test/fixtures/SmallNamespacedClass.eld
+++ b/test/fixtures/SmallNamespacedClass.eld
@@ -1 +1 @@
-(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") 
(:class (:declaration (:word "class") (:word "Controller")) (:block))))
\ No newline at end of file
+(:root (:word "declare") (:list (:word "strict_types") (:assignment "=")) 
(:terminator ";") (:namespace (:word "App\\Controller") (:terminator ";") 
(:class (:declaration (:word "class") (:word "Controller")) (:block))))
diff --git a/test/fixtures/TwoShortFunctions.eld 
b/test/fixtures/TwoShortFunctions.eld
index ba1a9b9e20..55f4dec0d8 100644
--- a/test/fixtures/TwoShortFunctions.eld
+++ b/test/fixtures/TwoShortFunctions.eld
@@ -1 +1 @@
-(:root (:function (:declaration (:word "function") (:word "work") (:list)) 
(:block (:word "return") (:variable "variable") (:terminator ";"))) (:function 
(:declaration (:word "function") (:word "work2") (:list)) (:block (:word 
"return") (:variable "paper") (:terminator ";"))))
\ No newline at end of file
+(:root (:function (:declaration (:word "function") (:word "work") (:list)) 
(:block (:word "return") (:variable "variable") (:terminator ";"))) (:function 
(:declaration (:word "function") (:word "work2") (:list)) (:block (:word 
"return") (:variable "paper") (:terminator ";"))))
diff --git a/test/fixtures/Variable.eld b/test/fixtures/Variable.eld
index c544e763e7..4388b45d4f 100644
--- a/test/fixtures/Variable.eld
+++ b/test/fixtures/Variable.eld
@@ -1 +1 @@
-(:root (:variable "variable"))
\ No newline at end of file
+(:root (:variable "variable"))
diff --git a/test/fixtures/Word.eld b/test/fixtures/Word.eld
index e71b757529..92ee97613c 100644
--- a/test/fixtures/Word.eld
+++ b/test/fixtures/Word.eld
@@ -1 +1 @@
-(:root (:word "bareword"))
\ No newline at end of file
+(:root (:word "bareword"))
diff --git a/test/test-index.el b/test/test-index.el
index d1b5fda91b..f984b6e76b 100644
--- a/test/test-index.el
+++ b/test/test-index.el
@@ -163,6 +163,49 @@ return StaticThing::create(new 
ThingFactory())->makeThing((((new Potato())->anti
                       (phpinspect--make-type :name "\\void" :fully-qualified t)
                       (phpinspect--function-return-type method))))))))
 
+(ert-deftest phpinspect-index-static-method-annotations ()
+  (let* ((result (phpinspect--index-tokens
+                  (phpinspect-parse-string
+                   "<?php
+
+/* @method static int peel(bool $fast, array $loose)
+                           * @method static Banana create()
+                            @method static hold() **/
+                           class Banana {}")))
+         (class (car (alist-get 'classes result)))
+         (methods (alist-get 'static-methods class)))
+    (should (= 3 (length methods)))
+    (dolist (method methods)
+      (should (member (phpinspect--function-name method)
+                      '("create" "hold" "peel")))
+
+      (cond ((string= (phpinspect--function-name method)
+                      "duplicate")
+             (should (phpinspect--type=
+                      (phpinspect--make-type :name "\\Banana" :fully-qualified 
t)
+                      (phpinspect--function-return-type method))))
+            ((string= (phpinspect--function-name method)
+                      "peel")
+             (should (phpinspect--type=
+                      (phpinspect--make-type :name "\\int" :fully-qualified t)
+                      (phpinspect--function-return-type method)))
+
+             (should (= 2 (length (phpinspect--function-arguments method))))
+             (should (phpinspect--type=
+                      (phpinspect--make-type :name "\\array" :fully-qualified 
t)
+                      (car (alist-get
+                            "loose" (phpinspect--function-arguments method) 
nil nil #'string=))))
+             (should (phpinspect--type=
+                      (phpinspect--make-type :name "\\bool" :fully-qualified t)
+                      (car (alist-get
+                            "fast" (phpinspect--function-arguments method) nil 
nil #'string=)))))
+            ((string= (phpinspect--function-name method)
+                      "hold")
+             (should (phpinspect--type=
+                      (phpinspect--make-type :name "\\void" :fully-qualified t)
+                      (phpinspect--function-return-type method))))))))
+
+
 (ert-deftest phpinspect-index-tokens-class ()
   (let* ((index1
           (phpinspect--index-tokens



reply via email to

[Prev in Thread] Current Thread [Next in Thread]