Skip to content

Commit 15c7a90

Browse files
committed
Code cleanup: fixed RubyMine's warnings
1 parent 1ca1c33 commit 15c7a90

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def print_contexts(contexts)
9191
end
9292

9393
def print_context(context)
94-
current = 'current="yes"' if context.thread == Thread.current
95-
print "<thread id=\"%s\" status=\"%s\" pid=\"%s\" #{current}/>", context.thnum, context.thread.status, Process.pid
94+
print "<thread id=\"%s\" status=\"%s\" pid=\"%s\" #{current_thread_attr}/>", context.thnum, context.thread.status, Process.pid
9695
end
9796

9897
def print_variables(vars, kind)
@@ -147,28 +146,29 @@ def print_variable(name, value, kind)
147146
end
148147
if value.is_a?(Array) || value.is_a?(Hash)
149148
has_children = !value.empty?
150-
unless has_children
151-
value_str = "Empty #{value.class}"
152-
else
153-
size = value.size
149+
if has_children
150+
size = value.size
154151
value_str = "#{value.class} (#{value.size} element#{size > 1 ? "s" : "" })"
152+
else
153+
value_str = "Empty #{value.class}"
155154
end
156155
elsif value.is_a?(String)
157156
has_children = value.respond_to?('bytes') || value.respond_to?('encoding')
158157
value_str = value
159158
else
160159
has_children = !value.instance_variables.empty? || !value.class.class_variables.empty?
161-
value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #$!>"
160+
value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #{$!}>"
162161
unless value_str.is_a?(String)
163162
value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String."
164163
end
165164
end
166165

167166
if value_str.respond_to?('encode')
167+
# noinspection RubyEmptyRescueBlockInspection
168168
begin
169169
value_str = value_str.encode("UTF-8")
170170
rescue
171-
end
171+
end
172172
end
173173
value_str = handle_binary_data(value_str)
174174
compact_value_str = build_compact_name(value_str, value)
@@ -189,7 +189,7 @@ def build_compact_name(value_str, value)
189189
end
190190
end
191191
if value.is_a?(Hash)
192-
slice = value.sort_by { |k,v| k.to_s }[0..5]
192+
slice = value.sort_by { |k, _| k.to_s }[0..5]
193193
compact = slice.map {|kv| "#{kv[0]}: #{handle_binary_data(kv[1])}"}.join(", ")
194194
compact = "{" + compact + (slice.size != value.size ? ", ..." : "") + "}"
195195
end
@@ -255,7 +255,7 @@ def print_pp(value)
255255

256256
def print_list(b, e, file, line)
257257
print "[%d, %d] in %s\n", b, e, file
258-
if lines = Debugger.source_for(file)
258+
if (lines = Debugger.source_for(file))
259259
b.upto(e) do |n|
260260
if n > 0 && lines[n-1]
261261
if n == line
@@ -266,7 +266,7 @@ def print_list(b, e, file, line)
266266
end
267267
end
268268
else
269-
print "No sourcefile available for %s\n", file
269+
print "No source-file available for %s\n", file
270270
end
271271
end
272272

@@ -280,7 +280,7 @@ def print_methods(methods)
280280

281281
# Events
282282

283-
def print_breakpoint(n, breakpoint)
283+
def print_breakpoint(_, breakpoint)
284284
print("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%d\"/>",
285285
breakpoint.source, breakpoint.pos, Debugger.current_context.thnum)
286286
end
@@ -302,7 +302,7 @@ def print_at_line(context, file, line)
302302
File.expand_path(file), line, context.thnum, context.stack_size
303303
end
304304

305-
def print_exception(exception, binding)
305+
def print_exception(exception, _)
306306
print_element("variables") do
307307
proxy = ExceptionProxy.new(exception)
308308
InspectCommand.reference_result(proxy)
@@ -349,6 +349,14 @@ def handle_binary_data(value)
349349
value
350350
end
351351

352+
def current_thread_attr
353+
if context.thread == Thread.current
354+
'current="yes"'
355+
else
356+
''
357+
end
358+
end
359+
352360
instance_methods.each do |m|
353361
if m.to_s.index('print_') == 0
354362
protect m

0 commit comments

Comments
 (0)