Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: EPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Eclipse Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.eclipse.org/legal/epl-v10.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2004 Jan Arne Petersen <jpetersen@uni-bonn.de> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the EPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the EPL, the GPL or the LGPL. END LICENSE BLOCK ***
 
 package org.jruby.common;
 
 import org.jruby.Ruby;
 
 import java.util.Set;

 
 public class RubyWarnings implements IRubyWarningsWarnCallback {
     private final Ruby runtime;
     private final Set<IDoncelers = new HashSet<ID>();
 
     public RubyWarnings(Ruby runtime) {
         this. = runtime;
     }
 
     public void warn(String message) {
         warn(.message);
     }
 
     public Ruby getRuntime() {
         return ;
     }
 
     public boolean isVerbose() {
         return .isVerbose();
     }

    
Prints a warning, unless $VERBOSE is nil.
 
     public void warn(ID idISourcePosition positionString message) {
         if (!.warningsEnabled()) return;
 
         warn(idposition.getFile(), position.getStartLine(), message);
     }

    
Prints a warning, unless $VERBOSE is nil.
 
     public void warn(ID idString fileNameint lineNumberString message) {
         if (!.warningsEnabled()) return;
 
         StringBuilder buffer = new StringBuilder(100);
 
         buffer.append(fileName).append(':').append(lineNumber + 1).append(' ');
         buffer.append("warning: ").append(message).append('\n');
         IRubyObject errorStream = .getGlobalVariables().get("$stderr");
         errorStream.callMethod(.getCurrentContext(), "write".newString(buffer.toString()));
     }
 
     public void warn(ID idString message) {
         if (!.warningsEnabled()) return;
 
         RubyStackTraceElement[] stack = getRubyStackTrace();
         String file;
         int line;
 
         if (stack.length == 0) {
             file = "(unknown)";
             line = -1;
         } else {
             file = stack[0].getFileName();
            line = stack[0].getLineNumber();
        }
        warn(idfilelinemessage);
    }
    
    public void warnOnce(ID idString message) {
        if (!.warningsEnabled()) return;
        if (.contains(id)) return;
        .add(id);
        warn(idmessage);
    }

    
Verbose mode warning methods, their contract is that consumer must explicitly check for runtime.isVerbose() before calling them
    public void warning(String message) {
        if (!.warningsEnabled()) return;
        warning(.message);
    }
    public void warning(ID idString message) {
        if (!.warningsEnabled()) return;
        RubyStackTraceElement[] stack = getRubyStackTrace();
        String file;
        int line;
        if (stack.length == 0) {
            file = "(unknown)";
            line = -1;
        } else {
            file = stack[0].getFileName();
            line = stack[0].getLineNumber();
        }
        warning(idfilelinemessage);
    }

    
Prints a warning, only in verbose mode.
    public void warning(ID idISourcePosition positionString message) {
        if (!.warningsEnabled()) return;
        warning(idposition.getFile(), position.getStartLine(), message);
    }

    
Prints a warning, only in verbose mode.
    public void warning(ID idString fileNameint lineNumberString message) {
        assert isVerbose();
        if (!.warningsEnabled()) return;
        warn(idfileNamelineNumbermessage);
    }
    private static RubyStackTraceElement[] getRubyStackTrace(Ruby runtime) {
        ThreadContext context = runtime.getCurrentContext();
        RubyStackTraceElement[] stack = context.createWarningBacktrace(runtime);
        return stack;
    }
    @Deprecated
    public void warn(ID idISourcePosition positionString messageObject... data) {
        warn(idposition.getFile(), position.getStartLine(), messagedata);
    }
    @Deprecated
    public void warn(ID idString fileNameint lineNumberString messageObject... data) {
        if (!.warningsEnabled()) return// TODO make an assert here
        StringBuilder buffer = new StringBuilder(100);
        buffer.append(fileName).append(':').append(lineNumber + 1).append(' ');
        buffer.append("warning: ").append(message).append('\n');
        IRubyObject errorStream = .getGlobalVariables().get("$stderr");
        errorStream.callMethod(.getCurrentContext(), "write".newString(buffer.toString()));
    }
    @Deprecated
    public void warn(ID idString messageObject... data) {
        ThreadContext context = .getCurrentContext();
        warn(idcontext.getFile(), context.getLine(), messagedata);
    }
    @Deprecated
    public void warning(String messageObject... data) {
        warning(.messagedata);
    }
    @Deprecated
    public void warning(ID idString messageObject... data) {
        ThreadContext context = .getCurrentContext();
        warning(idcontext.getFile(), context.getLine(), messagedata);
    }
    @Deprecated
    public void warning(ID idISourcePosition positionString messageObject... data) {
        warning(idposition.getFile(), position.getStartLine(), messagedata);
    }
    @Deprecated
    public void warning(ID idString fileNameint lineNumberString messageObject... data) {
        assert isVerbose(); 
        warn(idfileNamelineNumbermessagedata);
    }
New to GrepCode? Check out our FAQ X