Struct php_parser_rs::parser::ast::modifiers::MethodModifierGroup
source · #[repr(transparent)]pub struct MethodModifierGroup {
pub modifiers: Vec<MethodModifier>,
}
Fields§
§modifiers: Vec<MethodModifier>
Implementations§
source§impl MethodModifierGroup
impl MethodModifierGroup
pub fn is_empty(&self) -> bool
pub fn has_final(&self) -> bool
pub fn has_static(&self) -> bool
sourcepub fn has_abstract(&self) -> bool
pub fn has_abstract(&self) -> bool
Examples found in repository?
src/parser/internal/functions.rs (line 253)
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
pub fn method(
state: &mut State,
r#type: MethodType,
modifiers: MethodModifierGroup,
class_name: &str,
) -> ParseResult<Method> {
let comments = state.stream.comments();
let attributes = state.get_attributes();
let function = utils::skip(state, TokenKind::Function)?;
let current = state.stream.current();
let ampersand = if current.kind == TokenKind::Ampersand {
state.stream.next();
Some(current.span)
} else {
None
};
let name = identifiers::identifier_maybe_reserved(state)?;
let has_body = match r#type {
MethodType::Abstract => false,
MethodType::Concrete => true,
MethodType::DependingOnModifiers => !modifiers.has_abstract(),
};
if name.to_string().to_lowercase() == "__construct" {
if has_body {
let parameters = parameters::constructor_parameter_list(state, class_name)?;
let body = MethodBody {
comments: state.stream.comments(),
left_brace: utils::skip_left_brace(state)?,
statements: blocks::multiple_statements_until(state, &TokenKind::RightBrace)?,
right_brace: utils::skip_right_brace(state)?,
};
return Ok(Method::ConcreteConstructor(ConcreteConstructor {
comments,
attributes,
modifiers,
function,
ampersand,
name,
parameters,
body,
}));
} else {
let parameters = parameters::function_parameter_list(state)?;
let semicolon = utils::skip_semicolon(state)?;
return Ok(Method::AbstractConstructor(AbstractConstructor {
comments,
attributes,
modifiers,
function,
ampersand,
name,
parameters,
semicolon,
}));
}
}
let parameters = parameters::function_parameter_list(state)?;
let return_type = if state.stream.current().kind == TokenKind::Colon {
Some(ReturnType {
colon: utils::skip_colon(state)?,
data_type: data_type::data_type(state)?,
})
} else {
None
};
if has_body {
Ok(Method::Concrete(ConcreteMethod {
comments,
attributes,
modifiers,
function,
ampersand,
name,
parameters,
return_type,
body: MethodBody {
comments: state.stream.comments(),
left_brace: utils::skip_left_brace(state)?,
statements: blocks::multiple_statements_until(state, &TokenKind::RightBrace)?,
right_brace: utils::skip_right_brace(state)?,
},
}))
} else {
Ok(Method::Abstract(AbstractMethod {
comments,
attributes,
modifiers,
function,
ampersand,
name,
parameters,
return_type,
semicolon: utils::skip_semicolon(state)?,
}))
}
}
sourcepub fn get_abstract(&self) -> Option<&MethodModifier>
pub fn get_abstract(&self) -> Option<&MethodModifier>
Examples found in repository?
src/parser/internal/classes.rs (line 197)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
fn member(state: &mut State, abstract_class: bool, class_name: &str) -> ParseResult<ClassMember> {
let has_attributes = attributes::gather_attributes(state)?;
if !has_attributes && state.stream.current().kind == TokenKind::Use {
return traits::usage(state).map(ClassMember::TraitUsage);
}
if state.stream.current().kind == TokenKind::Var {
return properties::parse_var(state, class_name).map(ClassMember::VariableProperty);
}
let modifiers = modifiers::collect(state)?;
if state.stream.current().kind == TokenKind::Const {
return classish(state, modifiers::constant_group(modifiers)?).map(ClassMember::Constant);
}
if state.stream.current().kind == TokenKind::Function {
let method = method(
state,
MethodType::DependingOnModifiers,
modifiers::method_group(modifiers)?,
class_name,
)?;
match method {
Method::Abstract(method) => {
if !abstract_class {
return Err(ParseError::AbstractModifierOnNonAbstractClassMethod(
method.modifiers.get_abstract().unwrap().span(),
));
}
return Ok(ClassMember::AbstractMethod(method));
}
Method::Concrete(method) => {
return Ok(ClassMember::ConcreteMethod(method));
}
Method::AbstractConstructor(ctor) => {
if !abstract_class {
return Err(ParseError::AbstractModifierOnNonAbstractClassMethod(
ctor.modifiers.get_abstract().unwrap().span(),
));
}
return Ok(ClassMember::AbstractConstructor(ctor));
}
Method::ConcreteConstructor(ctor) => {
return Ok(ClassMember::ConcreteConstructor(ctor));
}
}
}
// e.g: public static
let modifiers = modifiers::property_group(modifiers)?;
properties::parse(state, class_name, modifiers).map(ClassMember::Property)
}
pub fn visibility(&self) -> Visibility
Trait Implementations§
source§impl Clone for MethodModifierGroup
impl Clone for MethodModifierGroup
source§fn clone(&self) -> MethodModifierGroup
fn clone(&self) -> MethodModifierGroup
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for MethodModifierGroup
impl Debug for MethodModifierGroup
source§impl<'de> Deserialize<'de> for MethodModifierGroup
impl<'de> Deserialize<'de> for MethodModifierGroup
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl JsonSchema for MethodModifierGroup
impl JsonSchema for MethodModifierGroup
source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read moresource§impl PartialEq<MethodModifierGroup> for MethodModifierGroup
impl PartialEq<MethodModifierGroup> for MethodModifierGroup
source§fn eq(&self, other: &MethodModifierGroup) -> bool
fn eq(&self, other: &MethodModifierGroup) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.