Index types used in class property initializers and combine change calls for fix-imports

master
Hugo Thunnissen 1 month ago
parent d7704c9d7c
commit 855529095a

@ -260,10 +260,11 @@ group."
(with-current-buffer (phpinspect-buffer-buffer buffer)
(save-excursion
(goto-char start)
(delete-region start end)
(dolist (statement statements)
(phpinspect-codify-token (cdr statement))
(insert-char ?\n))
(combine-after-change-calls
(delete-region start end)
(dolist (statement statements)
(phpinspect-codify-token (cdr statement))
(insert-char ?\n)))
(if (looking-at "[[:blank:]\n]+")
;; Delete excess trailing whitespace (there's more than 2 between the
@ -279,6 +280,7 @@ group."
"Find types that are used in the current buffer and make sure
that there are import (\"use\") statements for them."
(interactive)
(if phpinspect-current-buffer
(let* ((buffer phpinspect-current-buffer)
;; use buffer-reparse to ensure fully structurally correct
@ -346,6 +348,11 @@ that there are import (\"use\") statements for them."
(phpinspect-add-use-statements-for-missing-types
used-types buffer (append imports namespace-imports) project token-meta)
(with-current-buffer (get-buffer-create "attempt-before-namespace-removal-code")
(erase-buffer)
(insert (with-current-buffer (phpinspect-buffer-buffer buffer) (buffer-string))))
(phpinspect-remove-unneeded-use-statements
used-types buffer (append imports namespace-imports) token-meta)

@ -261,7 +261,9 @@ SCOPE should be a scope token (`phpinspect-scope-p')."
(t
(setq variable-name (cadr (seq-find #'phpinspect-variable-p scope)))))
(phpinspect--log "calling resolver from index-variable-from-scope")
(when add-used-types
(funcall add-used-types (phpinspect--find-used-types-in-tokens scope)))
(phpinspect--make-variable
;; Static class variables are always prefixed with dollar signs when
;; referenced.
@ -589,6 +591,7 @@ Returns a list of type name strings."
(while tokens
(let ((token (pop tokens))
(previous-token (car previous-tokens)))
(cond ((and (phpinspect-word-p previous-token)
(member (cadr previous-token) `("new" "instanceof"))
(phpinspect-word-p token))
@ -633,7 +636,12 @@ Returns a list of type name strings."
(nconc used-types-rear
(phpinspect--find-used-types-in-tokens (cdr (phpinspect-function-block token))))
used-types-rear (last used-types-rear)))
((or (phpinspect-list-p token) (phpinspect-block-p token) (phpinspect-array-p token))
((or (phpinspect-list-p token)
(phpinspect-block-p token)
(phpinspect-array-p token)
(phpinspect-scope-p token)
(phpinspect-static-p token)
(phpinspect-const-p token))
(setq used-types-rear
(nconc used-types-rear (phpinspect--find-used-types-in-tokens (cdr token)))
used-types-rear (last used-types-rear))))

@ -798,19 +798,19 @@ Returns the consumed text string without face properties."
(phpinspect-defparser scope-public
:tree-keyword "public"
:handlers '(function-keyword static-keyword const-keyword class-variable here-doc
string terminator tag comment word)
string terminator tag comment assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defparser scope-private
:tree-keyword "private"
:handlers '(function-keyword static-keyword const-keyword class-variable here-doc
string terminator tag comment word)
string terminator tag comment assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defparser scope-protected
:tree-keyword "protected"
:handlers '(function-keyword static-keyword const-keyword class-variable here-doc
string terminator tag comment word)
string terminator tag comment assignment-operator array word)
:delimiter-predicate #'phpinspect--scope-terminator-p)
(phpinspect-defhandler scope-keyword (start-token max-point)

@ -311,7 +311,7 @@ use CCC;
(let ((switch nil)
(delta 0))
(dotimes (i 100)
(dotimes (_i 100)
(if switch
(progn
(setq delta 0)

@ -92,6 +92,8 @@
use UsedTrait;
private array $bong = [ PropertyArray::class => PropertyArrayItem::class ];
private PropertyType $property;
/** @param ParamAnnotation $par
@ -106,7 +108,7 @@ return StaticThing::create(new ThingFactory())->makeThing((((new Potato())->anti
if ($param instanceof InstanceOffed) {
/** @var VarAnnotation $bing */
try {
$bing = [ 'bong' => [ 'nested' => (CastedType) NestedArray::call(), ], ];
$bing = [ ArrayKey::class => [ NestedArrayKey::class => (CastedType) NestedArray::call(), 'ba' => ArrayItem::class ], ];
} catch (CaughtException $e) {
// nothing
}
@ -122,7 +124,9 @@ try {
"StaticThing" "Thing" "ThingFactory" "Potato" "OtherThing"
"InnerFunctionParam" "PropertyType" "InstanceOffed"
"NestedArray" "UsedTrait" "VarAnnotation" "ParamAnnotation"
"ThrowAnnotationException" "CaughtException" "CastedType"))
"ThrowAnnotationException" "CaughtException" "CastedType"
"NestedArrayKey" "ArrayKey" "ArrayItem" "PropertyArray"
"PropertyArrayItem" "array"))
#'string<))
(sort used-types (lambda (s1 s2) (string< (phpinspect-name-string s1) (phpinspect-name-string s2))))))))

Loading…
Cancel
Save