Skip to content

Commit

Permalink
Dump warning by Kernel.warn only one time
Browse files Browse the repository at this point in the history
For SAFE_NOT_SUPPORTED warning.
  • Loading branch information
Hiroshi Nakamura committed Aug 9, 2011
1 parent 6e5b660 commit 70b90c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/org/jruby/common/IRubyWarnings.java
Expand Up @@ -79,7 +79,7 @@ public enum ID {
REGEXP_IGNORED_FLAGS("REGEXP_IGNORED_FLAGS"),
REGEXP_LITERAL_IN_CONDITION("REGEXP_LITERAL_IN_CONDITION"),
REGEXP_MATCH_AGAINST_STRING("REGEXP_MATCH_AGAINST_STRING"),
SAFE_NOT_SUPPORTED("SAFE_NOT_SUPPORTED"),
SAFE_NOT_SUPPORTED("SAFE_NOT_SUPPORTED", true),
STRUCT_CONSTANT_REDEFINED("STRUCT_CONSTANT_REDEFINED"),
SYMBOL_AS_INTEGER("SYMBOL_AS_INTEGER"),
SYSSEEK_BUFFERED_IO("SYSSEEK_BUFFERED_IO"),
Expand All @@ -93,13 +93,25 @@ public enum ID {

private final String id;

private final boolean oneTime;

ID(String id) {
this.id = id;
this.oneTime = false;
}

ID(String id, boolean oneTime) {
this.id = id;
this.oneTime = oneTime;
}

public String getID() {
return id;
}

public boolean isOneTime() {
return oneTime;
}
}

public abstract Ruby getRuntime();
Expand Down
12 changes: 12 additions & 0 deletions src/org/jruby/common/RubyWarnings.java
Expand Up @@ -27,6 +27,9 @@
***** END LICENSE BLOCK *****/
package org.jruby.common;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.joni.WarnCallback;
import org.jruby.Ruby;
import org.jruby.lexer.yacc.ISourcePosition;
Expand All @@ -39,6 +42,10 @@
public class RubyWarnings implements IRubyWarnings, WarnCallback {
private final Ruby runtime;

// Collections.newSetFromMap is from 1.6
// private final Set<ID> warned = Collections.newSetFromMap(new ConcurrentHashMap<ID, Boolean>());
private final Map<ID, ID> warned = new ConcurrentHashMap<ID, ID>();

public RubyWarnings(Ruby runtime) {
this.runtime = runtime;
}
Expand Down Expand Up @@ -67,6 +74,11 @@ public void warn(ID id, ISourcePosition position, String message) {
*/
public void warn(ID id, String fileName, int lineNumber, String message) {
if (!runtime.warningsEnabled()) return; // TODO make an assert here

if (id.isOneTime()) {
if (warned.containsKey(id)) return;
warned.put(id, id);
}

StringBuilder buffer = new StringBuilder(100);

Expand Down

0 comments on commit 70b90c3

Please sign in to comment.