|
49 | 49 | import java.util.Arrays; |
50 | 50 | import java.util.Collection; |
51 | 51 | import java.util.Collections; |
| 52 | +import java.util.EnumSet; |
52 | 53 | import java.util.HashMap; |
53 | 54 | import java.util.HashSet; |
54 | 55 | import java.util.IdentityHashMap; |
@@ -1374,9 +1375,11 @@ private boolean defineAnnotatedConstant(ThreadContext context, Field field) { |
1374 | 1375 |
|
1375 | 1376 | String[] names = jrubyConstant.value(); |
1376 | 1377 | if (names.length == 0) { |
1377 | | - setConstant(field.getName(), realVal); |
| 1378 | + defineConstant(field.getName(), realVal); |
1378 | 1379 | } else { |
1379 | | - for (String name : names) setConstant(name, realVal); |
| 1380 | + for (String name : names) { |
| 1381 | + defineConstant(name, realVal); |
| 1382 | + } |
1380 | 1383 | } |
1381 | 1384 |
|
1382 | 1385 | return true; |
@@ -1609,7 +1612,13 @@ public <T extends RubyModule> T defineConstants(ThreadContext context, Class con |
1609 | 1612 | */ |
1610 | 1613 | @JRubyAPI |
1611 | 1614 | public <C extends Enum<C> &Constant, T extends RubyModule> T defineConstantsFrom(ThreadContext context, Class<C> enumClass) { |
1612 | | - context.runtime.loadConstantSet(this, enumClass); |
| 1615 | + for (C constant : EnumSet.allOf(enumClass)) { |
| 1616 | + String name = constant.name(); |
| 1617 | + if (constant.defined() && Character.isUpperCase(name.charAt(0))) { |
| 1618 | + defineConstant(context, name, asFixnum(context, constant.intValue())); |
| 1619 | + } |
| 1620 | + } |
| 1621 | + |
1613 | 1622 | return (T) this; |
1614 | 1623 | } |
1615 | 1624 |
|
@@ -4593,12 +4602,16 @@ public IRubyObject const_source_location(ThreadContext context, IRubyObject[] ar |
4593 | 4602 | return context.nil; |
4594 | 4603 | } |
4595 | 4604 |
|
| 4605 | + @Deprecated(since = "10.0") |
| 4606 | + public IRubyObject const_set(IRubyObject name, IRubyObject value) { |
| 4607 | + return const_set(getCurrentContext(), name, value); |
| 4608 | + } |
| 4609 | + |
4596 | 4610 | /** rb_mod_const_set |
4597 | 4611 | * |
4598 | 4612 | */ |
4599 | 4613 | @JRubyMethod(name = "const_set") |
4600 | | - public IRubyObject const_set(IRubyObject name, IRubyObject value) { |
4601 | | - ThreadContext context = getRuntime().getCurrentContext(); |
| 4614 | + public IRubyObject const_set(ThreadContext context, IRubyObject name, IRubyObject value) { |
4602 | 4615 | return setConstant(validateConstant(name), value, context.getFile(), context.getLine() + 1); |
4603 | 4616 | } |
4604 | 4617 |
|
|
0 commit comments