Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Dump warning by Kernel.warn only one time

For SAFE_NOT_SUPPORTED warning.
  • Loading branch information...
commit 70b90c34b95e44d2cd0c0307f8ce320f6dfa62b5 1 parent 6e5b660
Hiroshi Nakamura nahi authored
14 src/org/jruby/common/IRubyWarnings.java
@@ -79,7 +79,7 @@
79 79 REGEXP_IGNORED_FLAGS("REGEXP_IGNORED_FLAGS"),
80 80 REGEXP_LITERAL_IN_CONDITION("REGEXP_LITERAL_IN_CONDITION"),
81 81 REGEXP_MATCH_AGAINST_STRING("REGEXP_MATCH_AGAINST_STRING"),
82   - SAFE_NOT_SUPPORTED("SAFE_NOT_SUPPORTED"),
  82 + SAFE_NOT_SUPPORTED("SAFE_NOT_SUPPORTED", true),
83 83 STRUCT_CONSTANT_REDEFINED("STRUCT_CONSTANT_REDEFINED"),
84 84 SYMBOL_AS_INTEGER("SYMBOL_AS_INTEGER"),
85 85 SYSSEEK_BUFFERED_IO("SYSSEEK_BUFFERED_IO"),
@@ -93,13 +93,25 @@
93 93
94 94 private final String id;
95 95
  96 + private final boolean oneTime;
  97 +
96 98 ID(String id) {
97 99 this.id = id;
  100 + this.oneTime = false;
  101 + }
  102 +
  103 + ID(String id, boolean oneTime) {
  104 + this.id = id;
  105 + this.oneTime = oneTime;
98 106 }
99 107
100 108 public String getID() {
101 109 return id;
102 110 }
  111 +
  112 + public boolean isOneTime() {
  113 + return oneTime;
  114 + }
103 115 }
104 116
105 117 public abstract Ruby getRuntime();
12 src/org/jruby/common/RubyWarnings.java
@@ -27,6 +27,9 @@
27 27 ***** END LICENSE BLOCK *****/
28 28 package org.jruby.common;
29 29
  30 +import java.util.Map;
  31 +import java.util.concurrent.ConcurrentHashMap;
  32 +
30 33 import org.joni.WarnCallback;
31 34 import org.jruby.Ruby;
32 35 import org.jruby.lexer.yacc.ISourcePosition;
@@ -39,6 +42,10 @@
39 42 public class RubyWarnings implements IRubyWarnings, WarnCallback {
40 43 private final Ruby runtime;
41 44
  45 + // Collections.newSetFromMap is from 1.6
  46 + // private final Set<ID> warned = Collections.newSetFromMap(new ConcurrentHashMap<ID, Boolean>());
  47 + private final Map<ID, ID> warned = new ConcurrentHashMap<ID, ID>();
  48 +
42 49 public RubyWarnings(Ruby runtime) {
43 50 this.runtime = runtime;
44 51 }
@@ -67,6 +74,11 @@ public void warn(ID id, ISourcePosition position, String message) {
67 74 */
68 75 public void warn(ID id, String fileName, int lineNumber, String message) {
69 76 if (!runtime.warningsEnabled()) return; // TODO make an assert here
  77 +
  78 + if (id.isOneTime()) {
  79 + if (warned.containsKey(id)) return;
  80 + warned.put(id, id);
  81 + }
70 82
71 83 StringBuilder buffer = new StringBuilder(100);
72 84

0 comments on commit 70b90c3

Please sign in to comment.
Something went wrong with that request. Please try again.