Skip to content

Commit 6c1fd1f

Browse files
committedFeb 5, 2018
further align DynamicMethod.name now being final and not-null
... follow-up on 577d13a handling a few regressions along the way - mostly from Java integration
1 parent 34e6c11 commit 6c1fd1f

19 files changed

+54
-54
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/Ruby.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ private void initRoot() {
13381338

13391339
// In 1.9 and later, Kernel.gsub is defined only when '-p' or '-n' is given on the command line
13401340
if (config.getKernelGsubDefined()) {
1341-
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE) {
1341+
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE, "gsub") {
13421342

13431343
@Override
13441344
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {

Diff for: ‎core/src/main/java/org/jruby/RubyKernel.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public static class MethodMissingMethod extends JavaMethodNBlock {
105105
private final Visibility visibility;
106106
private final CallType callType;
107107

108-
public MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
109-
super(implementationClass, Visibility.PRIVATE);
108+
MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
109+
super(implementationClass, Visibility.PRIVATE, "method_missing");
110110

111111
this.callType = callType;
112112
this.visibility = visibility;

Diff for: ‎core/src/main/java/org/jruby/RubyModule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,8 @@ public IRubyObject newMethod(IRubyObject receiver, final String methodName, bool
18701870

18711871
public static class RespondToMissingMethod extends JavaMethod.JavaMethodNBlock {
18721872
final CallSite site;
1873-
public RespondToMissingMethod(RubyModule implClass, Visibility vis, String methodName) {
1874-
super(implClass, vis);
1873+
public RespondToMissingMethod(RubyModule implClass, Visibility visibility, String methodName) {
1874+
super(implClass, visibility, methodName);
18751875

18761876
setParameterList(REST);
18771877
site = new FunctionalCachingCallSite(methodName);

Diff for: ‎core/src/main/java/org/jruby/ext/pathname/RubyPathname.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ public IRubyObject[] addArg(IRubyObject[] args, RubyString path) {
136136
private static void defineDelegateMethodsGeneric(RubyClass cPathname, final RubyModule klass,
137137
final ReturnValueMapper mapper, final AddArg addArg, String... methods) {
138138
for (String method : methods) {
139-
cPathname.addMethod(method, new JavaMethod.JavaMethodNBlock(cPathname,
140-
Visibility.PUBLIC) {
139+
cPathname.addMethod(method, new JavaMethod.JavaMethodNBlock(cPathname, Visibility.PUBLIC, method) {
141140
@Override
142141
public IRubyObject call(ThreadContext context, IRubyObject _self, RubyModule clazz,
143142
String name, IRubyObject[] args, Block block) {

Diff for: ‎core/src/main/java/org/jruby/internal/runtime/methods/JavaMethod.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,14 @@ protected static void checkArgumentCount(JavaMethod method, ThreadContext contex
276276

277277
// promise to implement N with block
278278
public static abstract class JavaMethodNBlock extends JavaMethod {
279-
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility) {
280-
super(implementationClass, visibility);
281-
}
282279
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility, String name) {
283280
super(implementationClass, visibility, name);
284281
}
285282
@Deprecated
283+
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility) {
284+
super(implementationClass, visibility);
285+
}
286+
@Deprecated
286287
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) {
287288
super(implementationClass, visibility);
288289
}

Diff for: ‎core/src/main/java/org/jruby/java/invokers/ConstructorInvoker.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
public final class ConstructorInvoker extends RubyToJavaInvoker {
1919

20-
public ConstructorInvoker(RubyModule host, List<Constructor> ctors) {
21-
super(host, setAccessible( ctors.toArray(new Constructor[ctors.size()]) ) );
20+
private static final Constructor[] EMPTY_ARRAY = new Constructor[0];
21+
22+
public ConstructorInvoker(RubyModule host, List<Constructor> ctors, String name) {
23+
super(host, setAccessible(ctors.toArray(EMPTY_ARRAY)), name);
2224
}
2325

2426
@Override

Diff for: ‎core/src/main/java/org/jruby/java/invokers/InstanceMethodInvoker.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
import org.jruby.util.ArraySupport;
1414

1515
public final class InstanceMethodInvoker extends MethodInvoker {
16-
public InstanceMethodInvoker(RubyModule host, List<Method> methods) {
17-
super(host, methods);
16+
public InstanceMethodInvoker(RubyModule host, List<Method> methods, String name) {
17+
super(host, methods, name);
1818
}
1919

20-
public InstanceMethodInvoker(RubyModule host, Method method) {
21-
super(host, method);
20+
public InstanceMethodInvoker(RubyModule host, Method method, String name) {
21+
super(host, method, name);
2222
}
2323

2424
@Override

Diff for: ‎core/src/main/java/org/jruby/java/invokers/MethodInvoker.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
public abstract class MethodInvoker extends RubyToJavaInvoker {
1212

13-
MethodInvoker(RubyModule host, List<Method> methods) {
14-
super(host, setAccessible( methods.toArray(new Method[methods.size()]) ) );
13+
private static final Method[] EMPTY_ARRAY = new Method[0];
14+
15+
MethodInvoker(RubyModule host, List<Method> methods, String name) {
16+
super(host, setAccessible(methods.toArray(EMPTY_ARRAY)), name);
1517
}
1618

17-
MethodInvoker(RubyModule host, Method method) {
18-
super(host, setAccessible(method));
19+
MethodInvoker(RubyModule host, Method method, String name) {
20+
super(host, setAccessible(method), name);
1921
}
2022

2123
@Override

Diff for: ‎core/src/main/java/org/jruby/java/invokers/RubyToJavaInvoker.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public abstract class RubyToJavaInvoker<T extends JavaCallable> extends JavaMeth
7171
private final Ruby runtime;
7272

7373
@SuppressWarnings("unchecked") // NULL_CACHE
74-
RubyToJavaInvoker(RubyModule host, Member member) {
75-
super(host, Visibility.PUBLIC);
74+
RubyToJavaInvoker(RubyModule host, Member member, String name) {
75+
super(host, Visibility.PUBLIC, name);
7676
this.runtime = host.getRuntime();
7777

7878
final T callable;
@@ -97,8 +97,8 @@ public abstract class RubyToJavaInvoker<T extends JavaCallable> extends JavaMeth
9797
}
9898

9999
@SuppressWarnings("unchecked") // NULL_CACHE
100-
RubyToJavaInvoker(RubyModule host, Member[] members) {
101-
super(host, Visibility.PUBLIC);
100+
RubyToJavaInvoker(RubyModule host, Member[] members, String name) {
101+
super(host, Visibility.PUBLIC, name);
102102
this.runtime = host.getRuntime();
103103

104104
// initialize all the callables for this method

Diff for: ‎core/src/main/java/org/jruby/java/invokers/SingletonMethodInvoker.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public final class SingletonMethodInvoker extends MethodInvoker {
1515

1616
private final Object singleton;
1717

18-
public SingletonMethodInvoker(Object singleton, RubyClass host, List<Method> methods) {
19-
super(host, methods);
18+
public SingletonMethodInvoker(Object singleton, RubyClass host, List<Method> methods, String name) {
19+
super(host, methods, name);
2020
this.singleton = singleton;
2121
}
2222

23-
public SingletonMethodInvoker(Object singleton, RubyClass host, Method method) {
24-
super(host, method);
23+
public SingletonMethodInvoker(Object singleton, RubyClass host, Method method, String name) {
24+
super(host, method, name);
2525
this.singleton = singleton;
2626
}
2727

Diff for: ‎core/src/main/java/org/jruby/java/invokers/StaticMethodInvoker.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414

1515
public final class StaticMethodInvoker extends MethodInvoker {
1616

17-
public StaticMethodInvoker(RubyClass host, List<Method> methods) {
18-
super(host, methods);
17+
public StaticMethodInvoker(RubyClass host, List<Method> methods, String name) {
18+
super(host, methods, name);
1919
}
2020

21-
public StaticMethodInvoker(RubyClass host, Method method) {
22-
super(host, method);
23-
}
24-
25-
public StaticMethodInvoker(RubyModule host, Method method) {
26-
super(host, method);
21+
public StaticMethodInvoker(RubyModule host, Method method, String name) {
22+
super(host, method, name);
2723
}
2824

2925
@Override

Diff for: ‎core/src/main/java/org/jruby/java/proxies/ConcreteJavaProxy.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static final class InitializeMethod extends org.jruby.internal.runtime.m
4141

4242
private final CallSite jcreateSite = MethodIndex.getFunctionalCallSite("__jcreate!");
4343

44-
InitializeMethod(final RubyClass clazz) { super(clazz, Visibility.PRIVATE); }
44+
InitializeMethod(final RubyClass clazz) { super(clazz, Visibility.PRIVATE, "initialize"); }
4545

4646
@Override
4747
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
@@ -92,7 +92,7 @@ private static final class NewMethod extends org.jruby.internal.runtime.methods.
9292
final DynamicMethod newMethod;
9393

9494
NewMethod(final RubyClass clazz) {
95-
super(clazz, Visibility.PUBLIC);
95+
super(clazz, Visibility.PUBLIC, "new");
9696
newMethod = clazz.searchMethod("new");
9797
}
9898

Diff for: ‎core/src/main/java/org/jruby/java/proxies/JavaInterfaceTemplate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static IRubyObject implement(ThreadContext context, IRubyObject self, IRu
7878
private static class DummyMethodImpl extends org.jruby.internal.runtime.methods.JavaMethod {
7979

8080
DummyMethodImpl(RubyModule targetModule) {
81-
super(targetModule, Visibility.PUBLIC);
81+
super(targetModule, Visibility.PUBLIC, ""); // NOTE: maybe dummy method should not be shared
8282
}
8383

8484
@Override

Diff for: ‎core/src/main/java/org/jruby/java/proxies/JavaProxy.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ private Method getMethod(ThreadContext context, String name, Class... argTypes)
445445

446446
private MethodInvoker getMethodInvoker(Method method) {
447447
if (Modifier.isStatic(method.getModifiers())) {
448-
return new StaticMethodInvoker(metaClass.getMetaClass(), method);
448+
return new StaticMethodInvoker(metaClass.getMetaClass(), method, method.getName());
449449
} else {
450-
return new InstanceMethodInvoker(metaClass, method);
450+
return new InstanceMethodInvoker(metaClass, method, method.getName());
451451
}
452452
}
453453

@@ -623,12 +623,12 @@ public static IRubyObject java_alias(ThreadContext context, IRubyObject clazz, I
623623
final MethodInvoker invoker;
624624

625625
if ( Modifier.isStatic( method.getModifiers() ) ) {
626-
invoker = new StaticMethodInvoker(proxyClass.getMetaClass(), method);
626+
invoker = new StaticMethodInvoker(proxyClass.getMetaClass(), method, newNameStr);
627627
// add alias to meta
628628
proxyClass.getSingletonClass().addMethod(newNameStr, invoker);
629629
}
630630
else {
631-
invoker = new InstanceMethodInvoker(proxyClass, method);
631+
invoker = new InstanceMethodInvoker(proxyClass, method, newNameStr);
632632
proxyClass.addMethod(newNameStr, invoker);
633633
}
634634

@@ -646,11 +646,11 @@ private static AbstractRubyMethod getRubyMethod(ThreadContext context, IRubyObje
646646
final String prettyName = name + CodegenUtils.prettyParams(argTypesClasses);
647647

648648
if ( Modifier.isStatic( method.getModifiers() ) ) {
649-
MethodInvoker invoker = new StaticMethodInvoker(proxyClass, method);
649+
MethodInvoker invoker = new StaticMethodInvoker(proxyClass, method, name);
650650
return RubyMethod.newMethod(proxyClass, prettyName, proxyClass, name, invoker, clazz);
651651
}
652652

653-
MethodInvoker invoker = new InstanceMethodInvoker(proxyClass, method);
653+
MethodInvoker invoker = new InstanceMethodInvoker(proxyClass, method, name);
654654
return RubyUnboundMethod.newUnboundMethod(proxyClass, prettyName, proxyClass, name, invoker);
655655
}
656656

Diff for: ‎core/src/main/java/org/jruby/javasupport/Java.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ else if ( clazz == Object.class ) {
498498
// solved here by adding an exception-throwing "inherited"
499499
if ( Modifier.isFinal(clazz.getModifiers()) ) {
500500
final String clazzName = clazz.getCanonicalName();
501-
proxy.getMetaClass().addMethod("inherited", new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC) {
501+
proxy.getMetaClass().addMethod("inherited", new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC, "inherited") {
502502
@Override
503503
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
504504
throw context.runtime.newTypeError("can not extend final Java class: " + clazzName);
@@ -1052,7 +1052,7 @@ private static boolean bindJavaPackageOrClassMethod(final RubyModule parentPacka
10521052
}
10531053

10541054
final RubyClass singleton = parentPackage.getSingletonClass();
1055-
singleton.addMethod(name.intern(), new JavaAccessor(singleton, packageOrClass, parentPackage));
1055+
singleton.addMethod(name.intern(), new JavaAccessor(singleton, packageOrClass, parentPackage, name));
10561056
return true;
10571057
}
10581058

@@ -1061,8 +1061,8 @@ private static class JavaAccessor extends org.jruby.internal.runtime.methods.Jav
10611061
private final RubyModule packageOrClass;
10621062
private final RubyModule parentPackage;
10631063

1064-
JavaAccessor(final RubyClass singleton, final RubyModule packageOrClass, final RubyModule parentPackage) {
1065-
super(singleton, PUBLIC);
1064+
JavaAccessor(final RubyClass singleton, final RubyModule packageOrClass, final RubyModule parentPackage, final String name) {
1065+
super(singleton, PUBLIC, name);
10661066
this.parentPackage = parentPackage; this.packageOrClass = packageOrClass;
10671067
}
10681068

Diff for: ‎core/src/main/java/org/jruby/javasupport/binding/ConstructorInvokerInstaller.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ void addConstructor(final Constructor ctor, final Class<?> clazz) {
3636

3737
@Override void install(final RubyModule proxy) {
3838
if ( localConstructor ) {
39-
proxy.addMethod(name, new ConstructorInvoker(proxy, constructors));
39+
proxy.addMethod(name, new ConstructorInvoker(proxy, constructors, name));
4040
}
4141
else { // if there's no constructor, we must prevent construction
42-
proxy.addMethod(name, new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC) {
42+
proxy.addMethod(name, new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC, name) {
4343
@Override
4444
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
4545
throw context.runtime.newTypeError("no public constructors for " + clazz);

Diff for: ‎core/src/main/java/org/jruby/javasupport/binding/InstanceMethodInvokerInstaller.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class InstanceMethodInvokerInstaller extends MethodInstaller {
1212

1313
@Override void install(final RubyModule proxy) {
1414
if ( hasLocalMethod() ) {
15-
defineMethods(proxy, new InstanceMethodInvoker(proxy, methods));
15+
defineMethods(proxy, new InstanceMethodInvoker(proxy, methods, name));
1616
}
1717
}
1818
}

Diff for: ‎core/src/main/java/org/jruby/javasupport/binding/SingletonMethodInvokerInstaller.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public SingletonMethodInvokerInstaller(String name, Object singleton) {
2020
// we don't check haveLocalMethod() here because it's not local and we know
2121
// that we always want to go ahead and install it
2222
final RubyClass singletonClass = proxy.getSingletonClass();
23-
defineMethods(singletonClass, new SingletonMethodInvoker(this.singleton, singletonClass, methods), false);
23+
defineMethods(singletonClass, new SingletonMethodInvoker(this.singleton, singletonClass, methods, name), false);
2424
}
2525
}

Diff for: ‎core/src/main/java/org/jruby/javasupport/binding/StaticMethodInvokerInstaller.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class StaticMethodInvokerInstaller extends MethodInstaller {
1414
@Override void install(final RubyModule proxy) {
1515
if ( hasLocalMethod() ) {
1616
final RubyClass singletonClass = proxy.getSingletonClass();
17-
defineMethods(singletonClass, new StaticMethodInvoker(singletonClass, methods), false);
17+
defineMethods(singletonClass, new StaticMethodInvoker(singletonClass, methods, name), false);
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)
Please sign in to comment.