Exemple #1
0
    def related_names(self, additional_module_paths=[]):
        """
        Returns `dynamic.RelatedName` objects, which contain all names, that
        are defined by the same variable, function, class or import.
        This function can be used either to show all the usages of a variable
        or for renaming purposes.

        TODO implement additional_module_paths
        """
        user_stmt = self.parser.user_stmt
        definitions, search_name = self._goto(add_import_name=True)
        if isinstance(user_stmt, parsing.Statement) \
                    and self.pos < user_stmt.get_assignment_calls().start_pos:
            # the search_name might be before `=`
            definitions = [v for v in user_stmt.set_vars
                                                if unicode(v) == search_name]
        if not isinstance(user_stmt, parsing.Import):
            # import case is looked at with add_import_name option
            definitions = dynamic.related_name_add_import_modules(definitions,
                                                                search_name)

        module = set([d.get_parent_until() for d in definitions])
        module.add(self.parser.module)
        names = dynamic.related_names(definitions, search_name, module)

        for d in set(definitions):
            if isinstance(d, parsing.Module):
                names.append(api_classes.RelatedName(d, d))
            else:
                names.append(api_classes.RelatedName(d.names[0], d))

        return sorted(set(names), key=lambda x: (x.module_path, x.start_pos),
                                                                reverse=True)
Exemple #2
0
    def related_names(self, additional_module_paths=[]):
        """
        Returns `dynamic.RelatedName` objects, which contain all names, that
        are defined by the same variable, function, class or import.
        This function can be used either to show all the usages of a variable
        or for renaming purposes.

        TODO implement additional_module_paths
        """
        user_stmt = self.parser.user_stmt
        definitions, search_name = self._goto(add_import_name=True)
        if isinstance(user_stmt, parsing.Statement) \
                    and self.pos < user_stmt.get_assignment_calls().start_pos:
            # the search_name might be before `=`
            definitions = [
                v for v in user_stmt.set_vars if str(v) == search_name
            ]
        if not isinstance(user_stmt, parsing.Import):
            # import case is looked at with add_import_name option
            definitions = dynamic.related_name_add_import_modules(
                definitions, search_name)

        module = set([d.get_parent_until() for d in definitions])
        module.add(self.parser.module)
        names = dynamic.related_names(definitions, search_name, module)

        for d in set(definitions):
            if isinstance(d, parsing.Module):
                names.append(api_classes.RelatedName(d, d))
            else:
                names.append(api_classes.RelatedName(d.names[0], d))

        return sorted(set(names),
                      key=lambda x: (x.module_path, x.start_pos),
                      reverse=True)
Exemple #3
0
    def related_names(self, additional_module_paths=()):
        """
        Return :class:`api_classes.RelatedName` objects, which contain all
        names that point to the definition of the name under the cursor. This
        is very useful for refactoring (renaming), or to show all usages of a
        variable.

        .. todo:: Implement additional_module_paths

        :rtype: list of :class:`api_classes.RelatedName`
        """
        user_stmt = self._parser.user_stmt
        definitions, search_name = self._goto(add_import_name=True)
        if isinstance(user_stmt, pr.Statement) \
                    and self.pos < user_stmt.get_commands()[0].start_pos:
            # the search_name might be before `=`
            definitions = [v for v in user_stmt.set_vars
                                if unicode(v.names[-1]) == search_name]
        if not isinstance(user_stmt, pr.Import):
            # import case is looked at with add_import_name option
            definitions = dynamic.related_name_add_import_modules(definitions,
                                                                search_name)

        module = set([d.get_parent_until() for d in definitions])
        module.add(self._parser.module)
        names = dynamic.related_names(definitions, search_name, module)

        for d in set(definitions):
            if isinstance(d, pr.Module):
                names.append(api_classes.RelatedName(d, d))
            else:
                names.append(api_classes.RelatedName(d.names[-1], d))

        return self._sorted_defs(set(names))
Exemple #4
0
    def related_names(self, additional_module_paths=[]):
        """
        Return :class:`api_classes.RelatedName` objects, which contain all
        names that point to the definition of the name under the cursor. This
        is very useful for refactoring (renaming), or to show all usages of a
        variable.

        .. todo:: Implement additional_module_paths

        :rtype: list of :class:`api_classes.RelatedName`
        """
        user_stmt = self._parser.user_stmt
        definitions, search_name = self._goto(add_import_name=True)
        if isinstance(user_stmt, parsing.Statement) \
                    and self.pos < user_stmt.get_assignment_calls().start_pos:
            # the search_name might be before `=`
            definitions = [v for v in user_stmt.set_vars
                                if unicode(v.names[-1]) == search_name]
        if not isinstance(user_stmt, parsing.Import):
            # import case is looked at with add_import_name option
            definitions = dynamic.related_name_add_import_modules(definitions,
                                                                search_name)

        module = set([d.get_parent_until() for d in definitions])
        module.add(self._parser.module)
        names = dynamic.related_names(definitions, search_name, module)

        for d in set(definitions):
            if isinstance(d, parsing.Module):
                names.append(api_classes.RelatedName(d, d))
            else:
                names.append(api_classes.RelatedName(d.names[-1], d))

        return sorted(set(names), key=lambda x: (x.module_path, x.start_pos))