diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2015-05-21 23:10:54 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-05-21 23:10:54 +0530 |
commit | 8394b8235071c69a949f4c73b421b177a51ba09f (patch) | |
tree | afdcc571dd675e4defe40f009f832c6311042fdb /components/plugins/reflector.rs | |
parent | a0fccea670124d5ccfef1c13fe1b5d2e58891236 (diff) | |
download | servo-8394b8235071c69a949f4c73b421b177a51ba09f.tar.gz servo-8394b8235071c69a949f4c73b421b177a51ba09f.zip |
Fix deprecated plugin APIs
Diffstat (limited to 'components/plugins/reflector.rs')
-rw-r--r-- | components/plugins/reflector.rs | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/components/plugins/reflector.rs b/components/plugins/reflector.rs index 6c2213cdabc..d369dcbd3f3 100644 --- a/components/plugins/reflector.rs +++ b/components/plugins/reflector.rs @@ -2,45 +2,46 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use syntax::ext::base::ExtCtxt; +use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::codemap::Span; -use syntax::ptr::P; -use syntax::ast::{Item, MetaItem}; +use syntax::ast::MetaItem; use syntax::ast; use utils::match_ty_unwrap; -pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, item: &Item, push: &mut FnMut(P<Item>) -> ()) { - if let ast::ItemStruct(ref def, _) = item.node { - let struct_name = item.ident; - // This path has to be hardcoded, unfortunately, since we can't resolve paths at expansion time - match def.fields.iter().find(|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) { - // If it has a field that is a Reflector, use that - Some(f) => { - let field_name = f.node.ident(); - let impl_item = quote_item!(cx, - impl ::dom::bindings::utils::Reflectable for $struct_name { - fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { - &self.$field_name +pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: Annotatable, push: &mut FnMut(Annotatable)) { + if let Annotatable::Item(item) = annotatable { + if let ast::ItemStruct(ref def, _) = item.node { + let struct_name = item.ident; + // This path has to be hardcoded, unfortunately, since we can't resolve paths at expansion time + match def.fields.iter().find(|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) { + // If it has a field that is a Reflector, use that + Some(f) => { + let field_name = f.node.ident(); + let impl_item = quote_item!(cx, + impl ::dom::bindings::utils::Reflectable for $struct_name { + fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { + &self.$field_name + } } - } - ); - impl_item.map(|it| push(it)) - }, - // Or just call it on the first field (supertype). - None => { - let field_name = def.fields[0].node.ident(); - let impl_item = quote_item!(cx, - impl ::dom::bindings::utils::Reflectable for $struct_name { - fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { - self.$field_name.reflector() + ); + impl_item.map(|it| push(Annotatable::Item(it))) + }, + // Or just call it on the first field (supertype). + None => { + let field_name = def.fields[0].node.ident(); + let impl_item = quote_item!(cx, + impl ::dom::bindings::utils::Reflectable for $struct_name { + fn reflector<'a>(&'a self) -> &'a ::dom::bindings::utils::Reflector { + self.$field_name.reflector() + } } - } - ); - impl_item.map(|it| push(it)) - } - }; - } else { - cx.span_err(span, "#[dom_struct] seems to have been applied to a non-struct"); + ); + impl_item.map(|it| push(Annotatable::Item(it))) + } + }; + } else { + cx.span_err(span, "#[dom_struct] seems to have been applied to a non-struct"); + } } } |