Skip to content

Commit e0629a3

Browse files
committed
[refactor] cleanup Java code (warnings) a bit
1 parent db4e8f7 commit e0629a3

File tree

3 files changed

+19
-38
lines changed

3 files changed

+19
-38
lines changed

src/main/java/org/jruby/rack/RackException.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*
1414
* @author kares
1515
*/
16-
@SuppressWarnings("serial")
1716
public class RackException extends RuntimeException {
1817

1918
public RackException(String message) {
@@ -57,9 +56,7 @@ static String exceptionMessage(final RaiseException e) {
5756
st.append(b.toString());
5857
return st.toString();
5958
}
60-
else {
61-
return null;
62-
}
59+
return null;
6360
}
6461

6562
}

src/main/java/org/jruby/rack/ext/Logger.java

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,8 @@ private void initialize(final IRubyObject context) {
109109
if ( context instanceof RackLogger ) {
110110
this.logger = (RackLogger) context;
111111
}
112-
else if ( context instanceof RackContext ) {
113-
this.logger = ((RackContext) context).getConfig().getLogger();
114-
}
115112
else {
116-
this.logger = (RackLogger) context.toJava(RackLogger.class);
113+
this.logger = context.toJava(RackLogger.class);
117114
}
118115
}
119116

@@ -285,8 +282,7 @@ public IRubyObject debug(final ThreadContext context,
285282
// See #add.
286283
//
287284
@JRubyMethod(name = "info")
288-
public IRubyObject info(final ThreadContext context,
289-
final IRubyObject msg, final Block block) {
285+
public IRubyObject info(final ThreadContext context, final IRubyObject msg, final Block block) {
290286
return context.runtime.newBoolean( add(INFO, context, msg, block) );
291287
}
292288

@@ -299,8 +295,7 @@ public IRubyObject info(final ThreadContext context, final Block block) {
299295
// Log a +WARN+ message.
300296
//
301297
@JRubyMethod(name = "warn")
302-
public IRubyObject warn(final ThreadContext context,
303-
final IRubyObject msg, final Block block) {
298+
public IRubyObject warn(final ThreadContext context, final IRubyObject msg, final Block block) {
304299
return context.runtime.newBoolean( add(WARN, context, msg, block) );
305300
}
306301

@@ -313,8 +308,7 @@ public IRubyObject warn(final ThreadContext context, final Block block) {
313308
// Log a +ERROR+ message.
314309
//
315310
@JRubyMethod(name = "error")
316-
public IRubyObject error(final ThreadContext context,
317-
final IRubyObject msg, final Block block) {
311+
public IRubyObject error(final ThreadContext context, final IRubyObject msg, final Block block) {
318312
return context.runtime.newBoolean( add(ERROR, context, msg, block) );
319313
}
320314

@@ -327,8 +321,7 @@ public IRubyObject error(final ThreadContext context, final Block block) {
327321
// Log a +FATAL+ message.
328322
//
329323
@JRubyMethod(name = "fatal")
330-
public IRubyObject fatal(final ThreadContext context,
331-
final IRubyObject msg, final Block block) {
324+
public IRubyObject fatal(final ThreadContext context, final IRubyObject msg, final Block block) {
332325
return context.runtime.newBoolean( add(FATAL, context, msg, block) );
333326
}
334327

@@ -342,9 +335,7 @@ public IRubyObject fatal(final ThreadContext context, final Block block) {
342335
// This will be printed no matter what the logger's level is.
343336
//
344337
@JRubyMethod(name = "unknown")
345-
public IRubyObject unknown(final ThreadContext context,
346-
final IRubyObject msg, final Block block) {
347-
// NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
338+
public IRubyObject unknown(final ThreadContext context, final IRubyObject msg, final Block block) {
348339
return context.runtime.newBoolean( add(UNKNOWN, context, msg, block) );
349340
}
350341

@@ -375,10 +366,8 @@ public IRubyObject add(final ThreadContext context,
375366

376367
// def add(severity, message = nil, progname = nil, &block)
377368
@JRubyMethod(name = "add")
378-
public IRubyObject add(final ThreadContext context,
379-
final IRubyObject severity, final IRubyObject msg,
380-
final IRubyObject progname, final Block block) {
381-
// NOTE possibly - "somehow" support UNKNOWN in RackLogger ?!
369+
public IRubyObject add(final ThreadContext context, final IRubyObject severity,
370+
final IRubyObject msg, final IRubyObject progname, final Block block) {
382371
return context.runtime.newBoolean( add(UNKNOWN, context, msg, block) );
383372
}
384373

@@ -431,17 +420,16 @@ public IRubyObject append(final ThreadContext context, final IRubyObject msg) {
431420
// private
432421

433422
@JRubyMethod(visibility = Visibility.PRIVATE, required = 4)
434-
public IRubyObject format_message(final ThreadContext context,
435-
final IRubyObject[] args) {
423+
public IRubyObject format_message(final ThreadContext context, final IRubyObject[] args) {
436424
if ( formatter instanceof RubyProc ) {
437425
return ((RubyProc) formatter).call(context, args);
438426
}
439427
return formatter.callMethod(context, "call", args);
440428
}
441429

442430
private IRubyObject format_message(final ThreadContext context,
443-
final int severityVal, final long datetimeMillis,
444-
final IRubyObject progname, final IRubyObject msg) {
431+
final int severityVal, final long datetimeMillis,
432+
final IRubyObject progname, final IRubyObject msg) {
445433
final IRubyObject severity =
446434
RubyString.newStringShared(context.runtime, formatSeverity(severityVal));
447435
final RubyTime datetime = RubyTime.newTime(context.runtime, datetimeMillis);
@@ -493,9 +481,9 @@ private static String formatSeverity(final int severity) {
493481
// RackLogger
494482

495483
@Override
496-
public Object toJava(Class target) {
484+
public <T> T toJava(Class<T> target) {
497485
// NOTE: maybe this is not a good idea ?!
498-
if ( RackLogger.class == target ) return logger;
486+
if ( RackLogger.class == target ) return (T) logger;
499487
return super.toJava(target);
500488
}
501489

@@ -563,14 +551,12 @@ public IRubyObject silence(final ThreadContext context, final Block block) {
563551
}
564552

565553
@JRubyMethod(name = "silence", required = 1)
566-
public IRubyObject silence(final ThreadContext context,
567-
final IRubyObject temp_level, final Block block) {
554+
public IRubyObject silence(final ThreadContext context, final IRubyObject temp_level, final Block block) {
568555
final int tempLevel = (int) temp_level.convertToInteger("to_i").getLongValue();
569556
return doSilence(tempLevel, context, block);
570557
}
571558

572-
private IRubyObject doSilence(final int tempLevel,
573-
final ThreadContext context, final Block block) {
559+
private IRubyObject doSilence(final int tempLevel, final ThreadContext context, final Block block) {
574560
if ( silencer ) {
575561
try { // not implemented - on purpose!
576562
return block.yield(context, this);
@@ -607,7 +593,7 @@ protected ServletLog(Ruby runtime, RubyClass metaClass) {
607593
super(runtime, metaClass);
608594
}
609595

610-
@JRubyMethod(required = 0, optional = 1)
596+
@JRubyMethod(optional = 1)
611597
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
612598
final IRubyObject rackContext;
613599
if ( args != null && args.length > 0 ) rackContext = args[0];
@@ -623,8 +609,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
623609
}
624610
else {
625611
try {
626-
RackLogger logger = (RackLogger) rackContext.toJava(RackLogger.class);
627-
this.context = logger;
612+
this.context = rackContext.toJava(RackLogger.class);
628613
}
629614
catch (RaiseException e) { // TypeError
630615
final IRubyObject error = e.getException();
@@ -633,7 +618,7 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
633618
}
634619
// support passing in a ServletContext instance (for convenience) :
635620
try {
636-
ServletContext servletContext = (ServletContext) rackContext.toJava(ServletContext.class);
621+
ServletContext servletContext = rackContext.toJava(ServletContext.class);
637622
this.context = new ServletContextLogger(servletContext);
638623
}
639624
catch (RaiseException fail) {

src/main/java/org/jruby/rack/ext/RackLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737
public class RackLibrary implements Library, BasicLibraryService {
3838

39-
@SuppressWarnings("deprecation")
4039
public static void load(final Ruby runtime) {
4140
final RubyModule _JRuby = runtime.getOrCreateModule("JRuby");
4241
final RubyModule _JRuby_Rack = _JRuby.defineModuleUnder("Rack");

0 commit comments

Comments
 (0)