Check whether a `ClassInfo` matches this context.
(&self, cls: &ClassInfo)
| 79 | impl ClassNameContext { |
| 80 | /// Check whether a `ClassInfo` matches this context. |
| 81 | pub(crate) fn matches(&self, cls: &ClassInfo) -> bool { |
| 82 | match self { |
| 83 | Self::Any => true, |
| 84 | Self::New => cls.kind == ClassLikeKind::Class && !cls.is_abstract, |
| 85 | Self::ExtendsClass => cls.kind == ClassLikeKind::Class && !cls.is_final, |
| 86 | Self::ExtendsInterface => cls.kind == ClassLikeKind::Interface, |
| 87 | Self::Implements => cls.kind == ClassLikeKind::Interface, |
| 88 | Self::TraitUse => cls.kind == ClassLikeKind::Trait, |
| 89 | Self::Instanceof | Self::TypeHint => cls.kind != ClassLikeKind::Trait, |
| 90 | Self::UseImport => true, |
| 91 | Self::UseFunction | Self::UseConst | Self::NamespaceDeclaration => false, |
| 92 | Self::Attribute(target) => { |
| 93 | cls.attribute_targets != 0 && (cls.attribute_targets & target) != 0 |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /// Check whether a class-like matches this context given only kind |
| 99 | /// flags (used by tests for `detect_stub_class_kind`). |
no outgoing calls