def __init__(self, type_tokens=None): self.input_tokens = type_tokens or [] self.comment = None self.extension_attributes = MutableDict() self.__constructed() MutableObject.__init__(self)
class Symbol(Base): """ The base class for all symbols, there should be no reason for instantiating it directly. """ __tablename__ = 'symbols' id_ = Column(Integer, primary_key=True) comment = Column(PickleType) unique_name = Column(String) display_name = Column(String) filename = Column(String) lineno = Column(Integer) extent_start = Column(Integer) extent_end = Column(Integer) location = Column(PickleType) language = Column(String) _type_ = Column(String) extension_contents = Column(MutableDict.as_mutable(PickleType)) extension_attributes = Column(MutableDict.as_mutable(PickleType)) link = Column(Link.as_mutable(PickleType)) skip = Column(Boolean) __mapper_args__ = { 'polymorphic_identity': 'symbol', 'polymorphic_on': _type_, } def __init__(self, **kwargs): self.extension_contents = {} self.extension_attributes = {} self.skip = False Base.__init__(self, **kwargs) # FIXME: this is a bit awkward to use. def add_extension_attribute(self, ext_name, key, value): """ Banana banana """ attributes = self.extension_attributes.pop(ext_name, {}) attributes[key] = value self.extension_attributes[ext_name] = attributes def get_extension_attribute(self, ext_name, key): """ Banana banana """ attributes = self.extension_attributes.get(ext_name) if not attributes: return None return attributes.get(key) # pylint: disable=no-self-use def get_children_symbols(self): """ Banana banana """ return [] # pylint: disable=unidiomatic-typecheck # pylint: disable=no-member def update_children_comments(self): """ Banana banana """ if self.comment is None: return for sym in self.get_children_symbols(): if type(sym) == ParameterSymbol: sym.comment = self.comment.params.get(sym.argname) elif type(sym) == FieldSymbol: sym.comment = self.comment.params.get(sym.member_name) elif type(sym) == ReturnItemSymbol: tag = self.comment.tags.get('returns') sym.comment = comment_from_tag(tag) elif type(sym) == Symbol: sym.comment = self.comment.params.get(sym.display_name) def _make_name(self): return self.display_name def get_extra_links(self): """ Banana banana """ return [] def get_type_name(self): """ Banana banana """ return '' def resolve_links(self, link_resolver): """ Banana banana """ if self.link is None: self.link = Link(self.unique_name, self._make_name(), self.unique_name) self.link = link_resolver.upsert_link(self.link, overwrite_ref=True) for sym in self.get_children_symbols(): if sym: sym.resolve_links(link_resolver)
class QualifiedSymbol(MutableObject): """ Banana banana """ def __init__(self, type_tokens=None): self.input_tokens = type_tokens or [] self.comment = None self.extension_attributes = MutableDict() self.__constructed() MutableObject.__init__(self) def add_extension_attribute(self, ext_name, key, value): """ Banana banana """ attributes = self.extension_attributes.pop(ext_name, {}) attributes[key] = value self.extension_attributes[ext_name] = attributes def get_extension_attribute(self, ext_name, key): """ Banana banana """ attributes = self.extension_attributes.get(ext_name) if not attributes: return None return attributes.get(key) # pylint: disable=no-self-use def get_children_symbols(self): """ Banana banana """ return [] def get_type_link(self): """ Banana banana """ return self.type_link # pylint: disable=attribute-defined-outside-init def resolve_links(self, link_resolver): """ Banana banana """ self.type_link = None self.type_tokens = [] for tok in self.input_tokens: if isinstance(tok, Link): self.type_link = link_resolver.upsert_link(tok) self.type_tokens.append(self.type_link) else: self.type_tokens.append(tok) def __constructed(self): self.extension_contents = {} def __setstate__(self, state): MutableObject.__setstate__(self, state) self.__constructed()