Skip to content

Commit 74d4306

Browse files
committedJan 31, 2018
Continue propagating name through JavaMethod subtypes.
1 parent 577d13a commit 74d4306

File tree

13 files changed

+334
-143
lines changed

13 files changed

+334
-143
lines changed
 

‎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) {

‎core/src/main/java/org/jruby/RubyKernel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static class MethodMissingMethod extends JavaMethodNBlock {
106106
private final CallType callType;
107107

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

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

‎core/src/main/java/org/jruby/RubyModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ public IRubyObject newMethod(IRubyObject receiver, final String methodName, bool
18711871
public static class RespondToMissingMethod extends JavaMethod.JavaMethodNBlock {
18721872
final CallSite site;
18731873
public RespondToMissingMethod(RubyModule implClass, Visibility vis, String methodName) {
1874-
super(implClass, vis);
1874+
super(implClass, vis, methodName);
18751875

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

‎core/src/main/java/org/jruby/anno/AnnotationBinder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void processMethodDeclaration(ExecutableElement method) {
318318
anno.frame());
319319
String implClass = anno.meta() ? "singletonClass" : "cls";
320320

321-
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");");
321+
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + method.getSimpleName() + "\");");
322322
out.println(" populateMethod(javaMethod, " +
323323
+AnnotationHelper.getArityValue(anno, actualRequired) + ", \""
324324
+ method.getSimpleName() + "\", "
@@ -364,7 +364,7 @@ public void processMethodDeclarationMulti(ExecutableElement method) {
364364
anno.frame());
365365
String implClass = anno.meta() ? "singletonClass" : "cls";
366366

367-
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ");");
367+
out.println(" javaMethod = new " + annotatedBindingName + "(" + implClass + ", Visibility." + anno.visibility() + ", \"" + method.getSimpleName() + "\");");
368368
out.println(" populateMethod(javaMethod, " +
369369
"-1, \"" +
370370
method.getSimpleName() + "\", " +

‎core/src/main/java/org/jruby/anno/IndyBinder.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ public void processMethodDeclarationMulti(List<ExecutableElement> methods) {
403403

404404
mv.aload(implClass);
405405
mv.getstatic(p(Visibility.class), anno.visibility().name(), ci(Visibility.class));
406+
mv.ldc(getBaseNameFor(anno.name(), methods.get(0)));
406407
mv.ldc(encodeSignature(0, 0, 0, 0, 0, true, false));
407408
mv.ldc(true);
408409
mv.ldc(anno.notImplemented());
@@ -424,7 +425,7 @@ public void processMethodDeclarationMulti(List<ExecutableElement> methods) {
424425
}
425426
}
426427

427-
Method handleInit = Method.getMethod("void foo(org.jruby.RubyModule, org.jruby.runtime.Visibility, long, boolean, boolean, java.lang.String, int, int, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable)");
428+
Method handleInit = Method.getMethod("void foo(org.jruby.RubyModule, org.jruby.runtime.Visibility, java.lang.String, long, boolean, boolean, java.lang.String, int, int, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable, java.util.concurrent.Callable)");
428429
mv.invokespecial("org/jruby/internal/runtime/methods/HandleMethod", "<init>", handleInit.getDescriptor());
429430

430431
mv.astore(BASEMETHOD);
@@ -604,4 +605,11 @@ private void defineMethodOnClass(int methodVar, int classVar, final String[] nam
604605
}
605606
}
606607
}
608+
609+
protected String getBaseNameFor(String[] names, ExecutableElement md) {
610+
if (names.length == 0) {
611+
return md.getSimpleName().toString();
612+
}
613+
return names[0];
614+
}
607615
}

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -136,16 +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) {
141-
@Override
142-
public IRubyObject call(ThreadContext context, IRubyObject _self, RubyModule clazz,
143-
String name, IRubyObject[] args, Block block) {
144-
RubyPathname self = (RubyPathname) _self;
145-
args = addArg.addArg(args, self.getPath());
146-
return mapper.map(context, (RubyClass) clazz, klass.callMethod(context, name, args, block));
147-
}
148-
});
139+
cPathname.addMethod(method, new PathnameDelegateMethod(cPathname, method, addArg, mapper, klass));
149140
}
150141
}
151142

