Struct php_parser_rs::parser::ast::modifiers::PromotedPropertyModifierGroup
source · #[repr(transparent)]pub struct PromotedPropertyModifierGroup {
pub modifiers: Vec<PromotedPropertyModifier>,
}
Fields§
§modifiers: Vec<PromotedPropertyModifier>
Implementations§
source§impl PromotedPropertyModifierGroup
impl PromotedPropertyModifierGroup
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Examples found in repository?
src/parser/internal/parameters.rs (line 107)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
pub fn constructor_parameter_list(
state: &mut State,
class_name: &str,
) -> Result<ConstructorParameterList, ParseError> {
let comments = state.stream.comments();
let left_parenthesis = utils::skip_left_parenthesis(state)?;
let parameters = utils::comma_separated::<ConstructorParameter>(
state,
&|state| {
attributes::gather_attributes(state)?;
let modifiers = modifiers::promoted_property_group(modifiers::collect(state)?)?;
let ty = data_type::optional_data_type(state)?;
let mut current = state.stream.current();
let ampersand = if matches!(current.kind, TokenKind::Ampersand) {
state.stream.next();
current = state.stream.current();
Some(current.span)
} else {
None
};
let ellipsis = if matches!(current.kind, TokenKind::Ellipsis) {
state.stream.next();
if !modifiers.is_empty() {
return Err(ParseError::VariadicPromotedProperty(current.span));
}
Some(current.span)
} else {
None
};
// 2. Then expect a variable.
let var = variables::simple_variable(state)?;
if !modifiers.is_empty() {
match &ty {
Some(ty) => {
if ty.includes_callable() || ty.is_bottom() {
return Err(ParseError::ForbiddenTypeUsedInProperty(
state.named(class_name),
var.to_string(),
ty.clone(),
state.stream.current().span,
));
}
}
None => {
if modifiers.has_readonly() {
return Err(ParseError::MissingTypeForReadonlyProperty(
state.named(class_name),
var.to_string(),
state.stream.current().span,
));
}
}
}
}
let mut default = None;
if state.stream.current().kind == TokenKind::Equals {
state.stream.next();
default = Some(expressions::create(state)?);
}
Ok(ConstructorParameter {
comments: state.stream.comments(),
name: var,
attributes: state.get_attributes(),
data_type: ty,
ellipsis,
default,
modifiers,
ampersand,
})
},
TokenKind::RightParen,
)?;
let right_parenthesis = utils::skip_right_parenthesis(state)?;
Ok(ConstructorParameterList {
comments,
left_parenthesis,
parameters,
right_parenthesis,
})
}
sourcepub fn has_readonly(&self) -> bool
pub fn has_readonly(&self) -> bool
Examples found in repository?
src/parser/internal/parameters.rs (line 132)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
pub fn constructor_parameter_list(
state: &mut State,
class_name: &str,
) -> Result<ConstructorParameterList, ParseError> {
let comments = state.stream.comments();
let left_parenthesis = utils::skip_left_parenthesis(state)?;
let parameters = utils::comma_separated::<ConstructorParameter>(
state,
&|state| {
attributes::gather_attributes(state)?;
let modifiers = modifiers::promoted_property_group(modifiers::collect(state)?)?;
let ty = data_type::optional_data_type(state)?;
let mut current = state.stream.current();
let ampersand = if matches!(current.kind, TokenKind::Ampersand) {
state.stream.next();
current = state.stream.current();
Some(current.span)
} else {
None
};
let ellipsis = if matches!(current.kind, TokenKind::Ellipsis) {
state.stream.next();
if !modifiers.is_empty() {
return Err(ParseError::VariadicPromotedProperty(current.span));
}
Some(current.span)
} else {
None
};
// 2. Then expect a variable.
let var = variables::simple_variable(state)?;
if !modifiers.is_empty() {
match &ty {
Some(ty) => {
if ty.includes_callable() || ty.is_bottom() {
return Err(ParseError::ForbiddenTypeUsedInProperty(
state.named(class_name),
var.to_string(),
ty.clone(),
state.stream.current().span,
));
}
}
None => {
if modifiers.has_readonly() {
return Err(ParseError::MissingTypeForReadonlyProperty(
state.named(class_name),
var.to_string(),
state.stream.current().span,
));
}
}
}
}
let mut default = None;
if state.stream.current().kind == TokenKind::Equals {
state.stream.next();
default = Some(expressions::create(state)?);
}
Ok(ConstructorParameter {
comments: state.stream.comments(),
name: var,
attributes: state.get_attributes(),
data_type: ty,
ellipsis,
default,
modifiers,
ampersand,
})
},
TokenKind::RightParen,
)?;
let right_parenthesis = utils::skip_right_parenthesis(state)?;
Ok(ConstructorParameterList {
comments,
left_parenthesis,
parameters,
right_parenthesis,
})
}
pub fn visibility(&self) -> Visibility
Trait Implementations§
source§impl Clone for PromotedPropertyModifierGroup
impl Clone for PromotedPropertyModifierGroup
source§fn clone(&self) -> PromotedPropertyModifierGroup
fn clone(&self) -> PromotedPropertyModifierGroup
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<'de> Deserialize<'de> for PromotedPropertyModifierGroup
impl<'de> Deserialize<'de> for PromotedPropertyModifierGroup
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 PromotedPropertyModifierGroup
impl JsonSchema for PromotedPropertyModifierGroup
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<PromotedPropertyModifierGroup> for PromotedPropertyModifierGroup
impl PartialEq<PromotedPropertyModifierGroup> for PromotedPropertyModifierGroup
source§fn eq(&self, other: &PromotedPropertyModifierGroup) -> bool
fn eq(&self, other: &PromotedPropertyModifierGroup) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.