aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs44
1 files changed, 22 insertions, 22 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index f3466c585..f030e0df8 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -3,7 +3,7 @@
3 3
4use itertools::Itertools; 4use itertools::Itertools;
5 5
6use crate::{SmolStr, SyntaxToken, ast::{self, AstNode, children, child_opt}, SyntaxKind::*, SyntaxElement}; 6use crate::{SmolStr, SyntaxToken, ast::{self, AstNode, children, child_opt}, SyntaxKind::*, SyntaxElement, T};
7use ra_parser::SyntaxKind; 7use ra_parser::SyntaxKind;
8 8
9impl ast::Name { 9impl ast::Name {
@@ -32,7 +32,7 @@ impl ast::Attr {
32 Some(prev) => prev, 32 Some(prev) => prev,
33 }; 33 };
34 34
35 prev.kind() == EXCL 35 prev.kind() == T![!]
36 } 36 }
37 37
38 pub fn as_atom(&self) -> Option<SmolStr> { 38 pub fn as_atom(&self) -> Option<SmolStr> {
@@ -102,9 +102,9 @@ impl ast::PathSegment {
102 PathSegmentKind::Name(name_ref) 102 PathSegmentKind::Name(name_ref)
103 } else { 103 } else {
104 match self.syntax().first_child_or_token()?.kind() { 104 match self.syntax().first_child_or_token()?.kind() {
105 SELF_KW => PathSegmentKind::SelfKw, 105 T![self] => PathSegmentKind::SelfKw,
106 SUPER_KW => PathSegmentKind::SuperKw, 106 T![super] => PathSegmentKind::SuperKw,
107 CRATE_KW => PathSegmentKind::CrateKw, 107 T![crate] => PathSegmentKind::CrateKw,
108 _ => return None, 108 _ => return None,
109 } 109 }
110 }; 110 };
@@ -113,7 +113,7 @@ impl ast::PathSegment {
113 113
114 pub fn has_colon_colon(&self) -> bool { 114 pub fn has_colon_colon(&self) -> bool {
115 match self.syntax.first_child_or_token().map(|s| s.kind()) { 115 match self.syntax.first_child_or_token().map(|s| s.kind()) {
116 Some(COLONCOLON) => true, 116 Some(T![::]) => true,
117 _ => false, 117 _ => false,
118 } 118 }
119 } 119 }
@@ -129,14 +129,14 @@ impl ast::Module {
129 pub fn has_semi(&self) -> bool { 129 pub fn has_semi(&self) -> bool {
130 match self.syntax().last_child_or_token() { 130 match self.syntax().last_child_or_token() {
131 None => false, 131 None => false,
132 Some(node) => node.kind() == SEMI, 132 Some(node) => node.kind() == T![;],
133 } 133 }
134 } 134 }
135} 135}
136 136
137impl ast::UseTree { 137impl ast::UseTree {
138 pub fn has_star(&self) -> bool { 138 pub fn has_star(&self) -> bool {
139 self.syntax().children_with_tokens().any(|it| it.kind() == STAR) 139 self.syntax().children_with_tokens().any(|it| it.kind() == T![*])
140 } 140 }
141} 141}
142 142
@@ -172,7 +172,7 @@ impl ast::ImplBlock {
172 } 172 }
173 173
174 pub fn is_negative(&self) -> bool { 174 pub fn is_negative(&self) -> bool {
175 self.syntax().children_with_tokens().any(|t| t.kind() == EXCL) 175 self.syntax().children_with_tokens().any(|t| t.kind() == T![!])
176 } 176 }
177} 177}
178 178
@@ -219,7 +219,7 @@ impl ast::FnDef {
219 self.syntax() 219 self.syntax()
220 .last_child_or_token() 220 .last_child_or_token()
221 .and_then(|it| it.as_token()) 221 .and_then(|it| it.as_token())
222 .filter(|it| it.kind() == SEMI) 222 .filter(|it| it.kind() == T![;])
223 } 223 }
224} 224}
225 225
@@ -227,7 +227,7 @@ impl ast::LetStmt {
227 pub fn has_semi(&self) -> bool { 227 pub fn has_semi(&self) -> bool {
228 match self.syntax().last_child_or_token() { 228 match self.syntax().last_child_or_token() {
229 None => false, 229 None => false,
230 Some(node) => node.kind() == SEMI, 230 Some(node) => node.kind() == T![;],
231 } 231 }
232 } 232 }
233} 233}
@@ -236,7 +236,7 @@ impl ast::ExprStmt {
236 pub fn has_semi(&self) -> bool { 236 pub fn has_semi(&self) -> bool {
237 match self.syntax().last_child_or_token() { 237 match self.syntax().last_child_or_token() {
238 None => false, 238 None => false,
239 Some(node) => node.kind() == SEMI, 239 Some(node) => node.kind() == T![;],
240 } 240 }
241 } 241 }
242} 242}
@@ -270,29 +270,29 @@ impl ast::FieldExpr {
270 270
271impl ast::RefPat { 271impl ast::RefPat {
272 pub fn is_mut(&self) -> bool { 272 pub fn is_mut(&self) -> bool {
273 self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) 273 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
274 } 274 }
275} 275}
276 276
277impl ast::BindPat { 277impl ast::BindPat {
278 pub fn is_mutable(&self) -> bool { 278 pub fn is_mutable(&self) -> bool {
279 self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) 279 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
280 } 280 }
281 281
282 pub fn is_ref(&self) -> bool { 282 pub fn is_ref(&self) -> bool {
283 self.syntax().children_with_tokens().any(|n| n.kind() == REF_KW) 283 self.syntax().children_with_tokens().any(|n| n.kind() == T![ref])
284 } 284 }
285} 285}
286 286
287impl ast::PointerType { 287impl ast::PointerType {
288 pub fn is_mut(&self) -> bool { 288 pub fn is_mut(&self) -> bool {
289 self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) 289 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
290 } 290 }
291} 291}
292 292
293impl ast::ReferenceType { 293impl ast::ReferenceType {
294 pub fn is_mut(&self) -> bool { 294 pub fn is_mut(&self) -> bool {
295 self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) 295 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
296 } 296 }
297} 297}
298 298
@@ -311,19 +311,19 @@ impl ast::SelfParam {
311 self.syntax() 311 self.syntax()
312 .children_with_tokens() 312 .children_with_tokens()
313 .filter_map(|it| it.as_token()) 313 .filter_map(|it| it.as_token())
314 .find(|it| it.kind() == SELF_KW) 314 .find(|it| it.kind() == T![self])
315 .expect("invalid tree: self param must have self") 315 .expect("invalid tree: self param must have self")
316 } 316 }
317 317
318 pub fn kind(&self) -> SelfParamKind { 318 pub fn kind(&self) -> SelfParamKind {
319 let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP); 319 let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == T![&]);
320 if borrowed { 320 if borrowed {
321 // check for a `mut` coming after the & -- `mut &self` != `&mut self` 321 // check for a `mut` coming after the & -- `mut &self` != `&mut self`
322 if self 322 if self
323 .syntax() 323 .syntax()
324 .children_with_tokens() 324 .children_with_tokens()
325 .skip_while(|n| n.kind() != AMP) 325 .skip_while(|n| n.kind() != T![&])
326 .any(|n| n.kind() == MUT_KW) 326 .any(|n| n.kind() == T![mut])
327 { 327 {
328 SelfParamKind::MutRef 328 SelfParamKind::MutRef
329 } else { 329 } else {
@@ -355,6 +355,6 @@ impl ast::WherePred {
355 355
356impl ast::TraitDef { 356impl ast::TraitDef {
357 pub fn is_auto(&self) -> bool { 357 pub fn is_auto(&self) -> bool {
358 self.syntax().children_with_tokens().any(|t| t.kind() == AUTO_KW) 358 self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
359 } 359 }
360} 360}