Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dump warning by Kernel.warn only one time

For SAFE_NOT_SUPPORTED warning.
  • Loading branch information...
commit 70b90c34b95e44d2cd0c0307f8ce320f6dfa62b5 1 parent 6e5b660
@nahi nahi authored
View
14 src/org/jruby/common/IRubyWarnings.java
@@ -79,7 +79,7 @@
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"),
@@ -93,13 +93,25 @@
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();
View
12 src/org/jruby/common/RubyWarnings.java
@@ -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;
@@ -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;
}
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.