def apply_to_rewrite_cursor(self, rewrite_cursor): import_clause = ScalaImportParser.search(rewrite_cursor) while import_clause is not None: rewritten_clauses = self.apply_rewrite(import_clause) if rewritten_clauses is None: # Spit out the original text, with any wrapping, whitespace or other idiosyncracies it may have. This makes # sure that We only modify files where needed, and not just because of such non-germane differences. rewrite_cursor.emit(import_clause.src_text) else: new_text = '\n'.join([repr(x) for x in rewritten_clauses]) + '\n' rewrite_cursor.emit(new_text) import_clause = ScalaImportParser.search(rewrite_cursor)
def apply_to_rewrite_cursor(self, rewrite_cursor): import_clause = ScalaImportParser.search(rewrite_cursor) while import_clause is not None: rewritten_clauses = self.apply_rewrite(import_clause) if rewritten_clauses is None: # Spit out the original text, with any wrapping, whitespace or other idiosyncracies it may have. This makes # sure that We only modify files where needed, and not just because of such non-germane differences. rewrite_cursor.emit(import_clause.src_text) else: new_text = '\n'.join([repr(x) for x in rewritten_clauses]) + '\n' rewrite_cursor.emit(new_text) import_clause = ScalaImportParser.search(rewrite_cursor)
def apply_to_rewrite_cursor(self, rewrite_cursor): # Search for the first import in the first import block. import_clause = ScalaImportParser.search(rewrite_cursor) while import_clause is not None: import_block = [] num_blank_lines = 0 while import_clause is not None: # Note that we don't care about blank lines in the middle of an import block, we only emit ones after the # end of a block. num_blank_lines = self.skip_blank_lines(rewrite_cursor) import_block.append(import_clause) import_clause = ScalaImportParser.match(rewrite_cursor) # Note use of match, not search. # We're on the first non-import, non-blank line after an import block, or at the end of the text. processed_imports = self._process_import_block(import_block) rewrite_cursor.emit(processed_imports) rewrite_cursor.emit('\n' * num_blank_lines) # Search for the first import in the next block. import_clause = ScalaImportParser.search(rewrite_cursor)
def apply_to_rewrite_cursor(self, rewrite_cursor): # Search for the first import in the first import block. import_clause = ScalaImportParser.search(rewrite_cursor) while import_clause is not None: import_block = [] num_blank_lines = 0 while import_clause is not None: # Note that we don't care about blank lines in the middle of an import block, we only emit ones after the # end of a block. num_blank_lines = self.skip_blank_lines(rewrite_cursor) import_block.append(import_clause) import_clause = ScalaImportParser.match(rewrite_cursor) # Note use of match, not search. # We're on the first non-import, non-blank line after an import block, or at the end of the text. processed_imports = self._process_import_block(import_block) rewrite_cursor.emit(processed_imports) rewrite_cursor.emit('\n' * num_blank_lines) # Search for the first import in the next block. import_clause = ScalaImportParser.search(rewrite_cursor)