rust/crates/ra_hir/src/impl_block.rs

54 lines
1.6 KiB
Rust
Raw Normal View History

//! FIXME: write short doc here
2019-11-15 18:28:00 +00:00
use hir_def::{type_ref::TypeRef, AstItemDef};
use ra_syntax::ast::{self};
use crate::{
2019-09-08 06:53:49 +00:00
db::{AstDatabase, DefDatabase, HirDatabase},
2019-11-20 18:55:33 +00:00
resolve::HasResolver,
ty::Ty,
2019-11-15 18:28:00 +00:00
AssocItem, Crate, HasSource, ImplBlock, Module, Source, TraitRef,
};
2019-06-11 14:36:52 +00:00
impl HasSource for ImplBlock {
2019-07-19 07:43:01 +00:00
type Ast = ast::ImplBlock;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::ImplBlock> {
2019-11-15 18:28:00 +00:00
self.id.source(db)
2019-06-11 14:36:52 +00:00
}
}
impl ImplBlock {
pub fn target_trait(&self, db: &impl DefDatabase) -> Option<TypeRef> {
2019-11-15 18:28:00 +00:00
db.impl_data(self.id).target_trait().cloned()
}
pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef {
2019-11-15 18:28:00 +00:00
db.impl_data(self.id).target_type().clone()
}
2019-01-26 21:52:04 +00:00
pub fn target_ty(&self, db: &impl HirDatabase) -> Ty {
Ty::from_hir(db, &self.resolver(db), &self.target_type(db))
2019-01-26 21:52:04 +00:00
}
pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> {
let target_ty = self.target_ty(db);
TraitRef::from_hir(db, &self.resolver(db), &self.target_trait(db)?, Some(target_ty))
2019-01-26 21:52:04 +00:00
}
pub fn items(&self, db: &impl DefDatabase) -> Vec<AssocItem> {
2019-11-15 18:28:00 +00:00
db.impl_data(self.id).items().iter().map(|it| (*it).into()).collect()
}
2019-01-23 22:08:41 +00:00
pub fn is_negative(&self, db: &impl DefDatabase) -> bool {
2019-11-15 18:28:00 +00:00
db.impl_data(self.id).is_negative()
}
pub fn module(&self, db: &impl DefDatabase) -> Module {
self.id.module(db).into()
}
pub fn krate(&self, db: &impl DefDatabase) -> Crate {
Crate { crate_id: self.module(db).id.krate }
}
}