1 28 package org.jruby.common; 29 30 import org.jruby.Ruby; 31 import org.jruby.lexer.yacc.ISourcePosition; 32 import org.jruby.runtime.builtin.IRubyObject; 33 34 37 public class RubyWarnings implements IRubyWarnings { 38 private Ruby runtime; 39 40 public RubyWarnings(Ruby runtime) { 41 this.runtime = runtime; 42 } 43 44 public void warn(ISourcePosition position, String message) { 45 assert position != null; 46 47 if(runtime.getVerbose().isNil()) { 48 return; 49 } 50 51 StringBuffer buffer = new StringBuffer (100); 52 53 buffer.append(position.getFile()).append(':').append(position.getEndLine()).append(' '); 54 buffer.append("warning: ").append(message).append('\n'); 55 IRubyObject errorStream = runtime.getGlobalVariables().get("$stderr"); 56 errorStream.callMethod(runtime.getCurrentContext(), "write", runtime.newString(buffer.toString())); 57 } 58 59 public boolean isVerbose() { 60 return runtime.getVerbose().isTrue(); 61 } 62 63 public void warn(String message) { 64 warn(runtime.getCurrentContext().getPosition(), message); 65 } 66 67 public void warning(String message) { 68 warning(runtime.getCurrentContext().getPosition(), message); 69 } 70 71 public void warning(ISourcePosition position, String message) { 72 if (isVerbose()) { 73 warn(position, message); 74 } 75 } 76 } 77 | Popular Tags |