def test_unreferenced_reference_by_process(self):
        ast = self.create_ast(Fixtures.MISS_DECLARATION)

        declarative_id_node = ast['body'][0]['left']

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertFalse(is_referenced_declarative_identifier(declarative_id_node))
    def test_referenced_function_reference_by_process(self):
        ast = self.create_ast(Fixtures.FUNCTION_REF)

        declarative_variable_node = ast['body'][0]['left']

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertTrue(is_referenced_declarative_identifier(declarative_variable_node))
    def test_builtin_reference_by_process(self):
        ast = self.create_ast(Fixtures.BUILTIN)

        ref_id_node = ast['body'][0]['left']['left']

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertTrue(is_reachable_reference_identifier(ref_id_node))
    def test_referenced_variable_by_process(self):
        ast = self.create_ast(Fixtures.DECLARING_AND_REFERENCING)

        declarative_id_node = ast['body'][0]['left']

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertTrue(is_referenced_declarative_identifier(declarative_id_node))
    def test_unreachable_reference_by_process(self):
        ast = self.create_ast(Fixtures.MISS_DECLARATION)

        ref_id_node = ast["body"][1]["left"]["left"]

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertFalse(is_reachable_reference_identifier(ref_id_node))
    def test_reachable_reference_by_process(self):
        ast = self.create_ast(Fixtures.DECLARING_AND_REFERENCING)

        ref_id_node = ast["body"][1]["left"]["left"]

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertTrue(is_reachable_reference_identifier(ref_id_node))
    def test_referenced_variable_reference_by_process(self):
        ast = self.create_ast(Fixtures.SAME_NAME_FUNCTION_AND_REFERENCE)

        declarative_variable_node = ast["body"][0]["left"]
        declarative_function_node = ast["body"][1]["left"]

        tester = ReferenceReachabilityTester()
        tester.process(ast)

        self.assertTrue(is_referenced_declarative_identifier(declarative_variable_node))
        self.assertFalse(is_referenced_declarative_identifier(declarative_function_node))
示例#8
0
文件: __init__.py 项目: rhysd/vint
class ScopePlugin(object):
    def __init__(self):
        self._ref_tester = ReferenceReachabilityTester()

    def process(self, ast):
        processed_ast = self._ref_tester.process(ast)
        return processed_ast

    def _get_link_registry(self):
        # NOTE: This is a hack for performance. We should build LinkRegistry
        # by this method if ReferenceReachabilityTester hide the link_registry.
        return self._ref_tester._link_registry

    def is_unreachable_reference_identifier(self, node):
        return _is_reference_identifier(node) and not _is_reachable_reference_identifier(node)

    def is_unused_declarative_identifier(self, node):
        return _is_declarative_identifier(node) and not _is_referenced_declarative_identifier(node)

    def is_autoload_identifier(self, node):
        return _is_autoload_identifier(node)

    def get_objective_scope_visibility(self, node):
        link_registry = self._get_link_registry()
        context_scope = link_registry.get_context_scope_by_identifier(node)
        scope_visibility_hint = _detect_scope_visibility(node, context_scope)
        return scope_visibility_hint["scope_visibility"]

    def get_explicity_of_scope_visibility(self, node):
        return _get_explicity_of_scope_visibility(node)

    def normalize_variable_name(self, node):
        link_registry = self._get_link_registry()
        context_scope = link_registry.get_context_scope_by_identifier(node)
        return _normalize_variable_name(node, context_scope)
示例#9
0
文件: __init__.py 项目: aiya000/vint
class ScopePlugin(AbstractASTPlugin):
    def __init__(self):
        super(ScopePlugin, self).__init__()
        self._ref_tester = ReferenceReachabilityTester()


    def process(self, ast):
        processed_ast = self._ref_tester.process(ast)
        return processed_ast


    def _get_link_registry(self):
        # NOTE: This is a hack for performance. We should build LinkRegistry
        # by this method if ReferenceReachabilityTester hide the link_registry.
        return self._ref_tester._scope_linker.link_registry


    def is_unreachable_reference_identifier(self, node):
        return _is_reference_identifier(node) \
            and not _is_reachable_reference_identifier(node)


    def is_unused_declarative_identifier(self, node):
        return _is_declarative_identifier(node) \
            and not _is_referenced_declarative_identifier(node)


    def is_autoload_identifier(self, node):
        return _is_autoload_identifier(node)


    def is_function_identifier(self, node):
        return _is_function_identifier(node)


    def get_objective_scope_visibility(self, node):
        scope_visibility_hint = self._ref_tester.get_objective_scope_visibility(node)
        return scope_visibility_hint.scope_visibility


    def get_explicity_of_scope_visibility(self, node):
        scope_visibility_hint = self._ref_tester.get_objective_scope_visibility(node)
        return scope_visibility_hint.explicity


    def normalize_variable_name(self, node):
        return _normalize_variable_name(node, self._ref_tester)
示例#10
0
 def __init__(self):
     super(ScopePlugin, self).__init__()
     self._ref_tester = ReferenceReachabilityTester()
示例#11
0
文件: __init__.py 项目: rhysd/vint
 def __init__(self):
     self._ref_tester = ReferenceReachabilityTester()
示例#12
0
文件: __init__.py 项目: Kuniwak/vint
 def __init__(self):
     super(ScopePlugin, self).__init__()
     self._ref_tester = ReferenceReachabilityTester()