MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / is_class_like_keyword

Function is_class_like_keyword

src/completion/phpdoc/generation.rs:694–722  ·  view source on GitHub ↗

Check whether a declaration string starts with a class-like keyword (class, interface, trait, enum), possibly preceded by modifiers.

(decl: &str)

Source from the content-addressed store, hash-verified

692/// Check whether a declaration string starts with a class-like keyword
693/// (class, interface, trait, enum), possibly preceded by modifiers.
694fn is_class_like_keyword(decl: &str) -> bool {
695 let class_keywords = ["class", "interface", "trait", "enum"];
696 let modifier_keywords = ["abstract", "final", "readonly"];
697 let lower = decl.to_lowercase();
698 let mut rest = lower.as_str().trim();
699 loop {
700 let mut found = false;
701 for kw in &class_keywords {
702 if let Some(after) = rest.strip_prefix(*kw)
703 && (after.is_empty() || after.starts_with(|c: char| c.is_whitespace()))
704 {
705 return true;
706 }
707 }
708 for kw in &modifier_keywords {
709 if let Some(after) = rest.strip_prefix(*kw)
710 && (after.is_empty() || after.starts_with(|c: char| c.is_whitespace()))
711 {
712 rest = after.trim_start();
713 found = true;
714 break;
715 }
716 }
717 if !found {
718 break;
719 }
720 }
721 false
722}
723
724/// Extract parent class names and interface names from a class-like
725/// declaration header (e.g. `class Foo extends Bar implements Baz`).

Callers 1

parse_declaration_infoFunction · 0.85

Calls 2

as_strMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected