aboutsummaryrefslogtreecommitdiffstats
path: root/components/script_plugins/webidl_must_inherit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script_plugins/webidl_must_inherit.rs')
-rw-r--r--components/script_plugins/webidl_must_inherit.rs60
1 files changed, 17 insertions, 43 deletions
diff --git a/components/script_plugins/webidl_must_inherit.rs b/components/script_plugins/webidl_must_inherit.rs
index 89233bb943e..7c092fcf0f9 100644
--- a/components/script_plugins/webidl_must_inherit.rs
+++ b/components/script_plugins/webidl_must_inherit.rs
@@ -13,9 +13,7 @@ use std::fs;
use std::io;
use std::path;
use syntax::ast;
-use webidl::ast::*;
-use webidl::visitor::*;
-use webidl::*;
+use weedle;
declare_lint!(
WEBIDL_INHERIT_CORRECT,
@@ -94,10 +92,22 @@ fn is_webidl_ty(cx: &LateContext, ty: &ty::TyS) -> bool {
}
fn check_inherits(code: &str, name: &str, parent_name: &str) -> Result<(), Box<Error>> {
- let idl = parse_string(code)?;
- let mut visitor = InterfaceVisitor::new(name.to_string());
- visitor.visit(&idl);
- let inherits = visitor.get_inherits();
+ let idl = weedle::parse(code).expect("Invalid webidl provided");
+ let mut inherits = "";
+
+ for def in idl {
+ if let weedle::Definition::Interface(def) = def {
+ if let Some(parent) = def.inheritance {
+ inherits = parent.identifier.0;
+ break;
+ }
+ } else if let weedle::Definition::CallbackInterface(def) = def {
+ if let Some(parent) = def.inheritance {
+ inherits = parent.identifier.0;
+ break;
+ }
+ }
+ }
if inherits == parent_name {
return Ok(());
@@ -184,39 +194,3 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WebIdlPass {
};
}
}
-
-struct InterfaceVisitor {
- name: String,
- inherits: String,
-}
-
-impl InterfaceVisitor {
- pub fn new(name: String) -> Self {
- InterfaceVisitor {
- name: name,
- inherits: String::new(),
- }
- }
-
- pub fn get_inherits(&self) -> &String {
- &self.inherits
- }
-}
-
-impl<'ast> ImmutableVisitor<'ast> for InterfaceVisitor {
- fn visit_callback_interface(&mut self, callback_interface: &'ast CallbackInterface) {
- if callback_interface.name == self.name {
- if let Some(ref inherit) = callback_interface.inherits {
- self.inherits = inherit.to_string()
- }
- }
- }
-
- fn visit_non_partial_interface(&mut self, non_partial_interface: &'ast NonPartialInterface) {
- if non_partial_interface.name == self.name {
- if let Some(ref inherit) = non_partial_interface.inherits {
- self.inherits = inherit.to_string()
- }
- }
- }
-}