

def organize_step_five(self):
    StatusManager().show_status('Organizing imports...', delay=(- 1), ref='organize_imports')
    ActionHistory().add_action(('javatar.commands.operations' + '.organize_imports.organize_step_six'), 'Organize Imports Step 5 - Organize the imports')
    current_package = JavaUtils().to_package(StateProperty().get_dir())
    import_code = ''
    if (not current_package.is_empty()):
        import_code += (('package ' + current_package.as_class_path()) + ';')
    import_code += '\n\n'
    package_declarations = JavaStructure().package_declarations_in_file(self.view.file_name())
    import_start = 0
    import_end = 0
    if (len(package_declarations) > 0):
        import_start = package_declarations[0]['begin']
        import_end = package_declarations[(- 1)]['end']
    if (len(self.import_nodes) > 0):
        import_end = self.import_nodes[(- 1)]['end']
    while re.search('\\s', self.view.substr(sublime.Region(import_end, (import_end + 1)))):
        import_end += 1
    imported_classes = []
    for class_path in self.importedTypes:
        cl_path = JavaClassPath(class_path)
        cl_package = cl_path.get_package().as_class_path()
        local_package = current_package.as_class_path()
        if (class_path.startswith('java.lang.') or (cl_package == local_package)):
            continue
        if ((cl_path.get_class().get() in self.useTypes) and (not cl_path.get_package().is_empty())):
            imported_classes.append(class_path)
    imported_classes.sort()
    first = True
    for class_path in imported_classes:
        if (not first):
            import_code += '\n'
        import_code += ('import %s;' % class_path)
        first = False
    if import_code:
        import_code += '\n\n'
        self.view.run_command('javatar_utils', {
            'util_type': 'replace',
            'region': [import_start, import_end],
            'text': import_code,
            'dest': 'Organize Imports',
        })
    StatusManager().hide_status('organize_imports')
    sublime.set_timeout((lambda : StatusManager().show_status('Imports has been organized')), 500)

dataset/ETHPy150Open spywhere/Javatar/commands/operations/organize_imports.py JavatarOrganizeImports.organize_step_five/original