コード例 #1
0
 def _process_normalizing(self, repair_path, intermediate_result, input_file, output_file):
     normalizer = IncludeDirectiveNormalizer(DefaultProjectFile(path_rel_to_root_unix=repair_path, 
             local_repository_root=self._local_source_resource_resolver.get_base_paths()[0]), 
                                             self._include_canonicalizer_factory,
                                             filemap_factory_func=self._filemap_factory.get_filemap)
     LineByLineProcessor(transform_func=normalizer.normalize).process_file(input_file, output_file)
     return (normalizer.get_included_files(), normalizer.get_statistics_dict())
コード例 #2
0
def RepairingIndividualFileRepairProcessor(local_source_resource_resolver,
                                           generation_strategy,
                                           is_implementation_file_func,
                                           required_include_files_calculator,
                                           include_list_generator_factory):
    assert isinstance_or_duck(required_include_files_calculator,
                              RequiredIncludeFilesCalculator)
    prepare_func = lambda repair_path_rel_to_root_unix, input_resource: required_include_files_calculator.calculate_required_include_files(
        project_file=DefaultProjectFile(
            path_rel_to_root_unix=repair_path_rel_to_root_unix,
            #module_name,
            local_repository_root=input_resource.get_resolution_root(),
            resource=input_resource))

    file_normalizer = BaseFileNormalizer(
        is_implementation_file_func=is_implementation_file_func,
        include_list_generator_factory=include_list_generator_factory)
    process_func = lambda repair_path, intermediate_result, input_file, output_file: file_normalizer.process(
        repair_path=repair_path,
        included_paths=intermediate_result,
        input_file=input_file,
        output_file=output_file)
    return IndividualCppFileTransformer(
        local_source_resource_resolver=local_source_resource_resolver,
        generation_strategy=generation_strategy,
        prepare_func=prepare_func,
        process_func=process_func)
コード例 #3
0
 def test4(self):
     normalizer = IncludeDirectiveNormalizer(
         DefaultProjectFile(path_rel_to_root_unix="a/b.cpp",
                            local_repository_root="/test",
                            path_module=posixpath),
         include_canonicalizer_factory=self.
         __create_include_path_canonicalizer_factory())
     test_str = r'#include "..\x.h"\n'
     self.assertEquals('#include "x.h"\n', normalizer.normalize(test_str))
コード例 #4
0
 def testOneSymbol(self, UsedSymbolsListerMock, HeaderListerMock):
     used_symbols_lister = cpp.incl_deps.repair_includes_if.UsedSymbolsLister()
     used_symbols_lister.get_symbol_candidates.return_value = dict({'test_id': 'test'}) 
     header_lister = cpp.incl_deps.repair_includes_if.HeaderLister()
     header_lister.map_symbol_ids_to_headers.return_value = set(('test.h', ))
     is_implementation_file_func = lambda x: True
     resource_resolver = None
     testee = TwoPhaseRequiredIncludeFilesCalculator(used_symbols_lister, header_lister, is_implementation_file_func, resource_resolver)
     local_root = os.path.dirname(os.tempnam())
     test_file = DefaultProjectFile(path_rel_to_root_unix="a.cpp", local_repository_root=local_root, resource=None)
     self.assertEquals(set(('test.h', )), set(testee.calculate_required_include_files(test_file)))
     self.assertTrue(used_symbols_lister.get_symbol_candidates.called)
     self.assertEquals([((['test_id'], test_file),)], header_lister.map_symbol_ids_to_headers.call_args_list)
コード例 #5
0
 def _process_normalizing(self, repair_path, intermediate_result, input_file, output_file):
     normalizer = IncludeDirectiveNormalizer(DefaultProjectFile(path_rel_to_root_unix=repair_path, 
             local_repository_root=self._local_source_resource_resolver.get_base_paths()[0]), 
                                             self._include_canonicalizer_factory,
                                             filemap_factory_func=self._filemap_factory.get_filemap)
     comment_filter = CommentFilter()
     if self.__skip_comments:
         filtered_input_file = comment_filter.filter(input_file)
     else:
         filtered_input_file = input_file
     for line in filtered_input_file:
         include_spec = normalizer.get_include_specification(line)
         if include_spec:
             (_include_spec_type, included_resource) = include_spec
             # TODO output rel_to_root if under root
             print >>self.__output_file, "%s,%s" % (repair_path, included_resource.name())
     return (normalizer.get_included_files(), normalizer.get_statistics_dict())
コード例 #6
0
 def _process_normalizing(self, repair_path, intermediate_result, input_file, output_file):
     normalizer = IncludeDirectiveNormalizer(DefaultProjectFile(path_rel_to_root_unix=repair_path, 
             local_repository_root=self._local_source_resource_resolver.get_base_paths()[0]), 
                                             self._include_canonicalizer_factory,
                                             filemap_factory_func=self._filemap_factory.get_filemap)
     # TODO or only create the iterator here? But this would not allow to return the statistics...
     if self.__skip_comments:
         comment_filter = CommentFilter()
         filtered_input_file = comment_filter.filter(input_file)
     else:
         filtered_input_file = input_file
     self.__include_map[repair_path] = tuple(ifilter(None, imap(normalizer.get_include_specification, filtered_input_file)))
     
     statistics_dict = normalizer.get_statistics_dict()
     if self.__skip_comments:
         DictTools.merge_dict(statistics_dict, comment_filter.get_statistics_dict(), value_merge_func=None)
     self.__logger.debug("%s includes files %s" % (repair_path, tuple(normalizer.get_included_files())))
     return (normalizer.get_included_files(), statistics_dict)