# encoding: utf-8 module Synvert::Core # Instance is an execution unit, it finds specified ast nodes, # checks if the nodes match some conditions, then add, replace or remove code. # # One instance can contains one or many [Synvert::Core::Rewriter::Scope] and [Synvert::Rewriter::Condition]. class Rewriter::Instance class < -1 if begin_pos <= @actions[j].end_pos @conflict_actions << @actions.delete_at(j) else i = j begin_pos = @actions[i].begin_pos end j -= 1 end @conflict_actions end # It checks if code is removed and that line is empty. # # @param source [String] source code of file # @param line [String] the line number def remove_code_or_whole_line(source, line) newline_at_end_of_line = source[-1] == "\n" source_arr = source.split("\n") if source_arr[line - 1] && source_arr[line - 1].strip.empty? source_arr.delete_at(line - 1) if source_arr[line - 2] && source_arr[line - 2].strip.empty? && source_arr[line - 1] && source_arr[line - 1].strip.empty? source_arr.delete_at(line - 1) end source_arr.join("\n") + (newline_at_end_of_line ? "\n" : '') else source end end end end