@@ -436,4 +427,25 @@ private static RubyArray mapToPathnames(ThreadContext context, RubyClass clazz,
436427
}
437428
return paths;
438429
}
430+
431+
private static class PathnameDelegateMethod extends JavaMethod.JavaMethodNBlock {
432+
private final AddArg addArg;
433+
private final ReturnValueMapper mapper;
434+
private final RubyModule klass;
435+
436+
public PathnameDelegateMethod(RubyClass cPathname, String method, AddArg addArg, ReturnValueMapper mapper, RubyModule klass) {
437+
super(cPathname, Visibility.PUBLIC, method);
438+
this.addArg = addArg;
439+
this.mapper = mapper;
440+
this.klass = klass;
441+
}
442+
443+
@Override
444+
public IRubyObject call(ThreadContext context, IRubyObject _self, RubyModule clazz,
445+
String name, IRubyObject[] args, Block block) {
446+
RubyPathname self = (RubyPathname) _self;
447+
args = addArg.addArg(args, self.getPath());
448+
return mapper.map(context, (RubyClass) clazz, klass.callMethod(context, name, args, block));
449+
}
450+
}
439451
}

‎core/src/main/java/org/jruby/internal/runtime/methods/InvocationMethodFactory.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public class InvocationMethodFactory extends MethodFactory implements Opcodes {
122122
params(ThreadContext.class, IRubyObject.class, RubyModule.class, String.class, IRubyObject.class, IRubyObject.class, IRubyObject.class));
123123

124124
/** The super constructor signature for Java-based method handles. */
125-
private final static String JAVA_SUPER_SIG = sig(Void.TYPE, params(RubyModule.class, Visibility.class));
125+
private final static String JAVA_SUPER_SIG = sig(Void.TYPE, params(RubyModule.class, Visibility.class, String.class));
126126

127127
/** The lvar index of "this" */
128128
public static final int THIS_INDEX = 0;
@@ -187,7 +187,7 @@ public InvocationMethodFactory(ClassLoader classLoader) {
187187
// return signature.isFixed() && signature.required() <= 3;
188188
//}
189189

190-
private static final Class[] RubyModule_and_Visibility = new Class[]{ RubyModule.class, Visibility.class };
190+
private static final Class[] RubyModule_and_Visibility_and_Name = new Class[]{ RubyModule.class, Visibility.class, String.class };
191191

192192
/**
193193
* Use code generation to provide a method handle based on an annotated Java
@@ -208,7 +208,7 @@ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, List<Jav
208208
DescriptorInfo info = new DescriptorInfo(descs);
209209
if (DEBUG) LOG.debug(" min: " + info.getMin() + ", max: " + info.getMax());
210210

211-
JavaMethod ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility).newInstance(implementationClass, anno.visibility());
211+
JavaMethod ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility_and_Name).newInstance(implementationClass, anno.visibility(), desc1.name);
212212

213213
TypePopulator.populateMethod(
214214
ic,
@@ -324,7 +324,7 @@ public DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMeth
324324
try {
325325
Class c = getAnnotatedMethodClass(Collections.singletonList(desc));
326326

327-
JavaMethod ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility).newInstance(implementationClass, desc.anno.visibility());
327+
JavaMethod ic = (JavaMethod) c.getConstructor(RubyModule_and_Visibility_and_Name).newInstance(implementationClass, desc.anno.visibility(), desc.name);
328328

329329
TypePopulator.populateMethod(
330330
ic,
@@ -419,7 +419,7 @@ private static ClassWriter createJavaMethodCtor(String namePath, String sup, Str
419419
cw.visitSource(sourceFile, null);
420420
SkinnyMethodAdapter mv = new SkinnyMethodAdapter(cw, ACC_PUBLIC, "<init>", JAVA_SUPER_SIG, null, null);
421421
mv.start();
422-
mv.aloadMany(0, 1, 2);
422+
mv.aloadMany(0, 1, 2, 3);
423423
mv.invokespecial(sup, "<init>", JAVA_SUPER_SIG);
424424
mv.aload(0);
425425
mv.ldc(parameterDesc);

0 commit comments

Comments
 (0)